chatmodel

package
v0.14.108 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package chatmodel includes base IO schema definitions and message types for chat-based LLMs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedUnmarshalInput  = errors.New("failed to unmarshal input: check the schema and try again")
	ErrFailedUnmarshalOutput = errors.New("failed to unmarshal output: check the schema and try again")
)
View Source
var (
	ErrInvalidChatContext = errors.New("invalid chat context")
)

Functions

func GetOrgID added in v0.14.91

func GetOrgID(ctx context.Context) string

GetOrgID retrieves the org ID from the provided context. If the context does not contain a ChatContext, it returns "main".

func GetTenantAndChatID added in v0.1.7

func GetTenantAndChatID(ctx context.Context) (string, string, error)

GetTenantAndChatID retrieves the tenant and chat ID from the provided context. If the context does not contain a ChatContext, it returns error.

func NewChatID

func NewChatID() string

NewChatID generates a new chat ID using the flake ID generator.

func NewFromContext added in v0.5.26

func NewFromContext(ctx context.Context) context.Context

NewFromContext returns new Background context with ChatContext from incoming context. This is useful for passing the chat context to the background context of a service.

func SetChatID added in v0.3.11

func SetChatID(ctx context.Context, chatID string) (context.Context, error)

func Stringify

func Stringify(s any) string

func ToBytes

func ToBytes(s any) []byte

func WithChatContext

func WithChatContext(ctx context.Context, chatCtx ChatContext) context.Context

WithChatContext returns a new context with ChatContext value

Types

type BaseClarificationResult

type BaseClarificationResult struct {
	Confidence    string `` /* 161-byte string literal not displayed */
	Clarification string `` /* 205-byte string literal not displayed */
	Reasoning     string `` /* 128-byte string literal not displayed */
}

func (*BaseClarificationResult) SetClarification added in v0.3.14

func (b *BaseClarificationResult) SetClarification(clarification string)

func (*BaseClarificationResult) SetConfidence added in v0.3.14

func (b *BaseClarificationResult) SetConfidence(confidence string)

func (*BaseClarificationResult) SetReasoning added in v0.3.14

func (b *BaseClarificationResult) SetReasoning(reasoning string)

type ChatContext

type ChatContext interface {
	// GetTenantID retrieves the tenant ID from the context
	GetTenantID() string
	// GetChatID retrieves the chat ID from the context
	GetChatID() string
	// SetChatID updates the chat ID in the context
	SetChatID(id string)
	// AppData returns immutable app data
	AppData() any
	// GetMetadata retrieves metadata by key
	GetMetadata(key string) (value any, ok bool)
	// SetMetadata sets metadata by key
	SetMetadata(key string, value any)
	// RunID returns the run ID for the chat
	RunID() string
	// GetOrgID retrieves the org ID from the context.
	// This is also used in metrics.
	// Used by some providers to identify the organization of the tenant,
	// for example, "main" for the default organization.
	GetOrgID() string
	// SetOrgID updates the org ID in the context
	SetOrgID(id string)
}

ChatContext is the context for the chat agent,

func GetChatContext

func GetChatContext(ctx context.Context) ChatContext

GetChatContext retrieves the ChatContext from the context

func NewChatContext

func NewChatContext(tenantID, chatID string, appData any) ChatContext

type ContentProvider

type ContentProvider interface {
	// GetContent gets the content of the message
	GetContent() string
}

ContentProvider is an interface for providing content from a message.

type FewShotExample

type FewShotExample struct {
	Prompt     string
	Completion string
}

type FewShotExamples

type FewShotExamples []FewShotExample

type IBaseResult added in v0.3.14

type IBaseResult interface {
	SetConfidence(string)
	SetClarification(string)
	SetReasoning(string)
}

type InputParser added in v0.3.14

type InputParser interface {
	// ParseInput parses the input string and populates the struct fields.
	ParseInput(input string) error
}

InputParser is an interface for parsing input strings into structured data.

type InputRequest added in v0.3.12

type InputRequest struct {
	// Input is the message sent by the user to the assistant.
	Input string `json:"input" yaml:"input" jsonschema:"title=Input,description=The message sent by the user to the assistant."`
}

InputRequest represents the input from the user to the AI agent.

func NewInputRequest added in v0.3.12

func NewInputRequest(chatMessage string) *InputRequest

NewInputRequest returns a new InputRequest

func (InputRequest) GetContent added in v0.3.16

func (o InputRequest) GetContent() string

GetContent gets the content of the message for the chat history

func (InputRequest) JSONSchemaExtend added in v0.4.19

func (o InputRequest) JSONSchemaExtend(schema *jsonschema.Schema)

func (*InputRequest) ParseInput added in v0.3.14

func (o *InputRequest) ParseInput(input string) error

type MCPInputRequest added in v0.3.12

type MCPInputRequest struct {
	ChatID string `json:"chatID" yaml:"chatID" jsonschema:"title=Chat ID,description=The unique identifier for the chat session."`
	// Input is the message sent by the user to the assistant.
	Input string `json:"input" yaml:"input" jsonschema:"title=Input,description=The message sent by the user to the assistant."`
}

MCPInputRequest represents the MCP input from the user to the AI agent.

func (MCPInputRequest) JSONSchemaExtend added in v0.4.19

func (o MCPInputRequest) JSONSchemaExtend(schema *jsonschema.Schema)

func (*MCPInputRequest) ParseInput added in v0.3.14

func (o *MCPInputRequest) ParseInput(input string) error

type OutputParser

type OutputParser[T any] interface {
	// Parse parses the output of an LLM call.
	// If the assistant fails to parse the input, it should return ErrFailedUnmarshalInput error.
	Parse(text string) (*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 OutputResult added in v0.3.12

type OutputResult struct {
	// contains the markdown-enabled response generated by the chat agent.
	Content string `json:"content" yaml:"content" jsonschema:"title=Response Content,description=The content returned by agent or tool."`
}

OutputResult represents the response generated by the chat agent.

func NewOutputResult added in v0.3.12

func NewOutputResult(chatMessage string) *OutputResult

NewOutputResult returns a new OutputResult

func (OutputResult) GetContent added in v0.3.12

func (o OutputResult) GetContent() string

GetContent gets the content of the message for the chat history

type String added in v0.2.10

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

String is a simple string type that implements the ContentProvider interface.

func NewString added in v0.2.10

func NewString(str string) *String

func (String) Bytes added in v0.2.10

func (s String) Bytes() []byte

func (String) GetContent added in v0.2.10

func (o String) GetContent() string

GetContent gets the content of the message for the chat history

func (*String) ParseInput added in v0.3.14

func (o *String) ParseInput(input string) error

func (String) String added in v0.2.10

func (s String) String() string

func (*String) Unmarshal added in v0.2.10

func (s *String) Unmarshal(bs []byte) error

type Stringer

type Stringer interface {
	String() string
}

Jump to

Keyboard shortcuts

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