schema

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 5 Imported by: 0

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

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

AIChatMessage is a message sent by an AI.

func (AIChatMessage) GetContent

func (m AIChatMessage) GetContent() string

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 ChatGeneration

type ChatGeneration struct {
	Generation
	Message ChatMessage
}

ChatGeneration is the output of a single chat generation.

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 {
	// AddUserMessage Convenience method for adding a human message string to the store.
	AddUserMessage(ctx context.Context, message string) error

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

	// AddMessage Add a Message object to the store.
	AddMessage(ctx context.Context, message ChatMessage) error

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

	// Messages get 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 a 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"
)

type ChatResult

type ChatResult struct {
	Generations []ChatGeneration
	LLMOutput   map[string]any
}

ChatResult is the class that contains all relevant information for a Chat Result.

type Document

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

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    string `json:"name"`
	Content string `json:"content"`
}

FunctionChatMessage is a chat message representing the result of a function call.

func (FunctionChatMessage) GetContent

func (m FunctionChatMessage) GetContent() string

func (FunctionChatMessage) GetName

func (m FunctionChatMessage) GetName() string

func (FunctionChatMessage) GetType

type Generation

type Generation struct {
	// Generated text output.
	Text string
	// Raw generation info response from the provider.
	// May include things like reason for finishing (e.g. in OpenAI).
	GenerationInfo map[string]any
}

Generation is the output of a single generation.

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 LLMResult

type LLMResult struct {
	Generations [][]Generation
	LLMOutput   map[string]any
}

LLMResult is the class that contains all relevant information for an LLM Result.

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

Jump to

Keyboard shortcuts

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