Documentation
¶
Overview ¶
Package chatmodel includes base IO schema definitions and message types for chat-based LLMs.
Index ¶
- Variables
- func GetOrgID(ctx context.Context) string
- func GetTenantAndChatID(ctx context.Context) (string, string, error)
- func NewChatID() string
- func NewFromContext(ctx context.Context) context.Context
- func SetChatID(ctx context.Context, chatID string) (context.Context, error)
- func Stringify(s any) string
- func ToBytes(s any) []byte
- func WithChatContext(ctx context.Context, chatCtx ChatContext) context.Context
- type BaseClarificationResult
- type ChatContext
- type ContentProvider
- type FewShotExample
- type FewShotExamples
- type IBaseResult
- type InputParser
- type InputRequest
- type MCPInputRequest
- type OutputParser
- type OutputResult
- type String
- type Stringer
Constants ¶
This section is empty.
Variables ¶
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") )
var (
ErrInvalidChatContext = errors.New("invalid chat context")
)
Functions ¶
func GetOrgID ¶ added in v0.14.91
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
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
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 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 FewShotExamples ¶
type FewShotExamples []FewShotExample
type IBaseResult ¶ added in v0.3.14
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 (String) GetContent ¶ added in v0.2.10
GetContent gets the content of the message for the chat history