schema

package
v0.0.81 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 9 Imported by: 6

Documentation

Overview

Package schema defines the data structures and types used in GoLC.

Index

Constants

This section is empty.

Variables

View Source
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

type AgentFinish struct {
	// Return values from the agent.
	ReturnValues map[string]any
	Log          string
}

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 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 CallbackOptions struct {
	Callbacks []Callback
	Verbose   bool
}

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

type ChainValues map[string]any

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.

func (ChainValues) GetString added in v0.0.57

func (cv ChainValues) GetString(name string) (string, error)

GetString retrieves the value associated with the given name as a string from ChainValues. If the name does not exist or the value is not a string, 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 Document

type Document struct {
	PageContent string
	Metadata    map[string]any
}

type DocumentLoader

type DocumentLoader interface {
	Load(ctx context.Context) ([]Document, error)
	LoadAndSplit(ctx context.Context, splitter TextSplitter) ([]Document, error)
}

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

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

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

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 LLMStartManagerInput struct {
	LLMType          string
	Prompt           string
	InvocationParams map[string]any
}

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 PromptTemplate added in v0.0.69

type PromptTemplate interface {
	// Format applies values to the template and returns the formatted result as a string.
	Format(values map[string]any) (string, error)

	// FormatPrompt applies values to the template and returns a PromptValue representation of the formatted result.
	FormatPrompt(values map[string]any) (PromptValue, error)

	// InputVariables returns a list of input variables used in the template.
	InputVariables() []string

	// OutputParser returns the output parser function and a boolean indicating if an output parser is defined.
	OutputParser() (OutputParser[any], bool)
}

PromptTemplate is an interface for creating templates that can be formatted with dynamic values.

type PromptValue

type PromptValue interface {
	// String returns the string representation of the prompt value.
	String() string

	// Messages returns the chat messages associated with the prompt value.
	Messages() ChatMessages
}

PromptValue is an interface representing a prompt value for LLMs and chat models.

type Retriever

type Retriever interface {
	GetRelevantDocuments(ctx context.Context, query string) ([]Document, error)
	// Verbose returns the verbosity setting of the retriever.
	Verbose() bool
	// Callbacks returns the registered callbacks of the retriever.
	Callbacks() []Callback
}

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

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 TextSplitter interface {
	SplitDocuments(docs []Document) ([]Document, error)
}

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

func NewToolInputFromArguments(input string) *ToolInput

NewToolInputFromArguments creates a new ToolInput from a structured input.

func NewToolInputFromString added in v0.0.29

func NewToolInputFromString(input string) *ToolInput

NewToolInputFromString creates a new ToolInput from a plain string input.

func (*ToolInput) GetString added in v0.0.29

func (ti *ToolInput) GetString() (string, error)

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

func (ti *ToolInput) String() string

String returns the string representation of the ToolInput.

func (*ToolInput) Structured added in v0.0.29

func (ti *ToolInput) Structured() bool

Structured returns true if the ToolInput is a structured input; otherwise, it returns false.

func (*ToolInput) Unmarshal added in v0.0.29

func (ti *ToolInput) Unmarshal(args any) error

Unmarshal unmarshals the ToolInput into the provided argument, which should be a pointer to a valid data type. If the ToolInput is a structured input, it attempts to unmarshal it into a map with a single key "__arg1".

type ToolStartInput added in v0.0.27

type ToolStartInput struct {
	*ToolStartManagerInput
	RunID string
}

type ToolStartManagerInput added in v0.0.27

type ToolStartManagerInput struct {
	ToolName string
	Input    *ToolInput
}

type VectorStore added in v0.0.10

type VectorStore interface {
	AddDocuments(ctx context.Context, docs []Document) error
	SimilaritySearch(ctx context.Context, query string) ([]Document, error)
}

Jump to

Keyboard shortcuts

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