Documentation
¶
Index ¶
- type Client
- func (*Client) Deps() []any
- func (c *Client) Embed(ctx context.Context, model, text string) ([]float32, error)
- func (c *Client) Generate(ctx context.Context, model, prompt string, schema json.RawMessage) (string, error)
- func (c *Client) Inject(args []any)
- func (*Client) NewResource() (any, error)
- func (c *Client) ProbeReady(ctx context.Context) error
- func (c *Client) StandBy() (func(context.Context) error, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a typed Ollama API client (Embed/Generate/Heartbeat) over an already-instrumented client-http.Client. It has no ecfg config of its own: Label and BaseURL live entirely on the injected client-http.Client, same slot the app configures via ecfg (e.g. `ecfg:"OLLAMA"`).
Catalog field: *Client (ResourceFactory).
func (*Client) Generate ¶
func (c *Client) Generate(ctx context.Context, model, prompt string, schema json.RawMessage) (string, error)
Generate produces a single, non-streaming response for prompt using model. schema constrains the response via Ollama's structured-output "format" field: pass json.RawMessage(`"json"`) for unstructured-but-valid JSON, a JSON Schema object for strict structure, or nil for plain text.
func (*Client) Inject ¶
Inject only stores the dependency pointer. sdi.Resolve runs Inject across every resource in a single pass ordered by registration, not by the Deps() graph — a ResourceFactory (this type) is always registered before any Configurable (client-http.Client) materializes, regardless of catalog field order. Reading dep.HTTPClient() here would observe it before client-http.Client's own Inject has set it. StandBy runs later, once sdi.Resolve has finished entirely (every resource's Inject has run), which is where dep's state is safe to consume.
func (*Client) NewResource ¶
func (*Client) ProbeReady ¶
ProbeReady reports whether the Ollama backend is reachable (ops/probe duck typing — see client-http's README for why this lives here and not on client-http itself: readiness is API-specific, and client-http has no idea what "up" means for the API it transports).
func (*Client) StandBy ¶ added in v0.2.0
StandBy builds the Ollama SDK client from the now fully-wired client-http.Client. It runs once, sequentially, after sdi.Resolve and before runner.Run starts the concurrent Start phase — no I/O happens here, so there is no ordering hazard to guard against the way there would be for a runner.Starter. It always returns a nil cleanup — see runner.StandBy's doc comment, which names this exact type as the example of a StandBy with nothing to undo.
The url.Parse error below is not expected to trigger when this Client was wired through app.Bootstrap's normal pipeline: ecfg.LoadEnv validates BaseURL via protovalidate (http.v1.URL's string.uri rule) before Config.Build ever runs. That is a calling-convention guarantee, not a type-safety one — clienthttp.Config's own fields are exported and Config.Build itself only rejects an empty string, so anything calling Build directly (as this package's own tests do) bypasses ecfg entirely. See TestMarkClientHTTPLoadEnvRejectsMalformedBaseURL, which pins the ecfg.LoadEnv side of this assumption, and TestClient_StandBy_malformedBaseURL, which exercises this error branch directly via that same bypass.
No nil-guard on c.http here (unlike apiClient's): Deps declares it as a single required dependency, so sdi.Resolve errors out before runner.Run's StandBy phase is ever reached if it's missing — StandBy is only called by that same trusted pipeline, not by arbitrary callers the way the business methods below are.