chat

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent represents a simplified chat agent that hides OpenAI SDK details

func NewAgent

func NewAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig models.Config,
) (*Agent, error)

NewAgent creates a new simplified chat agent

func (*Agent) AddMessage

func (agent *Agent) AddMessage(role roles.Role, content string)

AddMessage adds a message to the conversation history

func (*Agent) ExportMessagesToJSON

func (agent *Agent) ExportMessagesToJSON() (string, error)

ExportMessagesToJSON exports the conversation history to JSON

func (*Agent) GenerateCompletion

func (agent *Agent) GenerateCompletion(userMessages []messages.Message) (*CompletionResult, error)

GenerateCompletion sends messages and returns the completion result

func (*Agent) GenerateCompletionWithReasoning

func (agent *Agent) GenerateCompletionWithReasoning(userMessages []messages.Message) (*ReasoningResult, error)

GenerateCompletionWithReasoning sends messages and returns the completion result with reasoning

func (*Agent) GenerateStreamCompletion

func (agent *Agent) GenerateStreamCompletion(
	userMessages []messages.Message,
	callback StreamCallback,
) (*CompletionResult, error)

GenerateStreamCompletion sends messages and streams the response via callback

func (*Agent) GenerateStreamCompletionWithReasoning

func (agent *Agent) GenerateStreamCompletionWithReasoning(
	userMessages []messages.Message,
	reasoningCallback StreamCallback,
	responseCallback StreamCallback,
) (*ReasoningResult, error)

GenerateStreamCompletionWithReasoning sends messages and streams both reasoning and response

func (*Agent) GetContextSize

func (agent *Agent) GetContextSize() int

GetContextSize returns the approximate size of the current context

func (*Agent) GetMessages

func (agent *Agent) GetMessages() []messages.Message

GetMessages returns all conversation messages

func (*Agent) GetModelID added in v0.0.7

func (agent *Agent) GetModelID() string

func (*Agent) GetName added in v0.0.3

func (agent *Agent) GetName() string

func (*Agent) Kind

func (agent *Agent) Kind() agents.Kind

Kind returns the agent type

func (*Agent) ResetMessages

func (agent *Agent) ResetMessages()

ResetMessages clears all messages except the system instruction

func (*Agent) StopStream

func (agent *Agent) StopStream()

StopStream interrupts the current streaming operation

type AgentOption

type AgentOption func(*BaseAgent)

type BaseAgent

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

func NewBaseAgent

func NewBaseAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig openai.ChatCompletionNewParams,
	options ...AgentOption,
) (chatAgent *BaseAgent, err error)

NewBaseAgent creates a new ChatAgent instance

func (*BaseAgent) AddMessage

func (agent *BaseAgent) AddMessage(message openai.ChatCompletionMessageParamUnion)

AddMessage adds a new message to the agent's message history

func (*BaseAgent) GenerateCompletion

func (agent *BaseAgent) GenerateCompletion(messages []openai.ChatCompletionMessageParamUnion) (response string, finishReason string, err error)

func (*BaseAgent) GenerateCompletionWithReasoning

func (agent *BaseAgent) GenerateCompletionWithReasoning(messages []openai.ChatCompletionMessageParamUnion) (response string, reasoning string, finishReason string, err error)

GenerateCompletionWithReasoning executes a chat completion with the provided messages. It sends the messages to the model and returns the first choice's content and reasoning.

Parameters:

  • messages: The conversation messages to send to the model

Returns:

  • string: The content of the first choice from the model's response
  • string: The reasoning content from the model's response

func (*BaseAgent) GenerateStreamCompletion

func (agent *BaseAgent) GenerateStreamCompletion(
	messages []openai.ChatCompletionMessageParamUnion,
	callBack func(partialResponse string, finishReason string) error) (response string, finishReason string, err error)

func (*BaseAgent) GenerateStreamCompletionWithReasoning

func (agent *BaseAgent) GenerateStreamCompletionWithReasoning(
	messages []openai.ChatCompletionMessageParamUnion,
	reasoningCallback func(partialReasoning string, finishReason string) error,
	responseCallback func(partialResponse string, finishReason string) error,
) (response string, reasoning string, finishReason string, err error)

func (*BaseAgent) GetCurrentContextSize

func (agent *BaseAgent) GetCurrentContextSize() (contextSize int)

func (*BaseAgent) GetMessages

func (agent *BaseAgent) GetMessages() (messages []openai.ChatCompletionMessageParamUnion)

func (*BaseAgent) GetStringMessages

func (agent *BaseAgent) GetStringMessages() (stringMessages []messages.Message)

GetStringMessages converts all messages to a slice of StringMessage with role and content as strings

func (*BaseAgent) Kind

func (agent *BaseAgent) Kind() (kind agents.Kind)

func (*BaseAgent) ResetMessages

func (agent *BaseAgent) ResetMessages()

ResetMessages clears the agent's message history except for the initial system message

func (*BaseAgent) StopStream

func (agent *BaseAgent) StopStream()

StopStream interrupts the current streaming operation

type CompletionResult

type CompletionResult struct {
	Response     string
	FinishReason string
}

CompletionResult represents the result of a chat completion

type ReasoningResult

type ReasoningResult struct {
	Response     string
	Reasoning    string
	FinishReason string
}

ReasoningResult represents the result of a chat completion with reasoning

type StreamCallback

type StreamCallback func(chunk string, finishReason string) error

StreamCallback is a function called for each chunk of streaming response

Jump to

Keyboard shortcuts

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