Documentation
¶
Index ¶
- Variables
- func AssistantPromptMessage(text string) *assistantPromptMessage
- func CompressQueryMessage(messages []Message) (string, error)
- func ConcatQueryMessage(messages []Message) (string, error)
- func LastQueryMessage(messages []Message) (string, error)
- func Register(name string, provider Provider)
- func SummarizeQueryMessage(messages []Message) (string, error)
- func ToolPromptMessage(text string, toolID string) *toolPromptMessage
- func WithConfigSupplier(c ConfigSupplier)
- func WithConfigs(c map[string]any)
- func WithSingleConfig(c any)
- type BaseCache
- type Cache
- type CacheConfig
- type CacheFactory
- type CachedDocument
- type Chunk
- type ChunkDelta
- type ConfigSupplier
- type ConfigSupplierFunc
- type ExactMatchScorer
- type FunctionCallBehavior
- type FunctionDefinition
- type FunctionReference
- type Hook
- type HookOption
- type Instance
- type InvokeOption
- type InvokeOptions
- type MemoCache
- type Message
- type Messages
- type Metrics
- type NoneLogger
- func (w *NoneLogger) DebugContextf(ctx context.Context, format string, args ...interface{})
- func (w *NoneLogger) ErrorContextf(ctx context.Context, format string, args ...interface{})
- func (w *NoneLogger) InfoContextf(ctx context.Context, format string, args ...interface{})
- func (w *NoneLogger) WarnContextf(ctx context.Context, format string, args ...interface{})
- type Option
- type Options
- type OtelHook
- type PromptMessage
- type PromptMessageContent
- type PromptMessageRole
- type PromptMessageTool
- type Provider
- type QueryProcessor
- type RedisCache
- type Response
- type Result
- type Scorer
- type Stream
- type Tool
- type ToolCall
- type ToolCallFunction
- type ToolChoice
- type Usage
Constants ¶
This section is empty.
Variables ¶
var ( ErrCacheMiss = errors.New("cache miss") ErrCacheFull = errors.New("cache is full") )
添加自定义错误类型
Functions ¶
func AssistantPromptMessage ¶
func AssistantPromptMessage(text string) *assistantPromptMessage
AssistantPromptMessage ...
func CompressQueryMessage ¶
CompressQueryMessage ...
func ConcatQueryMessage ¶
ConcatQueryMessage ...
func LastQueryMessage ¶
LastQueryMessage ...
func SummarizeQueryMessage ¶
SummarizeQueryMessage extracts an intelligent summary from conversation messages
func ToolPromptMessage ¶
ToolPromptMessage ...
Types ¶
type BaseCache ¶
type BaseCache struct { Config *CacheConfig Embedder embedding.Embedder VectorStore vdb.VDB Ranker Scorer }
BaseCache ...
func (*BaseCache) SetQueryProcessor ¶
func (c *BaseCache) SetQueryProcessor(p QueryProcessor)
SetQueryProcessor ...
type Cache ¶
type Cache interface { Fetch(context.Context, []Message) (*CachedDocument, bool, error) Store(context.Context, *CachedDocument, string) error }
Cache ...
type CacheConfig ¶
type CacheConfig struct { TTL time.Duration MaxEntries int CleanupInterval time.Duration EnableMetrics bool QueryProcessor QueryProcessor }
CacheConfig 定义缓存的配置选项
type CachedDocument ¶
CachedDocument ...
type Chunk ¶
type Chunk struct { Model string `json:"model"` Messages []*PromptMessage `json:"-"` SystemFingerprint string `json:"system_fingerprint"` Delta *ChunkDelta `json:"delta"` }
Chunk ...
type ChunkDelta ¶
type ChunkDelta struct { Index int `json:"index"` Message *assistantPromptMessage `json:"message"` Usage *Usage `json:"usage"` FinishReason string `json:"finish_reason"` Done bool `json:"done"` }
ChunkDelta ...
type ConfigSupplier ¶
ConfigSupplier ...
var Config ConfigSupplier = &envConfig{}
Config default cache
type FunctionCallBehavior ¶
type FunctionCallBehavior string
FunctionCallBehavior is the behavior to use when calling functions.
const ( // FunctionCallBehaviorNone will not call any functions. FunctionCallBehaviorNone FunctionCallBehavior = "none" // FunctionCallBehaviorAuto will call functions automatically. FunctionCallBehaviorAuto FunctionCallBehavior = "auto" )
type FunctionDefinition ¶
type FunctionDefinition struct { // Name is the name of the function. Name string `json:"name"` // Description is a description of the function. Description string `json:"description"` // Parameters is a list of parameters for the function. Parameters any `json:"parameters,omitempty"` }
FunctionDefinition is a definition of a function that can be called by the model.
type FunctionReference ¶
type FunctionReference struct { // Name is the name of the function. Name string `json:"name"` }
FunctionReference is a reference to a function.
type Hook ¶
type Hook interface { OnBeforeInvoke(context.Context) context.Context OnAfterInvoke(ctx context.Context, err error) OnFirstChunk(context.Context, error) context.Context }
Hook ...
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance ...
func (*Instance) Invoke ¶
func (mi *Instance) Invoke(ctx context.Context, messages []Message, tools []PromptMessageTool, options ...InvokeOption) (*Response, error)
Invoke ...
type InvokeOption ¶
type InvokeOption func(*InvokeOptions)
InvokeOption is a function that configures a InvokeOptions.
func WithModel ¶
func WithModel(model string) InvokeOption
WithModel specifies which model name to use.
type InvokeOptions ¶
type InvokeOptions struct { // Model is the model to use. Model string `json:"model"` // Stream is the stream output. Stream bool `json:"stream"` // CandidateCount is the number of response candidates to generate. CandidateCount int `json:"candidate_count"` // MaxTokens is the maximum number of tokens to generate. MaxTokens int `json:"max_tokens"` // Temperature is the temperature for sampling, between 0 and 1. Temperature float64 `json:"temperature"` // StopWords is a list of words to stop on. StopWords []string `json:"stop_words"` // StreamingFunc is a function to be called for each chunk of a streaming response. // Return an error to stop streaming early. StreamingFunc func(ctx context.Context, chunk []byte) error `json:"-"` // TopK is the number of tokens to consider for top-k sampling. TopK int `json:"top_k"` // TopP is the cumulative probability for top-p sampling. TopP float64 `json:"top_p"` // Seed is a seed for deterministic sampling. Seed int `json:"seed"` // MinLength is the minimum length of the generated text. MinLength int `json:"min_length"` // MaxLength is the maximum length of the generated text. MaxLength int `json:"max_length"` // N is how many chat completion choices to generate for each input message. N int `json:"n"` // RepetitionPenalty is the repetition penalty for sampling. RepetitionPenalty float64 `json:"repetition_penalty"` // FrequencyPenalty is the frequency penalty for sampling. FrequencyPenalty float64 `json:"frequency_penalty"` // PresencePenalty is the presence penalty for sampling. PresencePenalty float64 `json:"presence_penalty"` // JSONMode is a flag to enable JSON mode. JSONMode bool `json:"json"` // Tools is a list of tools to use. Each tool can be a specific tool or a function. Tools []Tool `json:"tools,omitempty"` // ToolChoice is the choice of tool to use, it can either be "none", "auto" (the default behavior), or a specific tool as described in the ToolChoice type. ToolChoice any `json:"tool_choice"` // Function defitions to include in the request. // Deprecated: Use Tools instead. Functions []FunctionDefinition `json:"functions,omitempty"` // FunctionCallBehavior is the behavior to use when calling functions. // // If a specific function should be invoked, use the format: // `{"name": "my_function"}` // Deprecated: Use ToolChoice instead. FunctionCallBehavior FunctionCallBehavior `json:"function_call,omitempty"` // Metadata is a map of metadata to include in the request. // The meaning of this field is specific to the backend in use. Metadata map[string]interface{} `json:"metadata,omitempty"` }
InvokeOptions ...
type MemoCache ¶
type MemoCache struct { BaseCache // contains filtered or unexported fields }
MemoCache ...
type Message ¶
type Message interface { Content() *PromptMessageContent Role() PromptMessageRole ToolID() string String() string }
Message ...
type NoneLogger ¶
type NoneLogger struct { }
NoneLogger ...
func (*NoneLogger) DebugContextf ¶
func (w *NoneLogger) DebugContextf(ctx context.Context, format string, args ...interface{})
DebugContextf ...
func (*NoneLogger) ErrorContextf ¶
func (w *NoneLogger) ErrorContextf(ctx context.Context, format string, args ...interface{})
ErrorContextf ...
func (*NoneLogger) InfoContextf ¶
func (w *NoneLogger) InfoContextf(ctx context.Context, format string, args ...interface{})
InfoContextf ...
func (*NoneLogger) WarnContextf ¶
func (w *NoneLogger) WarnContextf(ctx context.Context, format string, args ...interface{})
WarnContextf ...
type OtelHook ¶
type OtelHook struct {
// contains filtered or unexported fields
}
OtelHook ...
func (*OtelHook) OnAfterInvoke ¶
OnAfterInvoke ...
func (*OtelHook) OnBeforeInvoke ¶
OnBeforeInvoke ...
type PromptMessage ¶
type PromptMessage struct { Name string // contains filtered or unexported fields }
PromptMessage ...
func SystemPromptMessage ¶
func SystemPromptMessage(text string) PromptMessage
SystemPromptMessage ...
func (PromptMessage) MarshalJSON ¶
func (m PromptMessage) MarshalJSON() ([]byte, error)
MarshalJSON 实现marshal
func (PromptMessage) String ¶
func (m PromptMessage) String() string
func (*PromptMessage) UnmarshalJSON ¶
func (m *PromptMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON 实现unmarshal
type PromptMessageContent ¶
PromptMessageContent ...
func TextPromptMessageContent ¶
func TextPromptMessageContent(text string) *PromptMessageContent
TextPromptMessageContent ...
type PromptMessageRole ¶
type PromptMessageRole string
const ( PromptMessageRoleSystem PromptMessageRole = "system" PromptMessageRoleUser PromptMessageRole = "user" PromptMessageRoleAssistant PromptMessageRole = "assistant" PromptMessageRoleTool PromptMessageRole = "tool" )
type PromptMessageTool ¶
PromptMessageTool for prompt message tool
type Provider ¶
type Provider interface {
Invoke(context.Context, []Message, []PromptMessageTool, ...InvokeOption) (*Response, error)
}
Provider ...
type RedisCache ¶
type RedisCache struct { BaseCache // contains filtered or unexported fields }
RedisCache ...
func (*RedisCache) Fetch ¶
func (m *RedisCache) Fetch(ctx context.Context, messages []Message) (*CachedDocument, bool, error)
Fetch ...
func (*RedisCache) Store ¶
func (m *RedisCache) Store(ctx context.Context, document *CachedDocument, value string) error
Store ...
type Result ¶
type Result struct { Model string `json:"model"` // Messages []*PromptMessage Message *assistantPromptMessage `json:"message"` Usage *Usage `json:"usage"` SystemFingerprint string `json:"system_fingerprint"` }
Result ...
type Tool ¶
type Tool struct { // Type is the type of the tool. Type string `json:"type"` // Function is the function to call. Function *FunctionDefinition `json:"function,omitempty"` }
Tool is a tool that can be used by the model.
type ToolCall ¶
type ToolCall struct { ID string `json:"id"` Type string `json:"type"` Function ToolCallFunction `json:"function"` }
ToolCall ...
type ToolCallFunction ¶
ToolCallFunction ...
type ToolChoice ¶
type ToolChoice struct { // Type is the type of the tool. Type string `json:"type"` // Function is the function to call (if the tool is a function). Function *FunctionReference `json:"function,omitempty"` }
ToolChoice is a specific tool to use.