conversation

package
v1.16.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 10 Imported by: 18

README

Conversation

Conversations provide a common way to converse with different LLM providers.

Documentation

Overview

Copyright 2024 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2025 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	DefaultOpenAIModel      = "gpt-5-nano"   // Enable GPT-5 (Preview) for all clients
	DefaultAzureOpenAIModel = "gpt-4.1-nano" // Default Azure OpenAI model
	DefaultAnthropicModel   = "claude-sonnet-4-20250514"
	DefaultGoogleAIModel    = "gemini-2.5-flash-lite"
	DefaultMistralModel     = "open-mistral-7b"
	DefaultHuggingFaceModel = "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"
	DefaultOllamaModel      = "llama3.2:latest"
)

Exported default model constants for consumers of the conversation package. These are used as fallbacks when env vars and metadata are not set.

Variables

This section is empty.

Functions

func CacheModel

func CacheModel(ctx context.Context, ttl string, model llms.Model) (llms.Model, error)

CacheModel creates a prompt query cache with a configured TTL

func GetAnthropicModel added in v1.16.1

func GetAnthropicModel(metadataValue string) string

func GetAzureOpenAIModel added in v1.16.1

func GetAzureOpenAIModel(metadataValue string) string

func GetGoogleAIModel added in v1.16.1

func GetGoogleAIModel(metadataValue string) string

func GetHuggingFaceModel added in v1.16.1

func GetHuggingFaceModel(metadataValue string) string

func GetMistralModel added in v1.16.1

func GetMistralModel(metadataValue string) string

func GetOllamaModel added in v1.16.1

func GetOllamaModel(metadataValue string) string

func GetOpenAIModel added in v1.16.1

func GetOpenAIModel(metadataValue string) string

Example usage for model getters with metadata support: Pass metadataValue from your metadata file/struct, or "" if not set.

Types

type Choice added in v1.16.0

type Choice struct {
	FinishReason string  `json:"finishReason"`
	Index        int64   `json:"index"`
	Message      Message `json:"message"`
}

type Conversation

type Conversation interface {
	metadata.ComponentWithMetadata

	Init(ctx context.Context, meta Metadata) error

	Converse(ctx context.Context, req *Request) (*Response, error)

	io.Closer
}

type LangchainMetadata

type LangchainMetadata struct {
	Key      string `json:"key"`
	Model    string `json:"model"`
	CacheTTL string `json:"cacheTTL"`
	Endpoint string `json:"endpoint"`
}

LangchainMetadata is a common metadata structure for langchain supported implementations.

type Message added in v1.16.0

type Message struct {
	Content         string           `json:"content,omitempty"`
	ToolCallRequest *[]llms.ToolCall `json:"toolCallRequest,omitempty"`
}

Message represents the content of a choice where it can be a text message or a tool call.

type Metadata

type Metadata struct {
	metadata.Base `json:",inline"`
}

Metadata represents a set of conversation specific properties.

type Request added in v1.16.0

type Request struct {
	// Message can be user input prompt/instructions and/or tool call responses.
	Message             *[]llms.MessageContent
	Tools               *[]llms.Tool
	ToolChoice          *string
	Parameters          map[string]*anypb.Any `json:"parameters"`
	ConversationContext string                `json:"conversationContext"`
	Temperature         float64               `json:"temperature"`

	// from metadata
	Key       string   `json:"key"`
	Model     string   `json:"model"`
	Endpoints []string `json:"endpoints"`
	Policy    string   `json:"loadBalancingPolicy"`
}

type Response added in v1.16.0

type Response struct {
	ConversationContext string   `json:"conversationContext"`
	Outputs             []Result `json:"outputs"`
}

type Result added in v1.16.0

type Result struct {
	StopReason string   `json:"stopReason"`
	Choices    []Choice `json:"choices,omitempty"`
}

Directories

Path Synopsis
aws

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL