Documentation ¶
Overview ¶
Package schema defines the data structures and types used in GoLC.
Index ¶
- Variables
- func ChatMessageToMap(cm ChatMessage) map[string]string
- type AIChatMessage
- type Agent
- type AgentAction
- type AgentActionInput
- type AgentActionManagerInput
- type AgentFinish
- type AgentFinishInput
- type AgentFinishManagerInput
- type AgentStep
- type CallOptions
- type Callback
- type CallbackManager
- type CallbackManagerForChainRun
- type CallbackManagerForModelRun
- type CallbackManagerForRetrieverRun
- type CallbackManagerForToolRun
- type CallbackOptions
- type Chain
- type ChainEndInput
- type ChainEndManagerInput
- type ChainErrorInput
- type ChainErrorManagerInput
- type ChainStartInput
- type ChainStartManagerInput
- type ChainValues
- type ChatMessage
- type ChatMessageExtension
- type ChatMessageHistory
- type ChatMessageType
- type ChatMessages
- type ChatModel
- type ChatModelStartInput
- type ChatModelStartManagerInput
- type Document
- type DocumentLoader
- type Embedder
- type FunctionCall
- type FunctionChatMessage
- type FunctionDefinition
- type FunctionDefinitionParameters
- type GenerateOptions
- type Generation
- type GenericChatMessage
- type HumanChatMessage
- type LLM
- type LLMStartInput
- type LLMStartManagerInput
- type Memory
- type Model
- type ModelEndInput
- type ModelEndManagerInput
- type ModelErrorInput
- type ModelErrorManagerInput
- type ModelNewTokenInput
- type ModelNewTokenManagerInput
- type ModelResult
- type OutputParser
- type PromptValue
- type Retriever
- type RetrieverEndInput
- type RetrieverEndManagerInput
- type RetrieverErrorInput
- type RetrieverErrorManagerInput
- type RetrieverStartInput
- type RetrieverStartManagerInput
- type StringifyChatMessagesOptions
- type SystemChatMessage
- type TextInput
- type TextManagerInput
- type TextSplitter
- type Tokenizer
- type Tool
- type ToolEndInput
- type ToolEndManagerInput
- type ToolErrorInput
- type ToolErrorManagerInput
- type ToolInput
- type ToolStartInput
- type ToolStartManagerInput
- type VectorStore
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidInputValues = errors.New("invalid input values") ErrInputValuesWrongType = errors.New("input value is of wrong type") )
Functions ¶
func ChatMessageToMap ¶ added in v0.0.12
func ChatMessageToMap(cm ChatMessage) map[string]string
ChatMessageToMap converts a ChatMessage to a map representation.
Types ¶
type AIChatMessage ¶
type AIChatMessage struct {
// contains filtered or unexported fields
}
AIChatMessage represents a chat message from an AI.
func NewAIChatMessage ¶
func NewAIChatMessage(content string, extFns ...func(o *ChatMessageExtension)) *AIChatMessage
NewAIChatMessage creates a new AIChatMessage instance.
func (AIChatMessage) Content ¶ added in v0.0.29
func (m AIChatMessage) Content() string
Content returns the content of the chat message.
func (AIChatMessage) Extension ¶ added in v0.0.29
func (m AIChatMessage) Extension() ChatMessageExtension
Extension returns the extension data of the chat message.
func (AIChatMessage) Type ¶
func (m AIChatMessage) Type() ChatMessageType
Type returns the type of the chat message.
type Agent ¶
type Agent interface { // Plan plans the agent's action given the intermediate steps and inputs. Plan(ctx context.Context, intermediateSteps []AgentStep, inputs ChainValues) ([]*AgentAction, *AgentFinish, error) // InputKeys returns the keys for expected input values for the agent. InputKeys() []string // OutputKeys returns the keys for the agent's output values. OutputKeys() []string }
Agent is an interface that defines the behavior of an agent.
type AgentAction ¶
type AgentAction struct { // Name of the tool to use for the action. Tool string // Input for the tool action. ToolInput *ToolInput // Log message associated with the action. Log string // Message log associated with the action. MessageLog ChatMessages }
AgentAction represents an action that the agent will take.
type AgentActionInput ¶ added in v0.0.27
type AgentActionInput struct { *AgentActionManagerInput RunID string }
type AgentActionManagerInput ¶ added in v0.0.27
type AgentActionManagerInput struct {
Action *AgentAction
}
type AgentFinish ¶
AgentFinish represents the return value of the agent.
type AgentFinishInput ¶ added in v0.0.27
type AgentFinishInput struct { *AgentFinishManagerInput RunID string }
type AgentFinishManagerInput ¶ added in v0.0.27
type AgentFinishManagerInput struct {
Finish *AgentFinish
}
type AgentStep ¶
type AgentStep struct { // Action to be taken by the agent. Action *AgentAction // Observation made during the step. Observation string }
AgentStep represents a step in the agent's action plan.
type CallOptions ¶ added in v0.0.22
type CallOptions struct { CallbackManger CallbackManagerForChainRun Stop []string }
CallOptions contains general options for executing a chain.
type Callback ¶
type Callback interface { AlwaysVerbose() bool RaiseError() bool OnLLMStart(ctx context.Context, input *LLMStartInput) error OnChatModelStart(ctx context.Context, input *ChatModelStartInput) error OnModelNewToken(ctx context.Context, input *ModelNewTokenInput) error OnModelEnd(ctx context.Context, input *ModelEndInput) error OnModelError(ctx context.Context, input *ModelErrorInput) error OnChainStart(ctx context.Context, input *ChainStartInput) error OnChainEnd(ctx context.Context, input *ChainEndInput) error OnChainError(ctx context.Context, input *ChainErrorInput) error OnAgentAction(ctx context.Context, input *AgentActionInput) error OnAgentFinish(ctx context.Context, input *AgentFinishInput) error OnToolStart(ctx context.Context, input *ToolStartInput) error OnToolEnd(ctx context.Context, input *ToolEndInput) error OnToolError(ctx context.Context, input *ToolErrorInput) error OnText(ctx context.Context, input *TextInput) error OnRetrieverStart(ctx context.Context, input *RetrieverStartInput) error OnRetrieverEnd(ctx context.Context, input *RetrieverEndInput) error OnRetrieverError(ctx context.Context, input *RetrieverErrorInput) error }
type CallbackManager ¶ added in v0.0.22
type CallbackManager interface { OnLLMStart(ctx context.Context, input *LLMStartManagerInput) (CallbackManagerForModelRun, error) OnChatModelStart(ctx context.Context, input *ChatModelStartManagerInput) (CallbackManagerForModelRun, error) OnChainStart(ctx context.Context, input *ChainStartManagerInput) (CallbackManagerForChainRun, error) OnToolStart(ctx context.Context, input *ToolStartManagerInput) (CallbackManagerForToolRun, error) OnRetrieverStart(ctx context.Context, input *RetrieverStartManagerInput) (CallbackManagerForRetrieverRun, error) RunID() string }
type CallbackManagerForChainRun ¶ added in v0.0.28
type CallbackManagerForChainRun interface { OnChainEnd(ctx context.Context, input *ChainEndManagerInput) error OnChainError(ctx context.Context, input *ChainErrorManagerInput) error OnAgentAction(ctx context.Context, input *AgentActionManagerInput) error OnAgentFinish(ctx context.Context, input *AgentFinishManagerInput) error OnText(ctx context.Context, input *TextManagerInput) error GetInheritableCallbacks() []Callback RunID() string }
type CallbackManagerForModelRun ¶ added in v0.0.28
type CallbackManagerForModelRun interface { OnModelNewToken(ctx context.Context, input *ModelNewTokenManagerInput) error OnModelEnd(ctx context.Context, input *ModelEndManagerInput) error OnModelError(ctx context.Context, input *ModelErrorManagerInput) error OnText(ctx context.Context, input *TextManagerInput) error GetInheritableCallbacks() []Callback RunID() string }
type CallbackManagerForRetrieverRun ¶ added in v0.0.52
type CallbackManagerForRetrieverRun interface { OnRetrieverEnd(ctx context.Context, input *RetrieverEndManagerInput) error OnRetrieverError(ctx context.Context, input *RetrieverErrorManagerInput) error }
type CallbackManagerForToolRun ¶ added in v0.0.28
type CallbackManagerForToolRun interface { OnToolEnd(ctx context.Context, input *ToolEndManagerInput) error OnToolError(ctx context.Context, input *ToolErrorManagerInput) error OnText(ctx context.Context, input *TextManagerInput) error }
type CallbackOptions ¶ added in v0.0.13
type Chain ¶
type Chain interface { // Call executes the chain with the given context and inputs. // It returns the outputs of the chain or an error, if any. Call(ctx context.Context, inputs ChainValues, optFns ...func(o *CallOptions)) (ChainValues, error) // Type returns the type of the chain. Type() string // Verbose returns the verbosity setting of the chain. Verbose() bool // Callbacks returns the callbacks associated with the chain. Callbacks() []Callback // Memory returns the memory associated with the chain. Memory() Memory // InputKeys returns the expected input keys. InputKeys() []string // OutputKeys returns the output keys the chain will return. OutputKeys() []string }
Chain represents a sequence of calls to llms oder other utilities.
type ChainEndInput ¶ added in v0.0.27
type ChainEndInput struct { *ChainEndManagerInput RunID string }
type ChainEndManagerInput ¶ added in v0.0.27
type ChainEndManagerInput struct {
Outputs ChainValues
}
type ChainErrorInput ¶ added in v0.0.27
type ChainErrorInput struct { *ChainErrorManagerInput RunID string }
type ChainErrorManagerInput ¶ added in v0.0.27
type ChainErrorManagerInput struct {
Error error
}
type ChainStartInput ¶ added in v0.0.27
type ChainStartInput struct { *ChainStartManagerInput RunID string }
type ChainStartManagerInput ¶ added in v0.0.27
type ChainStartManagerInput struct { ChainType string Inputs ChainValues }
type ChainValues ¶
ChainValues represents a map of key-value pairs used for passing inputs and outputs between chain components.
func (ChainValues) Clone ¶ added in v0.0.58
func (cv ChainValues) Clone() ChainValues
Clone creates a shallow copy of the ChainValues map.
func (ChainValues) GetDocuments ¶ added in v0.0.57
func (cv ChainValues) GetDocuments(name string) ([]Document, error)
GetDocuments retrieves the value associated with the given name as a slice of documents from ChainValues. If the name does not exist, the value is not a slice of documents, or the slice is empty, an error is returned.
type ChatMessage ¶
type ChatMessage interface { // Content returns the content of the chat message. Content() string // Type returns the type of the chat message. Type() ChatMessageType }
ChatMessage is an interface for different types of chat messages.
func MapToChatMessage ¶ added in v0.0.12
func MapToChatMessage(m map[string]string) (ChatMessage, error)
MapToChatMessage converts a map representation back to a ChatMessage.
type ChatMessageExtension ¶ added in v0.0.29
type ChatMessageExtension struct {
FunctionCall *FunctionCall `json:"functionCall,omitempty"`
}
ChatMessageExtension represents additional data associated with a chat message.
type ChatMessageHistory ¶
type ChatMessageHistory interface { // Messages returns the messages stored in the store. Messages(ctx context.Context) (ChatMessages, error) // Add a user message to the store. AddUserMessage(ctx context.Context, text string) error // Add an AI message to the store. AddAIMessage(ctx context.Context, text string) error // Add a self-created message to the store. AddMessage(ctx context.Context, message ChatMessage) error // Remove all messages from the store. Clear(ctx context.Context) error }
type ChatMessageType ¶
type ChatMessageType string
ChatMessageType represents the type of a chat message.
const ( ChatMessageTypeHuman ChatMessageType = "human" ChatMessageTypeAI ChatMessageType = "ai" ChatMessageTypeSystem ChatMessageType = "system" ChatMessageTypeGeneric ChatMessageType = "generic" ChatMessageTypeFunction ChatMessageType = "function" )
type ChatMessages ¶ added in v0.0.9
type ChatMessages []ChatMessage
ChatMessages represents a slice of ChatMessage.
func (ChatMessages) Format ¶ added in v0.0.9
func (cm ChatMessages) Format(optFns ...func(o *StringifyChatMessagesOptions)) (string, error)
Format formats the ChatMessages into a single string representation.
type ChatModel ¶ added in v0.0.13
type ChatModel interface { Model // Generate generates text based on the provided chat messages and options. Generate(ctx context.Context, messages ChatMessages, optFns ...func(o *GenerateOptions)) (*ModelResult, error) }
ChatModel is the interface for chat models.
type ChatModelStartInput ¶ added in v0.0.27
type ChatModelStartInput struct { *ChatModelStartManagerInput RunID string }
type ChatModelStartManagerInput ¶ added in v0.0.27
type ChatModelStartManagerInput struct { ChatModelType string Messages ChatMessages InvocationParams map[string]any }
type DocumentLoader ¶
type Embedder ¶
type Embedder interface { // EmbedDocuments embeds a list of documents and returns their embeddings. EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error) // EmbedQuery embeds a single query and returns its embedding. EmbedQuery(ctx context.Context, text string) ([]float64, error) }
Embedder is the interface for creating vector embeddings from texts.
type FunctionCall ¶ added in v0.0.27
type FunctionCall struct { Name string `json:"name,omitempty"` // call function with arguments in JSON format Arguments string `json:"arguments,omitempty"` }
FunctionCall represents a function call with optional arguments in JSON format.
type FunctionChatMessage ¶ added in v0.0.24
type FunctionChatMessage struct {
// contains filtered or unexported fields
}
FunctionChatMessage represents a chat message for a function call.
func NewFunctionChatMessage ¶ added in v0.0.24
func NewFunctionChatMessage(name, content string) *FunctionChatMessage
NewFunctionChatMessage creates a new FunctionChatMessage instance.
func (FunctionChatMessage) Content ¶ added in v0.0.29
func (m FunctionChatMessage) Content() string
Content returns the content of the chat message.
func (FunctionChatMessage) Name ¶ added in v0.0.24
func (m FunctionChatMessage) Name() string
Name returns the name of the function associated with the chat message.
func (FunctionChatMessage) Type ¶ added in v0.0.24
func (m FunctionChatMessage) Type() ChatMessageType
Type returns the type of the chat message.
type FunctionDefinition ¶ added in v0.0.26
type FunctionDefinition struct { Name string `json:"name"` Description string `json:"description,omitempty"` Parameters FunctionDefinitionParameters `json:"parameters"` }
type FunctionDefinitionParameters ¶ added in v0.0.26
type FunctionDefinitionParameters struct { Type string `json:"type"` Properties map[string]*jsonschema.Schema `json:"properties"` Required []string `json:"required"` }
type GenerateOptions ¶
type GenerateOptions struct { CallbackManger CallbackManagerForModelRun Stop []string Functions []FunctionDefinition }
type Generation ¶
type Generation struct { Text string Message ChatMessage Info map[string]any }
Generation represents a generated text along with its corresponding chat message and additional information.
type GenericChatMessage ¶
type GenericChatMessage struct {
// contains filtered or unexported fields
}
GenericChatMessage represents a generic chat message with an associated role.
func NewGenericChatMessage ¶
func NewGenericChatMessage(content, role string) *GenericChatMessage
NewGenericChatMessage creates a new GenericChatMessage instance.
func (GenericChatMessage) Content ¶ added in v0.0.29
func (m GenericChatMessage) Content() string
Content returns the content of the chat message.
func (GenericChatMessage) Role ¶
func (m GenericChatMessage) Role() string
Role returns the role associated with the chat message.
func (GenericChatMessage) Type ¶
func (m GenericChatMessage) Type() ChatMessageType
Type returns the type of the chat message.
type HumanChatMessage ¶
type HumanChatMessage struct {
// contains filtered or unexported fields
}
HumanChatMessage represents a chat message from a human.
func NewHumanChatMessage ¶
func NewHumanChatMessage(content string) *HumanChatMessage
NewHumanChatMessage creates a new HumanChatMessage instance.
func (HumanChatMessage) Content ¶ added in v0.0.29
func (m HumanChatMessage) Content() string
Content returns the content of the chat message.
func (HumanChatMessage) Type ¶
func (m HumanChatMessage) Type() ChatMessageType
Type returns the type of the chat message.
type LLM ¶
type LLM interface { Model // Generate generates text based on the provided prompt and options. Generate(ctx context.Context, prompt string, optFns ...func(o *GenerateOptions)) (*ModelResult, error) }
LLM is the interface for language models.
type LLMStartInput ¶ added in v0.0.27
type LLMStartInput struct { *LLMStartManagerInput RunID string }
type LLMStartManagerInput ¶ added in v0.0.27
type Memory ¶
type Memory interface { // Input keys this memory class will load dynamically. MemoryKeys() []string // Return key-value pairs given the text input to the chain. // If None, return all memories LoadMemoryVariables(ctx context.Context, inputs map[string]any) (map[string]any, error) // Save the context of this model run to memory. SaveContext(ctx context.Context, inputs map[string]any, outputs map[string]any) error // Clear memory contents. Clear(ctx context.Context) error }
type Model ¶ added in v0.0.13
type Model interface { Tokenizer // Type returns the type of the model. Type() string // Verbose returns the verbosity setting of the model. Verbose() bool // Callbacks returns the registered callbacks of the model. Callbacks() []Callback // InvocationParams returns the parameters used in the model invocation. InvocationParams() map[string]any }
Model is the interface for language models and chat models.
type ModelEndInput ¶ added in v0.0.27
type ModelEndInput struct { *ModelEndManagerInput RunID string }
type ModelEndManagerInput ¶ added in v0.0.27
type ModelEndManagerInput struct {
Result *ModelResult
}
type ModelErrorInput ¶ added in v0.0.27
type ModelErrorInput struct { *ModelErrorManagerInput RunID string }
type ModelErrorManagerInput ¶ added in v0.0.27
type ModelErrorManagerInput struct {
Error error
}
type ModelNewTokenInput ¶ added in v0.0.27
type ModelNewTokenInput struct { *ModelNewTokenManagerInput RunID string }
type ModelNewTokenManagerInput ¶ added in v0.0.27
type ModelNewTokenManagerInput struct {
Token string
}
type ModelResult ¶ added in v0.0.26
type ModelResult struct { Generations []Generation LLMOutput map[string]any }
ModelResult represents the result of a model generation.
type OutputParser ¶
type OutputParser[T any] interface { // Parse parses the output of an LLM call. ParseResult(result Generation) (any, error) // Parse parses the output of an LLM call. Parse(text string) (T, error) // ParseWithPrompt parses the output of an LLM call with the prompt used. ParseWithPrompt(text string, prompt PromptValue) (T, error) // GetFormatInstructions returns a string describing the format of the output. GetFormatInstructions() string // Type returns the string type key uniquely identifying this class of parser Type() string }
OutputParser is an interface for parsing the output of an LLM call.
type PromptValue ¶
type PromptValue interface { String() string Messages() ChatMessages }
PromptValue is an interface representing a prompt value for LLMs and chat models.
type RetrieverEndInput ¶ added in v0.0.52
type RetrieverEndInput struct { *RetrieverEndManagerInput RunID string }
type RetrieverEndManagerInput ¶ added in v0.0.52
type RetrieverEndManagerInput struct {
Docs []Document
}
type RetrieverErrorInput ¶ added in v0.0.52
type RetrieverErrorInput struct { *RetrieverErrorManagerInput RunID string }
type RetrieverErrorManagerInput ¶ added in v0.0.52
type RetrieverErrorManagerInput struct {
Error error
}
type RetrieverStartInput ¶ added in v0.0.52
type RetrieverStartInput struct { *RetrieverStartManagerInput RunID string }
type RetrieverStartManagerInput ¶ added in v0.0.52
type RetrieverStartManagerInput struct {
Query string
}
type StringifyChatMessagesOptions ¶
type StringifyChatMessagesOptions struct { HumanPrefix string AIPrefix string SystemPrefix string FunctionPrefix string }
StringifyChatMessagesOptions represents options for formatting ChatMessages.
type SystemChatMessage ¶
type SystemChatMessage struct {
// contains filtered or unexported fields
}
SystemChatMessage represents a chat message from the system.
func NewSystemChatMessage ¶
func NewSystemChatMessage(content string) *SystemChatMessage
NewSystemChatMessage creates a new SystemChatMessage instance.
func (SystemChatMessage) Content ¶ added in v0.0.29
func (m SystemChatMessage) Content() string
Content returns the content of the chat message.
func (SystemChatMessage) Type ¶
func (m SystemChatMessage) Type() ChatMessageType
Type returns the type of the chat message.
type TextInput ¶ added in v0.0.27
type TextInput struct { *TextManagerInput RunID string }
type TextManagerInput ¶ added in v0.0.27
type TextManagerInput struct {
Text string
}
type TextSplitter ¶
type Tokenizer ¶
type Tokenizer interface { // GetTokenIDs returns the token IDs corresponding to the provided text. GetTokenIDs(text string) ([]uint, error) // GetNumTokens returns the number of tokens in the provided text. GetNumTokens(text string) (uint, error) // GetNumTokensFromMessage returns the number of tokens in the provided chat messages. GetNumTokensFromMessage(messages ChatMessages) (uint, error) }
Tokenizer is an interface for tokenizing text.
type Tool ¶
type Tool interface { // Name returns the name of the tool. Name() string // Description returns the description of the tool. Description() string // Run executes the tool with the given input and returns the output. Run(ctx context.Context, input any) (string, error) // ArgsType returns the type of the input argument expected by the tool. ArgsType() reflect.Type // Verbose returns the verbosity setting of the tool. Verbose() bool // Callbacks returns the registered callbacks of the tool. Callbacks() []Callback }
Tool is an interface that defines the behavior of a tool.
type ToolEndInput ¶ added in v0.0.27
type ToolEndInput struct { *ToolEndManagerInput RunID string }
type ToolEndManagerInput ¶ added in v0.0.27
type ToolEndManagerInput struct {
Output string
}
type ToolErrorInput ¶ added in v0.0.27
type ToolErrorInput struct { *ToolErrorManagerInput RunID string }
type ToolErrorManagerInput ¶ added in v0.0.27
type ToolErrorManagerInput struct {
Error error
}
type ToolInput ¶ added in v0.0.29
type ToolInput struct {
// contains filtered or unexported fields
}
ToolInput represents an input for a tool, which can be either a structured input or a plain string input.
func NewToolInputFromArguments ¶ added in v0.0.29
NewToolInputFromArguments creates a new ToolInput from a structured input.
func NewToolInputFromString ¶ added in v0.0.29
NewToolInputFromString creates a new ToolInput from a plain string input.
func (*ToolInput) GetString ¶ added in v0.0.29
GetString returns the plain string value from the ToolInput if it is not a structured input. If the ToolInput is structured, it returns an error.
func (*ToolInput) String ¶ added in v0.0.29
String returns the string representation of the ToolInput.
func (*ToolInput) Structured ¶ added in v0.0.29
Structured returns true if the ToolInput is a structured input; otherwise, it returns false.
type ToolStartInput ¶ added in v0.0.27
type ToolStartInput struct { *ToolStartManagerInput RunID string }