components

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package components includes AgentMemory etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTurnID

func NewTurnID() string

NewTurnID returns a new turn ID.

Types

type LLMResponse added in v1.1.0

type LLMResponse struct {
	ID        string      `json:"id,omitempty"`
	Role      MessageRole `json:"role,omitempty"`
	Model     string      `json:"model,omitempty"`
	Usage     *LLMUsage   `json:"usage,omitempty"`
	Timestamp int64       `json:"ts,omitempty"`
	Details   any         `json:"content,omitempty"`
}

LLMResponse instructor provider chat response

func (*LLMResponse) FromAnthropic added in v1.1.0

func (r *LLMResponse) FromAnthropic(v *anthropic.MessagesResponse)

FromAnthropic convert response from anthropic

func (*LLMResponse) FromCohere added in v1.1.0

func (r *LLMResponse) FromCohere(v *cohere.NonStreamedChatResponse)

FromCohere convert response from cohere

func (*LLMResponse) FromGemini added in v1.1.0

func (r *LLMResponse) FromGemini(v *gemini.GenerateContentResponse)

func (*LLMResponse) FromOpenAI added in v1.1.0

func (r *LLMResponse) FromOpenAI(v *openai.ChatCompletionResponse)

FromOpenAI convnert response from openai

type LLMUsage added in v1.1.0

type LLMUsage struct {
	InputTokens  int `json:"input_tokens,omitempty"`
	OutputTokens int `json:"output_tokens,omitempty"`
}

func (*LLMUsage) Merge added in v1.1.8

func (u *LLMUsage) Merge(v *LLMUsage)

type Memory

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

Memory Manages the chat history for an AI agent. threadsafe

func NewMemory

func NewMemory(maxMessages int) *Memory

NewMemory initializes the Memory with an empty history and optional constraints.

func (*Memory) AddMessage added in v1.2.3

func (m *Memory) AddMessage(msg *Message)

func (*Memory) Copy

func (m *Memory) Copy(src MemoryStore)

Copy creates a copy of the chat memory.

func (*Memory) DeleteTurn

func (m *Memory) DeleteTurn(turnID string) error

DeleteTurn delete messages from the memory by its turn ID. returns Error if the specified turn ID is not found in the memory

func (*Memory) History

func (m *Memory) History() []Message

History retrieves the chat history, filtering out unnecessary fields and serializing content.

func (Memory) MaxMessages

func (m Memory) MaxMessages() int

MaxMessages returns the max number of messages

func (*Memory) MessageCount

func (m *Memory) MessageCount() int

MessageCount returns the number of messages in the chat history.

func (*Memory) NewMessage

func (m *Memory) NewMessage(role MessageRole, content schema.Schema) *Message

NewMessage adds a message to the chat history and manages overflow.

func (*Memory) NewTurn

func (m *Memory) NewTurn() MemoryStore

NewTurn initializes a new turn by generating a random turn ID.

func (*Memory) Reset added in v1.0.1

func (m *Memory) Reset() MemoryStore

func (*Memory) SetHistory

func (m *Memory) SetHistory(history []Message) *Memory

SetHistory set a copy of chat history

func (*Memory) SetMaxMessages

func (m *Memory) SetMaxMessages(maxMessages int) *Memory

SetMaxMessages set the max number of messages

func (*Memory) SetTurnID

func (m *Memory) SetTurnID(turnID string) MemoryStore

SetTurnID set the current turn ID

func (Memory) TurnID

func (m Memory) TurnID() string

TurnID returns the current turn ID

type MemoryStore added in v1.1.9

type MemoryStore interface {
	MaxMessages() int
	TurnID() string
	NewTurn() MemoryStore
	NewMessage(MessageRole, schema.Schema) *Message
	AddMessage(msg *Message)
	History() []Message
	Reset() MemoryStore
	Copy(MemoryStore)
	MessageCount() int
}

type Message

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

Message Represents a message in the chat history.

Attributes:

role (str): .
content: The content of the message.

func NewMessage

