Documentation
¶
Overview ¶
Package schema has the messages which providers reply with, which implement llm.Message, so providers share them
Index ¶
- Constants
- func AudioName(name, contentType string) string
- func LanguageCode(language string) string
- func ResourceType(data []byte, name string) string
- func UnknownType(contentType string) bool
- type ContentBlock
- type Event
- type EventAction
- type Message
- type MessageMeta
- type Resource
- type ResourceMeta
- type ResultType
- type ToolCall
- type ToolResult
Constants ¶
const ResultOK = ResultStop
ResultOK is an alias for ResultStop (normal completion).
Variables ¶
This section is empty.
Functions ¶
func AudioName ¶
AudioName returns the name of an audio file, which is its name, when it has the extension of an audio file, or otherwise "audio", with the extension of its type, such as "audio.wav" for audio/wave, as an API may detect an audio file's format from its name
func LanguageCode ¶
LanguageCode returns the ISO 639-1 code of a language, by the name whisper returns it as, such as "fr" for "french", in any case, or the language, in lower case, when it isn't one of whisper's, such as a code, or an empty string when there's none
func ResourceType ¶
ResourceType returns the MIME type of a resource's data, detected from the data, such as image/png or audio/wave, or from the extension of its name, when the data isn't recognised, or is only text, or is an Ogg container, which the extension is more specific about, such as text/markdown or audio/ogg. Ogg data without an extension is audio/ogg, as Ogg is almost always audio, and MP4 data whose brand is M4A or M4B, or which is named .m4a or .m4b, is audio/mp4. Without data, it's the type of the extension. Returns application/octet-stream when neither is recognised, and an empty string when there's no data, and the extension isn't known.
func UnknownType ¶
UnknownType returns true when the MIME type is empty, or is application/octet-stream, in any case, and with any parameters, so it's detected from the data
Types ¶
type ContentBlock ¶
type ContentBlock struct {
Text *string `` /* 141-byte string literal not displayed */
Thinking *string `` /* 136-byte string literal not displayed */
Resource *Resource `` /* 173-byte string literal not displayed */
ToolCall *ToolCall `` /* 161-byte string literal not displayed */
ToolResult *ToolResult `` /* 190-byte string literal not displayed */
}
ContentBlock represents a single piece of content within a message. Exactly one of the fields should be non-nil/non-empty.
func NewToolError ¶
func NewToolError(id, name string, err error) ContentBlock
NewToolError creates a content block containing the error from the tool call with the id and name, with the error message as a JSON string
func NewToolResult ¶
func NewToolResult(id, name string, v any) ContentBlock
NewToolResult creates a content block containing the result of the tool call with the id and name, or a tool error if the result is an error, or can't be encoded as JSON
type Event ¶
type Event struct {
Action EventAction `json:"action" help:"How it changed, which is create, update or delete" example:"create"`
Schema string `json:"schema,omitempty" help:"Schema of the table which changed" example:"llm"`
Table string `json:"table,omitempty" help:"Table which changed" example:"provider"`
Row string `json:"row,omitempty" help:"Row, or rows, which changed, such as by an identifier" example:"ollama"`
}
Event is a change: how it changed, which is its action, what changed, which is a table of a schema, and which row, or rows, changed, when it says, such as by an identifier which the rows share
type EventAction ¶
type EventAction string
EventAction is how something changed: it was created, updated or deleted
const ( EventCreate EventAction = "create" // Created EventUpdate EventAction = "update" // Updated EventDelete EventAction = "delete" // Deleted )
func (EventAction) String ¶
func (a EventAction) String() string
func (*EventAction) UnmarshalJSON ¶
func (a *EventAction) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes an action, which must be one of the actions
type Message ¶
type Message struct {
MessageMeta
Tokens uint64 `json:"tokens,omitempty" help:"Token count attributed to this message" example:"12"`
Result ResultType `` /* 158-byte string literal not displayed */
}
Message is a message in a conversation with a model, as a provider replies with it, with the tokens it used, and why the model stopped generating it
func MessageFrom ¶
MessageFrom returns the message, which is a schema message, or otherwise a new message with the message's role and text. Resources are left out of a new message, as they'd need to be read.
func NewMessage ¶
Create a new message with the given role and text content
type MessageMeta ¶
type MessageMeta struct {
Sender string `` /* 139-byte string literal not displayed */
Content []ContentBlock `` /* 162-byte string literal not displayed */
}
MessageMeta is a message as it's sent to a model: its role, which is the user's when omitted, and its content. It uses a universal content block representation that can be marshaled to any provider's format.
func (MessageMeta) Resources ¶
func (m MessageMeta) Resources() []llm.Resource
Resources returns the resource content blocks of the message
func (MessageMeta) Role ¶
func (m MessageMeta) Role() string
Role returns the role of the message, which is the user's when it's omitted
func (MessageMeta) Text ¶
func (m MessageMeta) Text() string
Text returns the text content blocks of the message, joined with newlines
func (MessageMeta) Thinking ¶
func (m MessageMeta) Thinking() string
Thinking returns the thinking content blocks of the message, joined with newlines, which some providers need sent back with the message's tool calls
func (MessageMeta) ToolCalls ¶
func (m MessageMeta) ToolCalls() []llm.ToolCall
ToolCalls returns the tool call content blocks of the message
func (MessageMeta) ToolResults ¶
func (m MessageMeta) ToolResults() []llm.ToolResult
ToolResults returns the tool result content blocks of the message
type Resource ¶
type Resource struct {
ResourceMeta
}
Resource represents binary or URI-referenced media (images, documents, etc.) in a message
func (Resource) Description ¶
Description returns an empty string, as resources in a message don't have a description
func (Resource) Name ¶
Name returns the last element of the path of the resource's URL, or an empty string when it's inline data only
type ResourceMeta ¶
type ResourceMeta struct {
ContentType string `json:"type" help:"Attachment MIME type, for example image/png or application/pdf" example:"image/png"`
Data []byte `json:"data,omitempty" help:"Inline attachment payload encoded as a byte string" example:"iVBORw0KGgo="`
URL *url.URL `json:"url,omitempty" help:"Attachment URL reference, for example https, gs, or file" example:"https://example.com/image.png"`
}
ResourceMeta holds the fields of a resource which can be set: its type and its data, a URL, or both
type ResultType ¶
type ResultType string
The result of generating a message (stopped, error, etc.)
const ( ResultStop ResultType = "stop" // Normal completion ResultMaxTokens ResultType = "max_tokens" // Truncated due to max tokens ResultBlocked ResultType = "blocked" // Blocked by safety, recitation, or content filter ResultToolCall ResultType = "tool_call" // Model requested a tool call ResultError ResultType = "error" // Generation error ResultOther ResultType = "other" // Other/unknown finish reason ResultMaxIterations ResultType = "max_iterations" // Tool-calling loop exhausted max iterations )
func (ResultType) String ¶
func (r ResultType) String() string
func (*ResultType) UnmarshalJSON ¶
func (r *ResultType) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a result, which must be one of the results
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty" help:"Provider-assigned tool call identifier" example:"call_123"`
Name string `json:"name" help:"Tool name to invoke" example:"get_weather"`
Input json.RawMessage `json:"input,omitempty" help:"JSON-encoded arguments passed to the tool" example:"{\"city\":\"London\"}"`
Meta map[string]any `json:"meta,omitempty" help:"Provider-specific metadata associated with the tool call" example:"{\"provider\":\"demo\"}"`
}
ToolCall represents a tool invocation requested by the model
type ToolResult ¶
type ToolResult struct {
ID string `json:"id,omitempty" help:"Tool call identifier this result belongs to" example:"call_123"`
Name string `json:"name,omitempty" help:"Tool name that produced this result" example:"get_weather"`
Content json.RawMessage `json:"content,omitempty" help:"JSON-encoded tool output content" example:"{\"temperature_c\":18}"`
IsError bool `json:"is_error,omitempty" help:"Whether the tool result represents an error" example:"false"`
}
ToolResult represents the result of running a tool