schema

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: MIT Imports: 7 Imported by: 6

Documentation

Index

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

type AgentFinish struct {
	ReturnValues map[string]any
	Log          string
}

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 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 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.

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 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)
}

type Embedder

type Embedder interface {
	// EmbedDocuments returns a vector for each text.
	EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error)
	// EmbedQuery embeds a single text.
	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"`
}

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

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

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

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, error)
	// 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 Retriever

type Retriever interface {
	GetRelevantDocuments(ctx context.Context, query string) ([]Document, error)
}

type StringifyChatMessagesOptions

type StringifyChatMessagesOptions struct {
	HumanPrefix    string
	AIPrefix       string
	SystemPrefix   string
	FunctionPrefix string
}

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

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
}

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 NewToolInputFromArguments(input string) *ToolInput

func NewToolInputFromString added in v0.0.29

func NewToolInputFromString(input string) *ToolInput

func (*ToolInput) GetString added in v0.0.29

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

func (*ToolInput) String added in v0.0.29

func (ti *ToolInput) String() string

func (*ToolInput) Structured added in v0.0.29

func (ti *ToolInput) Structured() bool

func (*ToolInput) Unmarshal added in v0.0.29

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

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