Documentation
¶
Overview ¶
Package chat exposes the Chat interface used by the application layer and builds the right protocol client for a configured model. Every vendor fact comes from internal/models/catalog; every wire protocol lives under internal/models/api. This package only glues the two together and wraps the client with debug / tracing / concurrency decorators.
Index ¶
- Constants
- Variables
- func EffectiveThinkingControl(config *ChatConfig) string
- func Resolve(config *ChatConfig) (*modelruntime.Resolved, error)
- type CacheRetention
- type Chat
- type ChatConfig
- type ChatOptions
- type FunctionCall
- type FunctionDef
- type ImageURL
- type Message
- type MessageContentPart
- type MessageKind
- type OllamaChat
- func (c *OllamaChat) Chat(ctx context.Context, messages []Message, opts *ChatOptions) (*types.ChatResponse, error)
- func (c *OllamaChat) ChatStream(ctx context.Context, messages []Message, opts *ChatOptions) (<-chan types.StreamResponse, error)
- func (c *OllamaChat) GetModelID() string
- func (c *OllamaChat) GetModelName() string
- type ReasoningEffort
- type Tool
- type ToolCall
Constants ¶
const ( MessageKindCompactionSummary = api.MessageKindCompactionSummary CacheRetentionNone = api.CacheRetentionNone CacheRetentionShort = api.CacheRetentionShort CacheRetentionLong = api.CacheRetentionLong )
Re-exported constants of the request model.
Variables ¶
var ( FingerprintPromptPrefix = api.FingerprintPromptPrefix PromptPrefixFingerprint = api.PromptPrefixFingerprint BuildPromptCacheKey = api.BuildPromptCacheKey )
Prompt-cache helpers re-exported for the application layer.
var SanitizeReasoningEffort = api.SanitizeReasoningEffort
SanitizeReasoningEffort is re-exported for the callers that build ChatOptions from stored strings (agent config, session SummaryConfig).
Functions ¶
func EffectiveThinkingControl ¶
func EffectiveThinkingControl(config *ChatConfig) string
EffectiveThinkingControl reports how the resolved model encodes thinking ("none" when it cannot be asked to think). Kept for the model debug view.
func Resolve ¶
func Resolve(config *ChatConfig) (*modelruntime.Resolved, error)
Resolve looks the configuration up in the catalog. It is exposed so the handler layer can report the effective protocol and capabilities.
Types ¶
type CacheRetention ¶
type CacheRetention = api.CacheRetention
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.
type Chat ¶
type Chat interface {
// Chat 进行非流式聊天
Chat(ctx context.Context, messages []Message, opts *ChatOptions) (*types.ChatResponse, error)
// ChatStream 进行流式聊天
ChatStream(ctx context.Context, messages []Message, opts *ChatOptions) (<-chan types.StreamResponse, error)
// GetModelName 获取模型名称
GetModelName() string
// GetModelID 获取模型ID
GetModelID() string
}
Chat 定义了聊天接口
func NewChat ¶
func NewChat(config *ChatConfig, ollamaService *ollama.OllamaService) (Chat, error)
NewChat 创建聊天实例
func NewRemoteChat ¶
func NewRemoteChat(config *ChatConfig) (Chat, error)
NewRemoteChat builds the protocol client for a remote model.
type ChatConfig ¶
type ChatConfig struct {
Source types.ModelSource
BaseURL string
ModelName string
APIKey string
ModelID string
Provider string
// MaxConcurrency caps concurrent background calls to this model; 0 falls
// back to the process-wide default (see limiter.GateN).
MaxConcurrency int
ExtraConfig map[string]string
// CustomHeaders 允许在调用远程 API 时附加自定义 HTTP 请求头(类似 OpenAI Python SDK 的 extra_headers)。
CustomHeaders map[string]string
AppID string
AppSecret string // 加密值,由工厂函数调用方传入,在使用前已解密
// Spec carries per-row catalog overrides (protocol, compat, levels).
Spec *types.ModelSpecOverride
}
ChatConfig is the operator-facing configuration of one chat model.
func ConfigFromModel ¶
func ConfigFromModel(m *types.Model, appID, appSecret string) *ChatConfig
ConfigFromModel 根据 types.Model 构造 ChatConfig。 保证生产路径(service 层根据 DB 中的模型配置拉起实例)和测试路径 (handler 层根据前端表单临时拉起实例)走完全相同的字段映射。 appID / appSecret 是已经解密/解析好的 WeKnoraCloud 凭证,调用方负责传入。
type ChatOptions ¶
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.
type FunctionCall ¶
type FunctionCall = api.FunctionCall
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.
type FunctionDef ¶
type FunctionDef = api.FunctionDef
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.
type ImageURL ¶
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.
type Message ¶
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.
type MessageContentPart ¶
type MessageContentPart = api.MessageContentPart
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.
type MessageKind ¶
type MessageKind = api.MessageKind
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.
type OllamaChat ¶
type OllamaChat struct {
// contains filtered or unexported fields
}
OllamaChat 实现了基于 Ollama 的聊天
func NewOllamaChat ¶
func NewOllamaChat(config *ChatConfig, ollamaService *ollama.OllamaService) (*OllamaChat, error)
NewOllamaChat 创建 Ollama 聊天实例
func (*OllamaChat) Chat ¶
func (c *OllamaChat) Chat(ctx context.Context, messages []Message, opts *ChatOptions) (*types.ChatResponse, error)
Chat 进行非流式聊天
func (*OllamaChat) ChatStream ¶
func (c *OllamaChat) ChatStream( ctx context.Context, messages []Message, opts *ChatOptions, ) (<-chan types.StreamResponse, error)
ChatStream 进行流式聊天
type ReasoningEffort ¶
type ReasoningEffort = api.ReasoningEffort
Message and the other aliases below re-export the request model defined in internal/models/api so historical chat.* names keep working.