Documentation
¶
Index ¶
- func Ptr[T any](v T) *T
- func ReadAllString(r io.Reader) string
- type ChatCompleteFinishReason
- type ChatCompleteRequest
- type ChatCompleteResponse
- type ChatCompleteResponseMetadata
- type ChatCompleteResponseUsage
- type ChatCompleter
- type EmbedRequest
- type EmbedResponse
- type Embedder
- type Message
- type MessagePart
- type MessagePartType
- type MessageRole
- type Schema
- type SchemaType
- type Temperature
- type ThinkingLevel
- type Tool
- type ToolCall
- type ToolFunction
- type ToolResult
- type ToolSchema
- type VectorComponent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadAllString ¶
ReadAllString is like io.ReadAll, but returns a string, and panics on errors. Useful for situations where the read cannot error.
Types ¶
type ChatCompleteFinishReason ¶
type ChatCompleteFinishReason string
ChatCompleteFinishReason describes why the model stopped generating tokens.
const ( // ChatCompleteFinishReasonUnknown indicates that the provider did not supply a recognised termination code. ChatCompleteFinishReasonUnknown ChatCompleteFinishReason = "unknown" // ChatCompleteFinishReasonStop indicates that generation stopped naturally or due to a configured stop sequence. ChatCompleteFinishReasonStop ChatCompleteFinishReason = "stop" // ChatCompleteFinishReasonLength indicates that generation hit the configured token limit. ChatCompleteFinishReasonLength ChatCompleteFinishReason = "length" // ChatCompleteFinishReasonContentFilter indicates that a platform-level moderation filter blocked the content. ChatCompleteFinishReasonContentFilter ChatCompleteFinishReason = "content_filter" // ChatCompleteFinishReasonToolCalls indicates that the model requested a tool invocation mid-response. ChatCompleteFinishReasonToolCalls ChatCompleteFinishReason = "tool_calls" // ChatCompleteFinishReasonRefusal indicates that the model produced a refusal message of its own accord. ChatCompleteFinishReasonRefusal ChatCompleteFinishReason = "refusal" )
type ChatCompleteRequest ¶
type ChatCompleteRequest struct {
MaxCompletionTokens *int
Messages []Message
ResponseSchema *Schema
System *string
Temperature *Temperature
ThinkingLevel *ThinkingLevel
Tools []Tool
}
ChatCompleteRequest for a chat model.
type ChatCompleteResponse ¶
type ChatCompleteResponse struct {
Meta *ChatCompleteResponseMetadata
// contains filtered or unexported fields
}
ChatCompleteResponse for ChatCompleter. Construct with NewChatCompleteResponse. Note that the [ChatCompleteResponse.Meta] field is a pointer, because it's updated continuously until the streaming response with ChatCompleteResponse.Parts is complete.
func NewChatCompleteResponse ¶
func NewChatCompleteResponse(partsFunc iter.Seq2[MessagePart, error]) ChatCompleteResponse
func (ChatCompleteResponse) Parts ¶
func (c ChatCompleteResponse) Parts() iter.Seq2[MessagePart, error]
type ChatCompleteResponseMetadata ¶
type ChatCompleteResponseMetadata struct {
Usage ChatCompleteResponseUsage
// FinishReason is optional; nil indicates the provider omitted a finish signal entirely.
FinishReason *ChatCompleteFinishReason
}
ChatCompleteResponseMetadata contains metadata about the request and response, for example, token usage.
type ChatCompleter ¶
type ChatCompleter interface {
ChatComplete(ctx context.Context, req ChatCompleteRequest) (ChatCompleteResponse, error)
}
ChatCompleter is satisfied by models supporting chat completion. Streaming chat completion is preferred where possible, so that methods on ChatCompleteResponse, like ChatCompleteResponse.Parts, can be used to stream the response.
type EmbedResponse ¶
type EmbedResponse[T VectorComponent] struct { Embedding []T }
EmbedResponse for Embedder.
type Embedder ¶
type Embedder[T VectorComponent] interface { Embed(ctx context.Context, p EmbedRequest) (EmbedResponse[T], error) }
Embedder is satisfied by models supporting embedding.
type Message ¶
type Message struct {
Role MessageRole
Parts []MessagePart
}
func NewModelTextMessage ¶
NewModelTextMessage is a convenience function to create a new model text message.
func NewUserDataMessage ¶
NewUserDataMessage is a convenience function to create a new user data message.
func NewUserTextMessage ¶
NewUserTextMessage is a convenience function to create a new user text message.
func NewUserToolResultMessage ¶
func NewUserToolResultMessage(result ToolResult) Message
type MessagePart ¶
type MessagePart struct {
Type MessagePartType
Data io.Reader
MIMEType string
// contains filtered or unexported fields
}
func DataMessagePart ¶
func DataMessagePart(mimeType string, data io.Reader) MessagePart
func TextMessagePart ¶
func TextMessagePart(text string) MessagePart
func ToolCallPart ¶
func ToolCallPart(id, name string, args json.RawMessage) MessagePart
func (MessagePart) Text ¶
func (m MessagePart) Text() string
func (MessagePart) ToolCall ¶
func (m MessagePart) ToolCall() ToolCall
func (MessagePart) ToolResult ¶
func (m MessagePart) ToolResult() ToolResult
type MessagePartType ¶
type MessagePartType string
MessagePartType for MessagePart.
const ( MessagePartTypeData MessagePartType = "data" MessagePartTypeText MessagePartType = "text" MessagePartTypeToolCall MessagePartType = "tool_call" MessagePartTypeToolResult MessagePartType = "tool_result" )
type MessageRole ¶
type MessageRole string
MessageRole for Message.
const ( MessageRoleUser MessageRole = "user" MessageRoleModel MessageRole = "model" )
type Schema ¶
type Schema struct {
// Optional. The value should be validated against any (one or more) of the subschemas
// in the list.
AnyOf []*Schema `json:"anyOf,omitempty"`
// Optional. Default value of the data.
Default any `json:"default,omitempty"`
// Optional. The description of the data.
Description string `json:"description,omitempty"`
// Optional. Possible values of the element of primitive type with enum format. Examples:
// 1. We can define direction as : {type:STRING, format:enum, enum:["EAST", NORTH",
// "SOUTH", "WEST"]} 2. We can define apartment number as : {type:INTEGER, format:enum,
// enum:["101", "201", "301"]}
Enum []string `json:"enum,omitempty"`
// Optional. Example of the object. Will only populated when the object is the root.
Example any `json:"example,omitempty"`
// Optional. The format of the data. Supported formats: for NUMBER type: "float", "double"
// for INTEGER type: "int32", "int64" for STRING type: "email", "byte", etc
Format string `json:"format,omitempty"`
// Optional. SCHEMA FIELDS FOR TYPE ARRAY Schema of the elements of Type.ARRAY.
Items *Schema `json:"items,omitempty"`
// Optional. Maximum number of the elements for Type.ARRAY.
MaxItems *int64 `json:"maxItems,omitempty,string"`
// Optional. Maximum value of the Type.INTEGER and Type.NUMBER
Maximum *float64 `json:"maximum,omitempty"`
// Optional. Minimum number of the elements for Type.ARRAY.
MinItems *int64 `json:"minItems,omitempty,string"`
// Optional. Minimum value of the Type.INTEGER and Type.NUMBER.
Minimum *float64 `json:"minimum,omitempty"`
// Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT.
Properties map[string]*Schema `json:"properties,omitempty"`
// Optional. The order of the properties. Not a standard field in open API spec. Only
// used to support the order of the properties.
PropertyOrdering []string `json:"propertyOrdering,omitempty"`
// Optional. Required properties of Type.OBJECT.
Required []string `json:"required,omitempty"`
// Optional. The title of the Schema.
Title string `json:"title,omitempty"`
// Optional. The type of the data.
Type SchemaType `json:"type,omitempty"`
}
func GenerateSchema ¶
GenerateSchema from any type. See github.com/invopop/jsonschema for struct tags etc.
type SchemaType ¶
type SchemaType string
const ( // OpenAPI string type SchemaTypeString SchemaType = "string" // OpenAPI number type SchemaTypeNumber SchemaType = "number" // OpenAPI integer type SchemaTypeInteger SchemaType = "integer" // OpenAPI boolean type SchemaTypeBoolean SchemaType = "boolean" // OpenAPI array type SchemaTypeArray SchemaType = "array" // OpenAPI object type SchemaTypeObject SchemaType = "object" )
type Temperature ¶
type Temperature float64
func (Temperature) Float64 ¶
func (t Temperature) Float64() float64
type ThinkingLevel ¶
type ThinkingLevel string
ThinkingLevel controls how much reasoning effort the model applies. Not all levels are supported by all providers; unsupported levels will panic.
const ( // ThinkingLevelNone disables thinking entirely. ThinkingLevelNone ThinkingLevel = "none" // ThinkingLevelMinimal applies minimal thinking. ThinkingLevelMinimal ThinkingLevel = "minimal" // ThinkingLevelLow applies low thinking effort. ThinkingLevelLow ThinkingLevel = "low" // ThinkingLevelMedium applies medium thinking effort. ThinkingLevelMedium ThinkingLevel = "medium" // ThinkingLevelHigh applies high thinking effort. ThinkingLevelHigh ThinkingLevel = "high" // ThinkingLevelXHigh applies extra-high thinking effort. ThinkingLevelXHigh ThinkingLevel = "xhigh" // ThinkingLevelMax applies maximum thinking effort. ThinkingLevelMax ThinkingLevel = "max" )
type Tool ¶
type Tool struct {
Name string
Description string
Schema ToolSchema
Execute ToolFunction
Summarize ToolFunction
}
Tool definition.
type ToolFunction ¶
type ToolResult ¶
TODO tool result can be string but also other types, such as image!
type ToolSchema ¶
ToolSchema in JSON Schema format of the arguments the tool accepts.
func GenerateToolSchema ¶
func GenerateToolSchema[T any]() ToolSchema
Directories
¶
| Path | Synopsis |
|---|---|
|
clients
|
|
|
Package eval lets you evaluate models with various Scorer functions.
|
Package eval lets you evaluate models with various Scorer functions. |
|
internal
|
|
|
examples/tools
command
|
|
|
examples/tools_custom
command
|
|