Documentation
¶
Overview ¶
Package schema has the requests and responses of the registry's API
Index ¶
- Constants
- func ProviderTypes() []string
- func RedactURL(u *url.URL) string
- type AskRequest
- type AskResponse
- type EmbedAttachment
- type EmbedContent
- type EmbedForm
- type EmbedMessage
- type EmbedRequest
- type EmbedResponse
- type ErrorEvent
- type LoadModelRequest
- type Model
- type ModelList
- type ModelListRequest
- type ProgressEvent
- type Provider
- type ProviderCapabilities
- type ProviderList
- type ProviderListRequest
- type ProviderMeta
- type ProviderStatus
- type RecognizeForm
- type RecognizeRequest
- type RecognizeResponse
- type StreamEvent
- type TranscribeForm
- type TranscribeRequest
- type TranscribeResponse
Constants ¶
const ( EventText = string(llm.StreamText) EventThinking = string(llm.StreamThinking) )
The events of a stream of a model's reply: a text or thinking event for each piece of the reply as it's generated, and then a result event, with the response, or an error event
const ( EventName = "event" EventShutdown = "shutdown" )
The events of a stream of the registry's events: each event, and that the server is stopping, before the stream ends, so a client knows it ended as there will be no more events
const ( EventProgress = "progress" EventResult = "result" EventError = "error" )
The events of a stream of a model which is loaded: its progress, and then the model, or the error
const AskBodyLimit = 32 << 20
AskBodyLimit is the largest request body, in bytes, when a model is asked, which allows for images in the messages
const EmbedBodyLimit = 32 << 20
EmbedBodyLimit is the largest request body, in bytes, when messages are embedded, which allows for images and audio in the messages
const EventSegment = "segment"
EventSegment is the event of a stream of a transcript with a segment, once it's transcribed, when segments are asked for, as its text events have each piece of its text
const RecognizeBodyLimit = 64 << 20
RecognizeBodyLimit is the largest request body, in bytes, when text is recognized, which allows for a document of 48 MiB encoded as base64
const TranscribeBodyLimit = 48 << 20
TranscribeBodyLimit is the largest request body, in bytes, when speech is transcribed, which allows for audio of 32 MiB encoded as base64
Variables ¶
This section is empty.
Functions ¶
func ProviderTypes ¶
func ProviderTypes() []string
ProviderTypes returns the types of providers which the registry creates, in order
Types ¶
type AskRequest ¶
type AskRequest struct {
Model string `json:"model" help:"Model, by name, or by provider and name" example:"ollama:llama3.2:latest"`
System string `json:"system,omitempty" help:"System prompt, sent before the messages" example:"Be brief" optional:""`
Tools []string `` /* 208-byte string literal not displayed */
Opt map[string]json.RawMessage `` /* 139-byte string literal not displayed */
Schema json.RawMessage `` /* 199-byte string literal not displayed */
Messages []providerschema.MessageMeta `json:"messages" help:"Messages, including earlier turns of the conversation, and the results of the tools the model called"`
}
AskRequest asks a model for its reply to the messages, which include earlier turns of the conversation, after the system prompt, with the options. The model can call the tools, whose calls are in its reply, for the caller to run, and send their results back. With a schema, the model replies with JSON which conforms to it.
func (AskRequest) JSONSchema ¶
func (r AskRequest) JSONSchema() (*jsonschema.Schema, error)
JSONSchema returns the schema of the reply, or nil when the reply is text. Returns ErrBadParameter when it isn't a JSON schema.
func (AskRequest) Opts ¶
func (r AskRequest) Opts(system string) ([]llm.Opt, error)
Opts returns the system prompt, and the options, for the provider to decode. A tool choice of "none" isn't an option, as the model is sent no tools instead, so a provider which can't choose tools needn't. Returns ErrBadParameter when an option is one which the request has a field for, which is the system prompt, and the schema.
func (AskRequest) String ¶
func (r AskRequest) String() string
type AskResponse ¶
type AskResponse struct {
Model string `json:"model" help:"Canonical name of the model which replied" example:"ollama:llama3.2:latest"`
Message providerschema.Message `json:"message" help:"The model's reply, which can have the tools it called"`
Schema bool `` /* 135-byte string literal not displayed */
Result json.RawMessage `` /* 136-byte string literal not displayed */
Usage llm.Usage `json:"usage" help:"Tokens used, by every request to the model"`
}
AskResponse is the model's reply, with its canonical name, its result, when the request has a schema, and the model replied with JSON which conforms to it, and the tokens used
func (AskResponse) String ¶
func (r AskResponse) String() string
type EmbedAttachment ¶
type EmbedAttachment struct {
Type string `json:"type" help:"MIME type of the attachment" example:"image/png"`
Data []byte `json:"data" help:"Data of the attachment, encoded as base64" example:"iVBORw0KGgo="`
}
EmbedAttachment is an image or audio to embed, by its type and data, as a URL can't be read
type EmbedContent ¶
type EmbedContent struct {
Text *string `json:"text,omitempty" help:"Text to embed" example:"A cat asleep in the sun" optional:""`
Attachment *EmbedAttachment `json:"attachment,omitempty" help:"Image or audio to embed, for a model which embeds them" optional:""`
}
EmbedContent is a piece of a message to embed: its text, or an attachment
type EmbedForm ¶
type EmbedForm struct {
Model string `json:"model" help:"Model for the embedding, by name, or by provider and name" example:"ollama:embeddinggemma-2:latest"`
Opt string `` /* 144-byte string literal not displayed */
File types.File `` /* 208-byte string literal not displayed */
}
EmbedForm is the form for embedding one message, such as from a web browser, which is a file, uploaded as text, an image or audio, which is read as an EmbedRequest with one message, as RecognizeForm is. The options are a JSON object, as a form's values are strings.
type EmbedMessage ¶
type EmbedMessage struct {
Content []EmbedContent `json:"content" help:"Text and attachments of the message to embed" example:"[{\"text\":\"A cat asleep in the sun\"}]"`
}
EmbedMessage is a message to embed, by its text, and its images and audio, inline, as a message has them, without the role, thinking or tools, which aren't embedded
type EmbedRequest ¶
type EmbedRequest struct {
Model string `json:"model" help:"Model for the embeddings, by name, or by provider and name" example:"ollama:embeddinggemma-2:latest"`
Messages []EmbedMessage `json:"messages" help:"Messages to embed, each by its text, and its images and audio for a model which embeds them"`
Opt map[string]json.RawMessage `json:"opt,omitzero" help:"Options for embeddings, by key, such as dimensions=256" example:"{\"dimensions\":256}" optional:""`
}
EmbedRequest asks a model for a vector for each of the messages, such as for semantic search, with the options. It's one model, as vectors from different models can't be compared.
func (EmbedRequest) Opts ¶
func (r EmbedRequest) Opts() []llm.Opt
Opts returns the options, for the provider to decode
func (EmbedRequest) String ¶
func (r EmbedRequest) String() string
type EmbedResponse ¶
type EmbedResponse struct {
Model string `json:"model" help:"Canonical name of the model which embedded the messages" example:"ollama:embeddinggemma-2:latest"`
Vectors []llm.Vector `json:"vectors" help:"A vector for each of the messages, in the same order"`
Usage llm.Usage `json:"usage" help:"Tokens used, which are input tokens"`
}
EmbedResponse is a vector for each of the messages, in the same order, with the model which embedded them, and the tokens used
func (EmbedResponse) String ¶
func (r EmbedResponse) String() string
type ErrorEvent ¶
type ErrorEvent struct {
Error string `json:"error" help:"Why the model couldn't be loaded"`
}
ErrorEvent is the data of an error event, which ends a stream when it fails
type LoadModelRequest ¶
type LoadModelRequest struct {
Provider string `` /* 182-byte string literal not displayed */
Name string `json:"name" help:"Name of the model to load" example:"llama3.2:latest"`
}
LoadModelRequest is a request to load a model, with a provider which loads models, such as Ollama, which downloads it when it isn't stored
func (LoadModelRequest) String ¶
func (r LoadModelRequest) String() string
type Model ¶
type Model struct {
Name string `json:"name" readonly:"" help:"Model name" example:"llama3.2:latest"`
Provider string `json:"provider" readonly:"" help:"Name of the model's provider in the registry" example:"my-ollama"`
Canonical string `` /* 158-byte string literal not displayed */
Description string `json:"description,omitempty" readonly:"" help:"Model description"`
Created time.Time `json:"created,omitzero" readonly:"" help:"When the model was created"`
Aliases []string `json:"aliases,omitempty" readonly:"" help:"Other names for the model"`
Meta map[string]json.RawMessage `json:"meta,omitempty" readonly:"" help:"Provider-specific metadata"`
InputTokenLimit *uint `json:"input_token_limit,omitempty" readonly:"" help:"Maximum number of input tokens"`
OutputTokenLimit *uint `json:"output_token_limit,omitempty" readonly:"" help:"Maximum number of output tokens"`
Capabilities llm.ModelCap `json:"capabilities" readonly:"" help:"What the model can do, of what's known"`
}
Model is a model of a provider in the registry
type ModelList ¶
type ModelList struct {
ModelListRequest
Count uint `json:"count"`
Body []*Model `json:"body,omitempty"`
}
ModelList is the models of the providers in the registry, in order of their providers' names, and then their names
type ModelListRequest ¶
type ModelListRequest struct {
Provider string `` /* 135-byte string literal not displayed */
}
ModelListRequest filters a list of models
func (ModelListRequest) Query ¶
func (r ModelListRequest) Query() url.Values
Query returns the request as the query of a URL
func (ModelListRequest) String ¶
func (r ModelListRequest) String() string
type ProgressEvent ¶
type ProgressEvent struct {
Status string `json:"status" help:"Status of the download"`
Percent float64 `json:"percent" help:"Percentage of the download which is complete, from 0 to 100"`
}
ProgressEvent is the data of a progress event, streamed while a model is loaded
type Provider ¶
type Provider struct {
Name string `` /* 218-byte string literal not displayed */
Type string `json:"provider" help:"Provider type" enum:"elevenlabs,eliza,gowhisper,ollama,openai" example:"ollama"`
ProviderMeta
Serial uint64 `` /* 130-byte string literal not displayed */
}
Provider is a provider's definition: its name in the registry, so there can be more than one provider of a type, its type, its fields which can be set, and its serial, which changes each time its definition does. It's what's needed to create it, and what a store of providers holds.
type ProviderCapabilities ¶
type ProviderCapabilities struct {
Generator bool `json:"generator,omitempty" readonly:"" help:"Whether the provider generates messages"`
Embedder bool `json:"embedder,omitempty" readonly:"" help:"Whether the provider embeds messages"`
Downloader bool `json:"downloader,omitempty" readonly:"" help:"Whether the provider downloads and deletes models, such as Ollama"`
Transcriber bool `json:"transcriber,omitempty" readonly:"" help:"Whether the provider transcribes and translates audio"`
Recognizer bool `json:"recognizer,omitempty" readonly:"" help:"Whether the provider recognizes text in images and documents"`
}
ProviderCapabilities are what a provider can do
func (ProviderCapabilities) String ¶
func (c ProviderCapabilities) String() string
type ProviderList ¶
type ProviderList struct {
ProviderListRequest
Count uint `json:"count"`
Body []*ProviderStatus `json:"body,omitempty"`
}
ProviderList is the providers in the registry, in order of their names
func (ProviderList) String ¶
func (l ProviderList) String() string
type ProviderListRequest ¶
type ProviderListRequest struct {
Type string `json:"provider,omitempty" help:"Returns only the providers of this type" example:"ollama" optional:""`
}
ProviderListRequest filters a list of providers
func (ProviderListRequest) Query ¶
func (r ProviderListRequest) Query() url.Values
Query returns the request as the query of a URL
func (ProviderListRequest) String ¶
func (r ProviderListRequest) String() string
type ProviderMeta ¶
type ProviderMeta struct {
URL string `` /* 170-byte string literal not displayed */
Include []string `` /* 167-byte string literal not displayed */
Exclude []string `` /* 132-byte string literal not displayed */
APIKey string `` /* 171-byte string literal not displayed */
}
ProviderMeta are the fields of a provider which can be set, and changed: its endpoint, which isn't needed for every type, the patterns of the names of its models, and its API key, which isn't returned
func (ProviderMeta) Equal ¶
func (m ProviderMeta) Equal(other ProviderMeta) bool
Equal returns true when the fields are the same: the endpoint, API key, or its placeholder, and patterns
func (ProviderMeta) String ¶
func (m ProviderMeta) String() string
type ProviderStatus ¶
type ProviderStatus struct {
Provider
ProviderCapabilities
Error string `json:"error,omitempty" readonly:"" help:"Why the provider can't be reached, when it can't"`
}
ProviderStatus is a provider in the registry: its definition, without its API key, and what's known of it now, which is what it can do, and the error of its ping, when it can't be reached
func (ProviderStatus) Header ¶
func (p ProviderStatus) Header() []string
func (ProviderStatus) String ¶
func (p ProviderStatus) String() string
func (ProviderStatus) Width ¶
func (p ProviderStatus) Width(col int) int
type RecognizeForm ¶
type RecognizeForm struct {
Model string `json:"model" help:"Model which recognizes text, by name, or by provider and name" example:"mistral:mistral-ocr-latest"`
Opt string `json:"opt,omitempty" help:"Options, as a JSON object, such as {\"pages\":\"0-1\"}" example:"{\"pages\":\"0-1\"}" optional:""`
File types.File `json:"file,omitzero" help:"Image or document to recognize, uploaded as a file"`
}
RecognizeForm is the form for recognizing the text in an image or document uploaded as a file, such as from a web browser, which is read as a RecognizeRequest. The options are a JSON object, as a form's values are strings.
type RecognizeRequest ¶
type RecognizeRequest struct {
Model string `json:"model" help:"Model which recognizes text, by name, or by provider and name" example:"mistral:mistral-ocr-latest"`
Type string `json:"type" help:"MIME type of the image or document" example:"application/pdf"`
Data []byte `json:"data" help:"Data of the image or document, encoded as base64" example:"JVBERi0xLjQ="`
Opt map[string]json.RawMessage `` /* 174-byte string literal not displayed */
}
RecognizeRequest asks a model for the text in an image, or a document such as a PDF, by its type and data, with the options
func (RecognizeRequest) Opts ¶
func (r RecognizeRequest) Opts() []llm.Opt
Opts returns the options, for the provider to decode
func (RecognizeRequest) Resource ¶
func (r RecognizeRequest) Resource() (llm.Resource, error)
Resource returns the image or document to recognize, or an error when it has no type, or no data
func (RecognizeRequest) String ¶
func (r RecognizeRequest) String() string
String returns the request without its data, which can be large
type RecognizeResponse ¶
type RecognizeResponse struct {
Model string `json:"model" help:"Canonical name of the model which recognized the text" example:"mistral:mistral-ocr-latest"`
llm.Document
Usage llm.Usage `json:"usage" help:"Pages recognized, and tokens used, for providers which report them"`
}
RecognizeResponse is the text of each page, in order, in Markdown, and its regions, when they're asked for, with the model which recognized it, and the pages, and tokens, used
func (RecognizeResponse) String ¶
func (r RecognizeResponse) String() string
type StreamEvent ¶
type StreamEvent struct {
Text string `json:"text" help:"A piece of the reply's text, or of the model's thinking"`
}
StreamEvent is the data of a text or thinking event, which is a piece of the reply as it's generated
type TranscribeForm ¶
type TranscribeForm struct {
Model string `json:"model" help:"Model which transcribes speech, by name, or by provider and name" example:"openai:whisper-1"`
Opt string `json:"opt,omitempty" help:"Options, as a JSON object, such as {\"segments\":true}" example:"{\"segments\":true}" optional:""`
File types.File `json:"file,omitzero" help:"Audio to transcribe, uploaded as a file"`
}
TranscribeForm is the form for transcribing, or translating, the speech in audio uploaded as a file, such as from a web browser, which is read as a TranscribeRequest. The options are a JSON object, as a form's values are strings.
type TranscribeRequest ¶
type TranscribeRequest struct {
Model string `json:"model" help:"Model which transcribes speech, by name, or by provider and name" example:"openai:whisper-1"`
Type string `json:"type" help:"MIME type of the audio" example:"audio/mpeg"`
Data []byte `json:"data" help:"Data of the audio, encoded as base64" example:"SUQzBAAAAAAA"`
Opt map[string]json.RawMessage `` /* 167-byte string literal not displayed */
}
TranscribeRequest asks a model for the speech in audio, by its type and data, as text, in the language it was spoken in, or translated into English, with the options
func (TranscribeRequest) Opts ¶
func (r TranscribeRequest) Opts() []llm.Opt
Opts returns the options, for the provider to decode
func (TranscribeRequest) Resource ¶
func (r TranscribeRequest) Resource() (llm.Resource, error)
Resource returns the audio to transcribe, or an error when it has no type, or no data
func (TranscribeRequest) String ¶
func (r TranscribeRequest) String() string
String returns the request without its data, which can be large
type TranscribeResponse ¶
type TranscribeResponse struct {
Model string `json:"model" help:"Canonical name of the model which transcribed the speech" example:"openai:whisper-1"`
llm.Transcript
Usage llm.Usage `json:"usage" help:"Seconds of audio, and tokens, used, for providers which report them"`
}
TranscribeResponse is the transcript, with its language, when it's known, and its segments, when they're asked for, with the model which transcribed it, and the seconds, and tokens, used
func (TranscribeResponse) String ¶
func (r TranscribeResponse) String() string