schema

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2023 License: MIT Imports: 3 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(text string) *AIChatMessage

func (AIChatMessage) Text

func (m AIChatMessage) Text() string

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 string
	Log       string
}

AgentAction is the agent's action to take.

type AgentFinish

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

AgentFinish is the agent's return value.

type AgentStep

type AgentStep struct {
	Action      AgentAction
	Observation string
}

AgentStep is a step of the agent.

type CallBackManagerForChainRun added in v0.0.22

type CallBackManagerForChainRun interface {
	OnChainEnd(outputs ChainValues) error
	OnChainError(chainError error) error
	OnAgentAction(action AgentAction) error
	OnAgentFinish(finish AgentFinish) error
	OnText(text string) error
	GetInheritableCallbacks() []Callback
	RunID() string
}

type CallBackManagerForLLMRun added in v0.0.22

type CallBackManagerForLLMRun interface {
	OnLLMNewToken(token string) error
	OnLLMEnd(result LLMResult) error
	OnLLMError(llmError error) error
	OnText(text string) error
	GetInheritableCallbacks() []Callback
	RunID() string
}

type CallBackManagerForToolRun added in v0.0.23

type CallBackManagerForToolRun interface {
	OnToolEnd(output string) error
	OnToolError(toolError error) error
	OnText(text string) error
}

type CallOptions added in v0.0.22

type CallOptions struct {
	CallbackManger CallBackManagerForChainRun
	Stop           []string
}

type Callback

type Callback interface {
	AlwaysVerbose() bool
	RaiseError() bool
	OnLLMStart(llmName string, prompts []string) error
	OnLLMNewToken(token string) error
	OnLLMEnd(result LLMResult) error
	OnLLMError(llmError error) error
	OnChainStart(chainName string, inputs ChainValues) error
	OnChainEnd(outputs ChainValues) error
	OnChainError(chainError error) error
	OnAgentAction(action AgentAction) error
	OnAgentFinish(finish AgentFinish) error
	OnToolStart(toolName string, input string) error
	OnToolEnd(output string) error
	OnToolError(toolError error) error
	OnText(text string) error
}

type CallbackManager added in v0.0.22

type CallbackManager interface {
	OnLLMStart(llmName string, prompts []string) (CallBackManagerForLLMRun, error)
	OnChainStart(chainName string, inputs ChainValues) (CallBackManagerForChainRun, error)
	OnToolStart(toolName string, input string) (CallBackManagerForToolRun, error)
	RunID() string
}

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
}

type ChainValues

type ChainValues map[string]any

type ChatMessage

type ChatMessage interface {
	Text() string
	Type() ChatMessageType
}

func MapToChatMessage added in v0.0.12

func MapToChatMessage(m map[string]string) (ChatMessage, error)

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

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(ctx context.Context, messages ChatMessages) (*LLMResult, error)
}

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 GenerateOptions

type GenerateOptions struct {
	CallbackManger CallBackManagerForLLMRun
	Stop           []string
}

type Generation

type Generation struct {
	Text    string
	Message ChatMessage
	Info    map[string]any
}

type GenericChatMessage

type GenericChatMessage struct {
	// contains filtered or unexported fields
}

func NewGenericChatMessage

func NewGenericChatMessage(text, role string) *GenericChatMessage

func (GenericChatMessage) Role

func (m GenericChatMessage) Role() string

func (GenericChatMessage) Text

func (m GenericChatMessage) Text() string

func (GenericChatMessage) Type

type HumanChatMessage

type HumanChatMessage struct {
	// contains filtered or unexported fields
}

func NewHumanChatMessage

func NewHumanChatMessage(text string) *HumanChatMessage

func (HumanChatMessage) Text

func (m HumanChatMessage) Text() string

func (HumanChatMessage) Type

type LLM

type LLM interface {
	Model
	Generate(ctx context.Context, prompts []string, optFns ...func(o *GenerateOptions)) (*LLMResult, error)
}

type LLMResult

type LLMResult struct {
	Generations [][]Generation
	LLMOutput   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() string
	Verbose() bool
	Callbacks() []Callback
}

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
}

type Retriever

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

type StringifyChatMessagesOptions

type StringifyChatMessagesOptions struct {
	HumanPrefix  string
	AIPrefix     string
	SystemPrefix string
}

type SystemChatMessage

type SystemChatMessage struct {
	// contains filtered or unexported fields
}

func NewSystemChatMessage

func NewSystemChatMessage(text string) *SystemChatMessage

func (SystemChatMessage) Text

func (m SystemChatMessage) Text() string

func (SystemChatMessage) Type

type TextSplitter

type TextSplitter interface {
	SplitDocuments(docs []Document) ([]Document, error)
}

type Tokenizer

type Tokenizer interface {
	GetTokenIDs(text string) ([]int, error)
	GetNumTokens(text string) (int, error)
	GetNumTokensFromMessage(messages ChatMessages) (int, error)
}

type Tool

type Tool interface {
	Name() string
	Description() string
	Run(ctx context.Context, query string) (string, error)
}

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