components

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 14 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 ApiResponse added in v1.0.1

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

ApiResponse instructor provider chat response

func (*ApiResponse) FromAnthropic added in v1.0.1

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

FromAnthropic convert response from anthropic

func (*ApiResponse) FromCohere added in v1.0.1

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

FromCohere convert response from cohere

func (*ApiResponse) FromOpenAI added in v1.0.1

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

FromOpenAI convnert response from openai

type ApiUsage added in v1.0.8

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

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

func (m *Memory) Copy(dist *Memory)

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() *Memory

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

func (*Memory) Reset added in v1.0.1

func (m *Memory) Reset() *Memory

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) *Memory

SetTurnID set the current turn ID

func (Memory) TurnID

func (m Memory) TurnID() string

TurnID returns the current turn ID

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

func (m Message) Content() schema.Schema

Content returns message content

func (Message) Role

func (m Message) Role() MessageRole

Role returns message role

func (*Message) SetTurnID

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

SetTurnID set message turnID

func (Message) ToAnthropic

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

ToAnthropic convert message to anthropic Message

func (Message) ToCohere added in v1.0.1

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

ToCohere convert message to cohere Message

func (Message) ToOpenAI

func (m Message) ToOpenAI(dist *openai.ChatCompletionMessage)

ToOpenAI convert message to openai ChatCompletionMessage

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 optimizer provides prompt optimization capabilities for Language Learning Models.
Package optimizer provides prompt optimization capabilities for Language Learning Models.
cot

Jump to

Keyboard shortcuts

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