Versions in this module Expand all Collapse all v0 v0.0.5 Feb 10, 2025 Changes in this version + type Loader interface + Load func(ctx context.Context) ([]Document, error) + LoadAndSplit func(ctx context.Context, splitter TextSplitter) ([]Document, error) v0.0.4 Feb 10, 2025 Changes in this version type Env + Get func(key string) string type FunctionDefinition + Strict bool type Message + func TextParts(role ChatMessageType, parts ...string) Message v0.0.3 Feb 7, 2025 v0.0.2 Feb 7, 2025 Changes in this version type Agent + Tools func() []AgentTool type Embedder + func NewEmbedder(client EmbedderClient, opts ...EmbedderOption) (Embedder, error) + type EmbedderOption func(p *embedder) + func WithBatchSize(batchSize int) EmbedderOption + func WithStripNewLines(stripNewLines bool) EmbedderOption v0.0.1 Feb 4, 2025 Changes in this version + var ErrAgentNoReturn = errors.New("no actions or finish was returned by the agent") + var ErrChainInitialization = errors.New("error initializing chain") + var ErrEmptyResponseFromProvider = fmt.Errorf("empty response from provider") + var ErrExecutorInputNotString = errors.New("input to executor not string") + var ErrInputValuesWrongType = errors.New("input key is of wrong type") + var ErrInputVariableReserved = errors.New("conflict with reserved variable name") + var ErrInvalidChainReturnType = errors.New("agent chain did not return a string") + var ErrInvalidInputValues = errors.New("invalid input values") + var ErrInvalidOptions = errors.New("invalid options") + var ErrInvalidOutputValues = errors.New("missing key in output values") + var ErrInvalidPartialVariableType = errors.New("invalid partial variable type") + var ErrInvalidTemplateFormat = errors.New("invalid template format") + var ErrInvalidValues = errors.New("invalid values") + var ErrMemoryValuesWrongType = errors.New("memory key is of wrong type") + var ErrMismatchMetadatasAndText = errors.New("number of texts and metadatas does not match") + var ErrMissingInputValues = errors.New("missing key in input values") + var ErrMissingMemoryKeyValues = errors.New("missing memory key in input values") + var ErrMultipleInputsInRun = errors.New("run not supported in chain with more then one expected input") + var ErrMultipleOutputsInPredict = errors.New("predict is not supported with a chain that returns multiple values") + var ErrMultipleOutputsInRun = errors.New("run not supported in chain with more then one expected output") + var ErrNeedChatMessageList = errors.New("variable should be a list of chat messages") + var ErrNotFinished = errors.New("agent not finished before max iterations") + var ErrOutputNotStringInPredict = errors.New("predict is not supported with a chain that does not return a string") + var ErrUnableToParseOutput = errors.New("unable to parse agent output") + var ErrUnexpectedChatMessageType = errors.New("unexpected chat message type") + var ErrUnknownAgentType = errors.New("unknown agent type") + var ErrWrongOutputTypeInRun = errors.New("run not supported in chain that returns value that is not string") + func BufferString(messages []ChatMessage, humanPrefix string, aiPrefix string) (string, error) + func Call(ctx context.Context, provider Provider, prompt string, ...) (string, error) + func ChainApply(ctx context.Context, c Chain, inputValues []map[string]any, maxWorkers int, ...) ([]map[string]any, error) + func ChainCall(ctx context.Context, c Chain, inputValues map[string]any, ...) (map[string]any, error) + func ChainPredict(ctx context.Context, c Chain, inputValues map[string]any, ...) (string, error) + func ChainRun(ctx context.Context, c Chain, input any, options ...ChainOption) (string, error) + func ResolvePartialValues(partialValues map[string]any, values map[string]any) (map[string]any, error) + type AIChatMessage struct + Content string + FunctionCall *FunctionCall + ToolCalls []ToolCall + func (ai AIChatMessage) MessageContent() string + func (ai AIChatMessage) MessageFunctionCall() *FunctionCall + func (ai AIChatMessage) Type() ChatMessageType + type Agent interface + AgentTools func() []AgentTool + InputKeys func() []string + OutputKeys func() []string + Plan func(ctx context.Context, steps []AgentStep, inputs map[string]string) ([]AgentAction, *AgentFinish, error) + type AgentAction struct + Log string + Tool string + ToolID string + ToolInput string + type AgentFinish struct + Log string + ReturnValues map[string]any + type AgentHooker interface + AgentHooks func() AgentHooks + type AgentHooks interface + AgentAction func(ctx context.Context, action AgentAction) + AgentFinish func(ctx context.Context, finish AgentFinish) + StreamingFunc func(ctx context.Context, chunk []byte) + type AgentStep struct + Action AgentAction + Observation string + type AgentTool interface + Call func(ctx context.Context, input string) (string, error) + Description func() string + Name func() string + type BinaryContent struct + Data []byte + MIMEType string + func BinaryPart(mime string, data []byte) BinaryContent + func (bc BinaryContent) String() string + type Chain interface + Call func(ctx context.Context, inputs map[string]any, options ...ChainOption) (map[string]any, error) + InputKeys func() []string + Memory func() Memory + OutputKeys func() []string + func NewChain(provider Provider, prompter PromptFormatter, opts ...ChainOption) Chain + type ChainHooker interface + ChainHooks func() ChainHooks + type ChainHooks interface + ChainEnd func(ctx context.Context, outputs map[string]any) + ChainError func(ctx context.Context, err error) + ChainStart func(ctx context.Context, inputs map[string]any) + StreamingFunc func(ctx context.Context, chunk []byte) + type ChainOption func(*ChainOptions) + func ChainWithHooks(hooks ChainHooks) ChainOption + func ChainWithMaxLength(maxLength int) ChainOption + func ChainWithMaxTokens(maxTokens int) ChainOption + func ChainWithMemory(memory Memory) ChainOption + func ChainWithMinLength(minLength int) ChainOption + func ChainWithModel(model string) ChainOption + func ChainWithOutputKey(outputKey string) ChainOption + func ChainWithParser(parser Parser[any]) ChainOption + func ChainWithRepetitionPenalty(repetitionPenalty float64) ChainOption + func ChainWithSeed(seed int) ChainOption + func ChainWithStopWords(stopWords []string) ChainOption + func ChainWithStreamingFunc(streamingFunc func(ctx context.Context, chunk []byte) error) ChainOption + func ChainWithTemperature(temperature float64) ChainOption + func ChainWithTopK(topK int) ChainOption + func ChainWithTopP(topP float64) ChainOption + type ChainOptions struct + Hooks ChainHooks + MaxLength int + MaxTokens int + Memory Memory + MinLength int + Model string + OutputKey string + Parser Parser[any] + RepetitionPenalty float64 + Seed int + StopWords []string + StreamingFunc func(ctx context.Context, chunk []byte) error + Temperature float64 + TopK int + TopP float64 + type ChatMessage interface + MessageContent func() string + Type func() ChatMessageType + type ChatMessageHistory interface + AddAIMessage func(ctx context.Context, message string) error + AddMessage func(ctx context.Context, message ChatMessage) error + AddUserMessage func(ctx context.Context, message string) error + Clear func(ctx context.Context) error + Messages func(ctx context.Context) ([]ChatMessage, error) + SetMessages func(ctx context.Context, messages []ChatMessage) error + type ChatMessageType string + const ChatMessageTypeAI + const ChatMessageTypeFunction + const ChatMessageTypeGeneric + const ChatMessageTypeHuman + const ChatMessageTypeSystem + const ChatMessageTypeTool + type ContentChoice struct + Content string + FuncCall *FunctionCall + GenerationInfo map[string]any + StopReason string + ToolCalls []ToolCall + type ContentOption func(*ContentOptions) + func WithCandidateCount(c int) ContentOption + func WithFrequencyPenalty(frequencyPenalty float64) ContentOption + func WithJSONMode() ContentOption + func WithMaxLength(maxLength int) ContentOption + func WithMaxTokens(maxTokens int) ContentOption + func WithMetadata(metadata map[string]any) ContentOption + func WithMinLength(minLength int) ContentOption + func WithModel(model string) ContentOption + func WithN(n int) ContentOption + func WithOptions(options ContentOptions) ContentOption + func WithPresencePenalty(presencePenalty float64) ContentOption + func WithRepetitionPenalty(repetitionPenalty float64) ContentOption + func WithSeed(seed int) ContentOption + func WithStopWords(stopWords []string) ContentOption + func WithStreamingFunc(streamingFunc func(ctx context.Context, chunk []byte) error) ContentOption + func WithTemperature(temperature float64) ContentOption + func WithToolChoice(choice any) ContentOption + func WithTools(tools []Tool) ContentOption + func WithTopK(topK int) ContentOption + func WithTopP(topP float64) ContentOption + type ContentOptions struct + CandidateCount int + FrequencyPenalty float64 + JSONMode bool + MaxLength int + MaxTokens int + Metadata map[string]any + MinLength int + Model string + N int + PresencePenalty float64 + RepetitionPenalty float64 + Seed int + StopWords []string + StreamingFunc func(ctx context.Context, chunk []byte) error + Temperature float64 + ToolChoice any + Tools []Tool + TopK int + TopP float64 + type ContentPart interface + type ContentResponse struct + Choices []*ContentChoice + func Content(ctx context.Context, provider Provider, prompt string, ...) (*ContentResponse, error) + type Document struct + Metadata map[string]any + PageContent string + Score float32 + func CreateDocuments(textSplitter TextSplitter, texts []string, metadatas []map[string]any) ([]Document, error) + func SplitDocuments(textSplitter TextSplitter, documents []Document) ([]Document, error) + type Embedder interface + EmbedDocuments func(ctx context.Context, texts []string) ([][]float32, error) + EmbedQuery func(ctx context.Context, text string) ([]float32, error) + type EmbedderClient interface + CreateEmbedding func(ctx context.Context, texts []string) ([][]float32, error) + type EmbedderClientFunc func(ctx context.Context, texts []string) ([][]float32, error) + func (e EmbedderClientFunc) CreateEmbedding(ctx context.Context, texts []string) ([][]float32, error) + type EmptyHooks struct + func (EmptyHooks) AgentAction(context.Context, AgentAction) + func (EmptyHooks) AgentFinish(context.Context, AgentFinish) + func (EmptyHooks) ChainEnd(context.Context, map[string]any) + func (EmptyHooks) ChainError(context.Context, error) + func (EmptyHooks) ChainStart(context.Context, map[string]any) + func (EmptyHooks) ProviderError(context.Context, error) + func (EmptyHooks) ProviderGenerateContentEnd(context.Context, *ContentResponse) + func (EmptyHooks) ProviderGenerateContentStart(context.Context, []Message) + func (EmptyHooks) ProviderStart(context.Context, []string) + func (EmptyHooks) RetrieverEnd(context.Context, string, []Document) + func (EmptyHooks) RetrieverStart(context.Context, string) + func (EmptyHooks) StreamingFunc(context.Context, []byte) + func (EmptyHooks) Text(context.Context, string) + func (EmptyHooks) ToolEnd(context.Context, string) + func (EmptyHooks) ToolError(context.Context, error) + func (EmptyHooks) ToolStart(context.Context, string) + type EmptyMemory struct + func (EmptyMemory) Clear(context.Context) error + func (EmptyMemory) LoadVariables(context.Context, map[string]any) (map[string]any, error) + func (EmptyMemory) MemoryKey(context.Context) string + func (EmptyMemory) SaveContext(context.Context, map[string]any, map[string]any) error + func (EmptyMemory) Variables(context.Context) []string + type EmptyParser struct + func (EmptyParser) FormatInstructions() string + func (EmptyParser) Parse(text string) (any, error) + func (EmptyParser) ParseWithPrompt(text string, _ Prompt) (any, error) + func (EmptyParser) Type() string + type Env interface + Bool func(key string, fallback bool) bool + Duration func(key string, fallback time.Duration) time.Duration + Float64 func(key string, fallback float64) float64 + Int func(key string, fallback int) int + String func(key, fallback string) string + func NewEnv(getenv Getenv) Env + type FunctionCall struct + Arguments string + Name string + type FunctionCallBehavior string + const FunctionCallBehaviorAuto + const FunctionCallBehaviorNone + type FunctionDefinition struct + Description string + Name string + Parameters any + type FunctionReference struct + Name string + type GenericChatMessage struct + Content string + Name string + Role string + func (m GenericChatMessage) MessageContent() string + func (m GenericChatMessage) MessageName() string + func (m GenericChatMessage) Type() ChatMessageType + type Getenv func(string) string + type HTTPDoer interface + Do func(req *http.Request) (*http.Response, error) + type Hooks interface + type HumanChatMessage struct + Content string + func (human HumanChatMessage) MessageContent() string + func (human HumanChatMessage) Type() ChatMessageType + type ImageURLContent struct + Detail string + URL string + func ImageURLPart(url string) ImageURLContent + func ImageURLWithDetailPart(url string, detail string) ImageURLContent + func (iuc ImageURLContent) String() string + type Memory interface + Clear func(ctx context.Context) error + LoadVariables func(ctx context.Context, inputs map[string]any) (map[string]any, error) + MemoryKey func(ctx context.Context) string + SaveContext func(ctx context.Context, inputs map[string]any, outputs map[string]any) error + Variables func(ctx context.Context) []string + type Message struct + Parts []ContentPart + Role ChatMessageType + func TextPartsMessage(role ChatMessageType, parts ...string) Message + type MessageFormatter interface + FormatMessages func(values map[string]any) ([]ChatMessage, error) + InputVariables func() []string + type Named interface + MessageName func() string + type ParseError struct + Reason string + Text string + func (e ParseError) Error() string + type Parser interface + FormatInstructions func() string + Parse func(text string) (T, error) + Type func() string + type ParserErrorHandler struct + Formatter func(err string) string + func NewParserErrorHandler(formatFunc func(string) string) *ParserErrorHandler + type Prompt interface + Messages func() []ChatMessage + String func() string + type PromptFormatter interface + FormatPrompt func(values map[string]any) (Prompt, error) + InputVariables func() []string + type Provider interface + GenerateContent func(ctx context.Context, messages []Message, options ...ContentOption) (*ContentResponse, error) + type ProviderHooks interface + ProviderError func(ctx context.Context, err error) + ProviderGenerateContentEnd func(ctx context.Context, res *ContentResponse) + ProviderGenerateContentStart func(ctx context.Context, ms []Message) + ProviderStart func(ctx context.Context, prompts []string) + StreamingFunc func(ctx context.Context, chunk []byte) + type Renderer interface + RenderTemplate func(tmpl string, values map[string]any) (string, error) + type RendererFunc func(string, map[string]any) (string, error) + func (render RendererFunc) RenderTemplate(tmpl string, values map[string]any) (string, error) + type Retriever interface + RelevantDocuments func(ctx context.Context, query string) ([]Document, error) + type RetrieverHooks interface + RetrieverEnd func(ctx context.Context, query string, documents []Document) + RetrieverStart func(ctx context.Context, query string) + type String string + func (s String) Messages() []ChatMessage + func (s String) String() string + type StringFormatter interface + FormatString func(values map[string]any) (string, error) + type SystemChatMessage struct + Content string + func (system SystemChatMessage) MessageContent() string + func (system SystemChatMessage) Type() ChatMessageType + type Template struct + Content string + Parser Parser[any] + PartialVariables map[string]any + Variables []string + func FStringTemplate(content string, variables []string) Template + func GoTemplate(content string, variables []string) Template + func NewTemplate(content string, variables []string, renderer Renderer, ...) Template + func (p Template) FormatPrompt(values map[string]any) (Prompt, error) + func (p Template) FormatString(values map[string]any) (string, error) + func (p Template) InputVariables() []string + type TemplateOption func(*Template) + func TemplateWithParser(parser Parser[any]) TemplateOption + func TemplateWithPartialVariables(partialVariables map[string]any) TemplateOption + type TextContent struct + Text string + func TextPart(s string) TextContent + func (tc TextContent) String() string + type TextSplitter interface + SplitText func(text string) ([]string, error) + type Tool struct + Function *FunctionDefinition + Type string + type ToolCall struct + FunctionCall *FunctionCall + ID string + Type string + type ToolCallResponse struct + Content string + Name string + ToolCallID string + type ToolChatMessage struct + CallID string + Content string + func (tool ToolChatMessage) ID() string + func (tool ToolChatMessage) MessageContent() string + func (tool ToolChatMessage) Type() ChatMessageType + type ToolChoice struct + Function *FunctionReference + Type string + type ToolHooks interface + ToolEnd func(ctx context.Context, output string) + ToolError func(ctx context.Context, err error) + ToolStart func(ctx context.Context, input string) + type VectorStore interface + AddDocuments func(ctx context.Context, docs []Document, options ...VectorStoreOption) ([]string, error) + SimilaritySearch func(ctx context.Context, query string, numDocs int, options ...VectorStoreOption) ([]Document, error) + type VectorStoreOption func(*VectorStoreOptions) + func VectorStoreWithDeduplicater(fn func(ctx context.Context, doc Document) bool) VectorStoreOption + func VectorStoreWithEmbedder(embedder Embedder) VectorStoreOption + func VectorStoreWithFilters(filters any) VectorStoreOption + func VectorStoreWithNameSpace(namespace string) VectorStoreOption + func VectorStoreWithScoreThreshold(scoreThreshold float32) VectorStoreOption + type VectorStoreOptions struct + Deduplicater func(context.Context, Document) bool + Embedder Embedder + Filters any + Namespace string + ScoreThreshold float32 + type VectorStoreRetriever struct + Hooks RetrieverHooks + func NewVectorStoreRetriever(vs VectorStore, numDocs int, options ...VectorStoreRetrieverOption) VectorStoreRetriever + func (r VectorStoreRetriever) RelevantDocuments(ctx context.Context, query string) ([]Document, error) + type VectorStoreRetrieverOption func(*VectorStoreRetriever) + func VectorStoreRetrieverWithHooks(hooks RetrieverHooks) VectorStoreRetrieverOption + func VectorStoreRetrieverWithOptions(options ...VectorStoreOption) VectorStoreRetrieverOption