schema

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 5 Imported by: 176

Documentation

Overview

Package schema implements a shared core set of data types for use in langchaingo.

The primary interface through which end users interact with LLMs is a chat interface. For this reason, some model providers have started providing access to the underlying API in a way that expects chat messages. These messages have a content field (which is usually text) and are associated with a user (or role). Right now the supported users are System, Human, AI, and a generic/arbitrary user.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedChatMessageType = errors.New("unexpected chat message type")

ErrUnexpectedChatMessageType is returned when a chat message is of an unexpected type.

Functions

func GetBufferString

func GetBufferString(messages []ChatMessage, humanPrefix string, aiPrefix string) (string, error)

GetBufferString gets the buffer string of messages.

Types

type AIChatMessage

type AIChatMessage struct {
	// Content is the content of the message.
	Content string `json:"content,omitempty"`

	// FunctionCall represents the model choosing to call a function.
	FunctionCall *FunctionCall `json:"function_call,omitempty"`

	// ToolCalls represents the model choosing to call tools.
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}

AIChatMessage is a message sent by an AI.

func (AIChatMessage) GetContent

func (m AIChatMessage) GetContent() string

func (AIChatMessage) GetFunctionCall

func (m AIChatMessage) GetFunctionCall() *FunctionCall

func (AIChatMessage) GetType

func (m AIChatMessage) GetType() ChatMessageType

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 ChatMessage

type ChatMessage interface {
	// GetType gets the type of the message.
	GetType() ChatMessageType
	// GetContent gets the content of the message.
	GetContent() string
}

ChatMessage represents a message in a chat.

type ChatMessageHistory

type ChatMessageHistory interface {
	// AddMessage adds a message to the store.
	AddMessage(ctx context.Context, message ChatMessage) error

	// AddUserMessage is a convenience method for adding a human message string
	// to the store.
	AddUserMessage(ctx context.Context, message string) error

	// AddAIMessage is a convenience method for adding an AI message string to
	// the store.
	AddAIMessage(ctx context.Context, message string) error

	// Clear removes all messages from the store.
	Clear(ctx context.Context) error

	// Messages retrieves all messages from the store
	Messages(ctx context.Context) ([]ChatMessage, error)

	// SetMessages replaces existing messages in the store
	SetMessages(ctx context.Context, messages []ChatMessage) error
}

ChatMessageHistory is the interface for chat history in memory/store.

type ChatMessageType

type ChatMessageType string

ChatMessageType is the type of chat message.

const (
	// ChatMessageTypeAI is a message sent by an AI.
	ChatMessageTypeAI ChatMessageType = "ai"
	// ChatMessageTypeHuman is a message sent by a human.
	ChatMessageTypeHuman ChatMessageType = "human"
	// ChatMessageTypeSystem is a message sent by the system.
	ChatMessageTypeSystem ChatMessageType = "system"
	// ChatMessageTypeGeneric is a message sent by a generic user.
	ChatMessageTypeGeneric ChatMessageType = "generic"
	// ChatMessageTypeFunction is a message sent by a function.
	ChatMessageTypeFunction ChatMessageType = "function"
	// ChatMessageTypeTool is a message sent by a tool.
	ChatMessageTypeTool ChatMessageType = "tool"
)

type Document

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

Document is the interface for interacting with a document.

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

FunctionCall is the name and arguments of a function call.

type FunctionChatMessage

type FunctionChatMessage struct {
	// Name is the name of the function.
	Name string `json:"name"`
	// Content is the content of the function message.
	Content string `json:"content"`
}

FunctionChatMessage is a chat message representing the result of a function call. Deprecated: Use ToolChatMessage instead.

func (FunctionChatMessage) GetContent

func (m FunctionChatMessage) GetContent() string

func (FunctionChatMessage) GetName

func (m FunctionChatMessage) GetName() string

func (FunctionChatMessage) GetType

type GenericChatMessage

type GenericChatMessage struct {
	Content string
	Role    string
	Name    string
}

GenericChatMessage is a chat message with an arbitrary speaker.

func (GenericChatMessage) GetContent

func (m GenericChatMessage) GetContent() string

func (GenericChatMessage) GetName

func (m GenericChatMessage) GetName() string

func (GenericChatMessage) GetType

func (m GenericChatMessage) GetType() ChatMessageType

type HumanChatMessage

type HumanChatMessage struct {
	Content string
}

HumanChatMessage is a message sent by a human.

func (HumanChatMessage) GetContent

func (m HumanChatMessage) GetContent() string

func (HumanChatMessage) GetType

func (m HumanChatMessage) GetType() ChatMessageType

type Memory

type Memory interface {
	// GetMemoryKey getter for memory key.
	GetMemoryKey(ctx context.Context) string
	// MemoryVariables Input keys this memory class will load dynamically.
	MemoryVariables(ctx context.Context) []string
	// LoadMemoryVariables 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)
	// SaveContext 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
}

Memory is the interface for memory in chains.

type Named

type Named interface {
	GetName() string
}

Named is an interface for objects that have a name.

type OutputParser

type OutputParser[T any] interface {
	// 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() []ChatMessage
}

PromptValue is the interface that all prompt values must implement.

type Retriever

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

Retriever is an interface that defines the behavior of a retriever.

type SystemChatMessage

type SystemChatMessage struct {
	Content string
}

SystemChatMessage is a chat message representing information that should be instructions to the AI system.

func (SystemChatMessage) GetContent

func (m SystemChatMessage) GetContent() string

func (SystemChatMessage) GetType

func (m SystemChatMessage) GetType() ChatMessageType

type ToolCall added in v0.1.8

type ToolCall struct {
	// ID is the ID of the tool call.
	ID string `json:"id"`
	// Type is the type of the tool call.
	Type string `json:"type"`
	// FunctionCall is the function call of the tool call.
	FunctionCall *FunctionCall `json:"function_call,omitempty"`
}

ToolCall is the name and arguments of a tool call.

type ToolChatMessage added in v0.1.8

type ToolChatMessage struct {
	// ID is the ID of the tool call.
	ID string `json:"tool_call_id"`
	// Content is the content of the tool message.
	Content string `json:"content"`
}

ToolChatMessage is a chat message representing the result of a tool call.

func (ToolChatMessage) GetContent added in v0.1.8

func (m ToolChatMessage) GetContent() string

func (ToolChatMessage) GetID added in v0.1.8

func (m ToolChatMessage) GetID() string

func (ToolChatMessage) GetType added in v0.1.8

func (m ToolChatMessage) GetType() ChatMessageType

Jump to

Keyboard shortcuts

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