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) Chat(ctx context.Context, id uuid.UUID, req schema.ChatRequest, ...) (*schema.ChatResponse, error)
- func (c *Client) CreateAgent(ctx context.Context, meta schema.AgentMeta) (*schema.Agent, error)
- func (c *Client) CreateProvider(ctx context.Context, provider schema.Provider) (*schema.ProviderStatus, error)
- func (c *Client) CreateSession(ctx context.Context, meta schema.SessionMeta) (*schema.Session, error)
- func (c *Client) DeleteAgent(ctx context.Context, name string) (*schema.Agent, error)
- func (c *Client) DeleteEvent(ctx context.Context, id uuid.UUID) (*schema.Event, 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) DeleteSession(ctx context.Context, id uuid.UUID) (*schema.Session, error)
- func (c *Client) Embed(ctx context.Context, req schema.EmbedRequest) (*schema.EmbedResponse, error)
- func (c *Client) ForgetSessionMessages(ctx context.Context, id uuid.UUID) (*schema.Session, error)
- func (c *Client) GetAgent(ctx context.Context, name string) (*schema.Agent, error)
- func (c *Client) GetEvent(ctx context.Context, id uuid.UUID) (*schema.Event, 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) GetSession(ctx context.Context, id uuid.UUID) (*schema.Session, error)
- func (c *Client) ListAgents(ctx context.Context, req schema.AgentListRequest) (*schema.AgentList, error)
- func (c *Client) ListEvents(ctx context.Context, req schema.EventListRequest) (*schema.EventList, 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) ListSessionMessages(ctx context.Context, id uuid.UUID, req schema.MessageListRequest) (*schema.MessageList, error)
- func (c *Client) ListSessions(ctx context.Context, req schema.SessionListRequest) (*schema.SessionList, error)
- func (c *Client) LoadModel(ctx context.Context, req schema.LoadModelRequest, ...) (*schema.Model, error)
- func (c *Client) ReadAgentYAML(ctx context.Context, name string, w io.Writer) error
- func (c *Client) Recognize(ctx context.Context, req schema.RecognizeRequest) (*schema.RecognizeResponse, error)
- func (c *Client) SetSessionStatus(ctx context.Context, id uuid.UUID, status schema.SessionStatus) (*schema.Session, error)
- func (c *Client) Speak(ctx context.Context, req schema.SpeakRequest, w io.Writer) (string, *schema.SpeakMeta, 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) TriggerEvent(ctx context.Context, req schema.EventRequest) (*schema.TriggerEventResponse, error)
- func (c *Client) UnloadModel(ctx context.Context, name string) (*schema.Model, error)
- func (c *Client) UpdateAgent(ctx context.Context, name string, meta schema.AgentMeta) (*schema.Agent, error)
- func (c *Client) UpdateProvider(ctx context.Context, name string, meta schema.ProviderMeta) (*schema.ProviderStatus, error)
- func (c *Client) UpdateSession(ctx context.Context, id uuid.UUID, meta schema.SessionMeta) (*schema.Session, error)
- func (c *Client) WriteAgentYAML(ctx context.Context, r io.Reader) (*schema.Agent, 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) Chat ¶ added in v0.6.0
func (c *Client) Chat(ctx context.Context, id uuid.UUID, req schema.ChatRequest, stream llm.GeneratorStreamFn) (*schema.ChatResponse, error)
Chat adds the messages to the session with the identifier, which its model replies to, running the tools it calls, and returns what was added, with the model's reply, 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, and the tools' log lines, as they're generated. The request isn't timed out, as a model can take a while to reply, but is cancelled with the context.
func (*Client) CreateAgent ¶ added in v0.6.0
CreateAgent creates an agent with the definition, and returns it
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) CreateSession ¶ added in v0.6.0
func (c *Client) CreateSession(ctx context.Context, meta schema.SessionMeta) (*schema.Session, error)
CreateSession creates a session with the settings, and no messages, and returns it
func (*Client) DeleteAgent ¶ added in v0.6.0
DeleteAgent deletes the agent with the name, and returns it, as it was
func (*Client) DeleteEvent ¶ added in v1.2.0
DeleteEvent deletes the outcome of the event with the identifier, and returns it, as it was
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) DeleteSession ¶ added in v0.6.0
DeleteSession deletes the session with the identifier, 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) ForgetSessionMessages ¶ added in v1.0.0
ForgetSessionMessages forgets the messages of the session with the identifier, keeping its settings, and returns it
func (*Client) GetEvent ¶ added in v1.2.0
GetEvent returns the outcome of the event with the identifier
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) GetSession ¶ added in v0.6.0
GetSession returns the session with the identifier, without its messages, which ListSessionMessages lists
func (*Client) ListAgents ¶ added in v0.6.0
func (c *Client) ListAgents(ctx context.Context, req schema.AgentListRequest) (*schema.AgentList, error)
ListAgents returns the agents, in the server's order, as the request selects, and how many there are
func (*Client) ListEvents ¶ added in v1.2.0
func (c *Client) ListEvents(ctx context.Context, req schema.EventListRequest) (*schema.EventList, error)
ListEvents returns the outcomes of events, the most recent first, as the request selects, and how many there are
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) ListSessionMessages ¶ added in v0.6.0
func (c *Client) ListSessionMessages(ctx context.Context, id uuid.UUID, req schema.MessageListRequest) (*schema.MessageList, error)
ListSessionMessages returns the messages of the session with the identifier, oldest first, as the request selects, and how many there are
func (*Client) ListSessions ¶ added in v0.6.0
func (c *Client) ListSessions(ctx context.Context, req schema.SessionListRequest) (*schema.SessionList, error)
ListSessions returns the sessions, without their messages, most recently modified first, as the request selects, and how many there are
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) ReadAgentYAML ¶ added in v0.6.0
ReadAgentYAML writes the definition of the agent with the name to the writer, as YAML, as a file of it is, which WriteAgentYAML can create again
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) SetSessionStatus ¶ added in v0.6.0
func (c *Client) SetSessionStatus(ctx context.Context, id uuid.UUID, status schema.SessionStatus) (*schema.Session, error)
SetSessionStatus sets the status of the session with the identifier, to typing, as someone types a message, which it is for a while after, or idle, when they stop, and returns the session, with its status
func (*Client) Speak ¶ added in v1.3.0
func (c *Client) Speak(ctx context.Context, req schema.SpeakRequest, w io.Writer) (string, *schema.SpeakMeta, error)
Speak writes the request's text, spoken by its model, which is found by its name, or the provider and name separated by ":", such as "ollama:phonon:latest", as audio, to the writer, as it's read, and returns its type, such as audio/wav, and the model which spoke it, and the usage. The request isn't timed out, as speaking a long text can take a while.
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) TriggerEvent ¶ added in v1.2.0
func (c *Client) TriggerEvent(ctx context.Context, req schema.EventRequest) (*schema.TriggerEventResponse, error)
TriggerEvent schedules the event, from a source other than a heartbeat, such as a file which changed, to run, and returns whether it's scheduled, rather than an event of its source, which is already, and its outcome, which is scheduled, until it's run
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) UpdateAgent ¶ added in v0.6.0
func (c *Client) UpdateAgent(ctx context.Context, name string, meta schema.AgentMeta) (*schema.Agent, error)
UpdateAgent changes the definition of the agent with the name: what the update sets is changed, and the rest kept. Returns the agent.
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) UpdateSession ¶ added in v0.6.0
func (c *Client) UpdateSession(ctx context.Context, id uuid.UUID, meta schema.SessionMeta) (*schema.Session, error)
UpdateSession changes the settings of the session with the identifier, as SessionMeta.Merge does, so what the update doesn't set is kept, and returns it
func (*Client) WriteAgentYAML ¶ added in v0.6.0
WriteAgentYAML creates an agent with the definition which is read from the reader, which is YAML, such as a file of an agent's definition, which the server parses, and returns it