func NewMessage(role MessageRole, content schema.Schema) *Message

NewMessage returns a new Message

func (Message) Attachement

func (m Message) Attachement() *schema.Attachement

Attachement returns message attachement

func (Message) Chunks added in v1.2.1

func (m Message) Chunks() []schema.Schema

Chunks returns message attachement chunks

func (Message) Content

func (m Message) Content() schema.Schema

Content returns message content

func (Message) FileIDs added in v1.2.1

func (m Message) FileIDs() []string

FileIDs returns message attachement file ids

func (Message) Files added in v1.2.1

func (m Message) Files() []io.Reader

Files returns message attachement files

func (Message) ImageURLs added in v1.2.1

func (m Message) ImageURLs() []string

ImageURLs returns message attachement image urls

func (*Message) Mode added in v1.3.4

func (m *Message) Mode() instructor.Mode

func (*Message) Raw added in v1.3.4

func (m *Message) Raw() string

func (Message) Role

func (m Message) Role() MessageRole

Role returns message role

func (*Message) SetMode added in v1.3.4

func (m *Message) SetMode(mode instructor.Mode)

func (*Message) SetRaw added in v1.3.1

func (m *Message) SetRaw(raw string)

func (*Message) SetTurnID

func (m *Message) SetTurnID(turnID string) *Message

SetTurnID set message turnID

func (*Message) StringifiedContent added in v1.3.4

func (m *Message) StringifiedContent() string

func (Message) ToAnthropic

func (m Message) ToAnthropic(dist *anthropic.Message) []anthropic.Message

ToAnthropic convert message to anthropic Message

func (Message) ToCohere added in v1.0.1

func (m Message) ToCohere(dist *cohere.Message) []*cohere.Message

ToCohere convert message to cohere Message

func (Message) ToGemini added in v1.1.0

func (m Message) ToGemini(dist *gemini.Content) []*gemini.Content

ToGemini convert message to openai Content

func (Message) ToOpenAI

ToOpenAI convert message to openai ChatCompletionMessage

func (Message) TryAttachChunkPrompt added in v1.2.1

func (m Message) TryAttachChunkPrompt(idx int) string

func (Message) TurnID

func (m Message) TurnID() string

turnID returns message turnID

type MessageRole

type MessageRole = string

MessageRole is the role of the message sender (e.g., 'user', 'system', 'tool')

const (
	SystemRole    MessageRole = "system"
	UserRole      MessageRole = "user"
	AssistantRole MessageRole = "assistant"
	ToolRole      MessageRole = "tool"
	FunctionRole  MessageRole = "function"
)

Directories

Path Synopsis
Package document contains Document structs and Parsers prepare for RAG
Package document contains Document structs and Parsers prepare for RAG
parsers
Package parsers include different parsers implementation
Package parsers include different parsers implementation
parsers/docx
Package docx a parser for docx
Package docx a parser for docx
parsers/html
Package html a parser for html
Package html a parser for html
parsers/pdf
Package pdf a parser for PDF
Package pdf a parser for PDF
parsers/pptx
Package pptx a Parser for pptx
Package pptx a Parser for pptx
parsers/xlsx
Package xlsx a xlsx parser
Package xlsx a xlsx parser
Package embedder contains Embedder interface and different providers including openai, voyageai, coheren, gemini and huggingface, etc.
Package embedder contains Embedder interface and different providers including openai, voyageai, coheren, gemini and huggingface, etc.
splitter
Package splitter defines different chunker spliters
Package splitter defines different chunker spliters
Package optimizer provides prompt optimization capabilities for Language Learning Models.
Package optimizer provides prompt optimization capabilities for Language Learning Models.
Package systemprompt contains system prompt generator and context provider
Package systemprompt contains system prompt generator and context provider
cot
Package vectordb contains vectordb interface and different engines like memory, chromem and milvus implementations.
Package vectordb contains vectordb interface and different engines like memory, chromem and milvus implementations.

Jump to

Keyboard shortcuts

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