Documentation
¶
Overview ¶
Package schema defines the data structures and types used in GoLC.
Index ¶
- 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 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 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 ¶
This section is empty.
Functions ¶
func ChatMessageToMap ¶ added in v0.0.12
func ChatMessageToMap(cm ChatMessage) map[string]string
Types ¶
type AIChatMessage ¶
type AIChatMessage struct {
// contains filtered or unexported fields
}
func NewAIChatMessage ¶
func NewAIChatMessage(content string, extFns ...func(o *ChatMessageExtension)) *AIChatMessage
func (AIChatMessage) Content ¶ added in v0.0.29
func (m AIChatMessage) Content() string
func (AIChatMessage) Extension ¶ added in v0.0.29
func (m AIChatMessage) Extension() ChatMessageExtension
func (AIChatMessage) Type ¶
func (m AIChatMessage) Type() ChatMessageType
type Agent ¶
type Agent interface {
Plan(ctx context.Context, intermediateSteps []AgentStep, inputs map[string]string) ([]*AgentAction, *AgentFinish, error)
InputKeys() []string
OutputKeys() []string
}
type AgentAction ¶
type AgentAction struct {
Tool string
ToolInput *ToolInput
Log string
MessageLog ChatMessages
}
AgentAction is the agent's action to 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 is the agent's return value.
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 *AgentAction
Observation string
}
AgentStep is a step of the agent.
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
}
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)
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 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.
type ChatMessage ¶
type ChatMessage interface {
Content() string
Type() ChatMessageType
}
func MapToChatMessage ¶ added in v0.0.12
func MapToChatMessage(m map[string]string) (ChatMessage, error)
type ChatMessageExtension ¶ added in v0.0.29
type ChatMessageExtension struct {
FunctionCall *FunctionCall `json:"functionCall,omitempty"`
}
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
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
func (ChatMessages) Format ¶ added in v0.0.9
func (cm ChatMessages) Format(optFns ...func(o *StringifyChatMessagesOptions)) (string, error)
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 FunctionChatMessage ¶ added in v0.0.24
type FunctionChatMessage struct {
// contains filtered or unexported fields
}
func NewFunctionChatMessage ¶ added in v0.0.24
func NewFunctionChatMessage(name, content string) *FunctionChatMessage
func (FunctionChatMessage) Content ¶ added in v0.0.29
func (m FunctionChatMessage) Content() string
func (FunctionChatMessage) Name ¶ added in v0.0.24
func (m FunctionChatMessage) Name() string
func (FunctionChatMessage) Type ¶ added in v0.0.24
func (m FunctionChatMessage) Type() ChatMessageType
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
}
func NewGenericChatMessage ¶
func NewGenericChatMessage(content, role string) *GenericChatMessage
func (GenericChatMessage) Content ¶ added in v0.0.29
func (m GenericChatMessage) Content() string
func (GenericChatMessage) Role ¶
func (m GenericChatMessage) Role() string
func (GenericChatMessage) Type ¶
func (m GenericChatMessage) Type() ChatMessageType
type HumanChatMessage ¶
type HumanChatMessage struct {
// contains filtered or unexported fields
}
func NewHumanChatMessage ¶
func NewHumanChatMessage(content string) *HumanChatMessage
func (HumanChatMessage) Content ¶ added in v0.0.29
func (m HumanChatMessage) Content() string
func (HumanChatMessage) Type ¶
func (m HumanChatMessage) Type() ChatMessageType
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 SystemChatMessage ¶
type SystemChatMessage struct {
// contains filtered or unexported fields
}
func NewSystemChatMessage ¶
func NewSystemChatMessage(content string) *SystemChatMessage
func (SystemChatMessage) Content ¶ added in v0.0.29
func (m SystemChatMessage) Content() string
func (SystemChatMessage) Type ¶
func (m SystemChatMessage) Type() ChatMessageType
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
}
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
}
func NewToolInputFromArguments ¶ added in v0.0.29
func NewToolInputFromString ¶ added in v0.0.29
func (*ToolInput) Structured ¶ added in v0.0.29
type ToolStartInput ¶ added in v0.0.27
type ToolStartInput struct {
*ToolStartManagerInput
RunID string
}