Documentation
¶
Overview ¶
Package httpclient is a client of the registry's HTTP API
Index ¶
- type Client
- func (c *Client) Ask(ctx context.Context, req schema.AskRequest, stream llm.GeneratorStreamFn) (*schema.AskResponse, error)
- func (c *Client) CreateProvider(ctx context.Context, provider schema.Provider) (*schema.ProviderStatus, error)
- func (c *Client) DeleteModel(ctx context.Context, name string) (*schema.Model, error)
- func (c *Client) DeleteProvider(ctx context.Context, name string) (*schema.ProviderStatus, error)
- func (c *Client) Embed(ctx context.Context, req schema.EmbedRequest) (*schema.EmbedResponse, error)
- func (c *Client) GetModel(ctx context.Context, name string) (*schema.Model, error)
- func (c *Client) GetProvider(ctx context.Context, name string) (*schema.ProviderStatus, error)
- func (c *Client) ListModels(ctx context.Context, req schema.ModelListRequest) (*schema.ModelList, error)
- func (c *Client) ListProviders(ctx context.Context, req schema.ProviderListRequest) (*schema.ProviderList, error)
- func (c *Client) LoadModel(ctx context.Context, req schema.LoadModelRequest, ...) (*schema.Model, error)
- func (c *Client) Recognize(ctx context.Context, req schema.RecognizeRequest) (*schema.RecognizeResponse, error)
- func (c *Client) Transcribe(ctx context.Context, req schema.TranscribeRequest, ...) (*schema.TranscribeResponse, error)
- func (c *Client) Translate(ctx context.Context, req schema.TranscribeRequest, ...) (*schema.TranscribeResponse, error)
- func (c *Client) UnloadModel(ctx context.Context, name string) (*schema.Model, error)
- func (c *Client) UpdateProvider(ctx context.Context, name string, meta schema.ProviderMeta) (*schema.ProviderStatus, error)
- func (c *Client) WatchEvents(ctx context.Context, fn func(providerschema.Event) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is a client of the registry's HTTP API, which wraps the base HTTP client, with typed methods for its requests
func New ¶
New returns a client of the registry's API, at the URL, which is the server's API endpoint, such as http://localhost:8084/api, with the options. Each method adds its own path, such as llm/provider, as the registry's handlers register them.
func (*Client) Ask ¶
func (c *Client) Ask(ctx context.Context, req schema.AskRequest, stream llm.GeneratorStreamFn) (*schema.AskResponse, error)
Ask returns the reply of the request's model to its messages, with the tools it called, for the caller to run, the reply's result, when the request has a schema, and the tokens used. When the stream function isn't nil, the reply is streamed, and the function is called with each piece of its text and thinking as it's generated. The request isn't timed out, as a model can take a while to reply, but is cancelled with the context.
func (*Client) CreateProvider ¶
func (c *Client) CreateProvider(ctx context.Context, provider schema.Provider) (*schema.ProviderStatus, error)
CreateProvider creates a provider of the type, with its name, endpoint and API key, which can be a credential's placeholder, such as ${OPENAI_KEY}, and returns it, once it's reached
func (*Client) DeleteModel ¶
DeleteModel deletes the model with the name, or alias, or provider and name, such as my-ollama:gemma:latest, from its provider's storage, and returns it
func (*Client) DeleteProvider ¶
DeleteProvider deletes the provider with the name from the registry, and returns it
func (*Client) Embed ¶
func (c *Client) Embed(ctx context.Context, req schema.EmbedRequest) (*schema.EmbedResponse, error)
Embed returns a vector for each of the messages in the request, in the same order, from its model, with the model's canonical name, and the tokens used. A model is its name, or the provider and name separated by ":", such as "ollama:embeddinggemma-2:latest". The request isn't timed out, as a model can take a while to load, but is cancelled with the context.
func (*Client) GetModel ¶
GetModel returns the model with the name, or alias, or provider and name, separated by a colon, such as my-ollama:llama3.2:latest. The name is one segment of the path, so a "/" in it is escaped.
func (*Client) GetProvider ¶
GetProvider returns the provider with the name, with whether it can be reached
func (*Client) ListModels ¶
func (c *Client) ListModels(ctx context.Context, req schema.ModelListRequest) (*schema.ModelList, error)
ListModels returns the models of the providers, or of the provider which the request selects, in order of their providers' names, and then their names
func (*Client) ListProviders ¶
func (c *Client) ListProviders(ctx context.Context, req schema.ProviderListRequest) (*schema.ProviderList, error)
ListProviders returns the providers, in order of their names, of the type which the request selects, or every type, with whether each can be reached
func (*Client) LoadModel ¶
func (c *Client) LoadModel(ctx context.Context, req schema.LoadModelRequest, progress llm.DownloadProgressFn) (*schema.Model, error)
LoadModel loads the model in the request, with its provider, or the one provider which loads models, which downloads it when it isn't stored, and returns it. Loading isn't timed out, as models can be large, but is cancelled with the context. When the progress function isn't nil, the download's progress is streamed, and the function is called with each progress event.
func (*Client) Recognize ¶
func (c *Client) Recognize(ctx context.Context, req schema.RecognizeRequest) (*schema.RecognizeResponse, error)
Recognize returns the text in the image or document of the request, as a message with a text block for each page, in order, from its model, with the model's canonical name, and the pages and tokens used. A model is its name, or the provider and name separated by ":", such as "mistral:mistral-ocr-latest". The request isn't timed out, as a document can take a while, but is cancelled with the context.
func (*Client) Transcribe ¶
func (c *Client) Transcribe(ctx context.Context, req schema.TranscribeRequest, stream llm.TranscriberStreamFn) (*schema.TranscribeResponse, error)
Transcribe returns the speech in the audio of the request, as text, in the language it was spoken in, and its segments, when they're asked for, from its model, with the model's canonical name, and the seconds and tokens used. A model is its name, or the provider and name separated by ":", such as "openai:whisper-1". When the stream function isn't nil, the transcript is streamed, and the function is called with each piece of its text, and each segment, when they're asked for. The request isn't timed out, as audio can take a while, but is cancelled with the context.
func (*Client) Translate ¶
func (c *Client) Translate(ctx context.Context, req schema.TranscribeRequest, stream llm.TranscriberStreamFn) (*schema.TranscribeResponse, error)
Translate returns the speech in the audio of the request, in any language, as English text, as Transcribe does
func (*Client) UnloadModel ¶
UnloadModel unloads the model with the name, or alias, or provider and name, such as my-ollama:gemma:latest, from its provider's memory, keeping it stored, and returns it. The name is one segment of the path, so a "/" in it is escaped.
func (*Client) UpdateProvider ¶
func (c *Client) UpdateProvider(ctx context.Context, name string, meta schema.ProviderMeta) (*schema.ProviderStatus, error)
UpdateProvider replaces the fields of the provider with the name with the meta, keeping its API key when the meta has none, and returns it
func (*Client) WatchEvents ¶
WatchEvents calls the function with each of the registry's events, as the server streams them, such as when a provider is created, updated or deleted, until the context is cancelled, when it returns nil, or the function returns an error, which it returns, or the stream ends. When the server stops, it returns ErrServiceUnavailable.