client

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package client defines the provider-neutral transport contract used by jungi to talk to LLM APIs, plus the OpenRouter client implementation.

Client is the interface callers depend on; each implementation owns its own provider-specific conversation state and SDK wiring, converting to and from the neutral message, model, tooldef, and usage packages via the adapters colocated with those packages.

Package client also provides the OpenRouter chat-completions transport. openrouterClient keeps the running conversation as a local slice of ChatMessages: the full conversation is resent on every call rather than relying on server-side continuation.

Requests are always sent with streaming disabled — OpenRouter aggregates many upstream models, and a non-streaming request keeps the response shape and error handling uniform across whichever model is actually serving it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	SendMessage(ctx context.Context, messages []message.Message) (Response, error)
	SendToolResult(ctx context.Context, results []message.ToolResult) (Response, error)
	Model() model.ID
	Reset()
	// SetTools replaces the advertised tool set for subsequent requests.
	// An empty or nil slice disables tool advertisement entirely.
	SetTools([]tooldef.Definition)
}

Client defines the interface for sending messages to an LLM.

Implementations own the server-side conversation state. Callers pass the full session message slice on each call; the implementation is responsible for deciding which turns to transmit. Reset discards that state, starting the next call as a fresh conversation.

func New

func New(apiKey string, log *logger.Logger, systemPrompt string, m model.ID, tools []tooldef.Definition, opts model.GenerationOptions, transportOpts ...Option) Client

New creates a client configured for the specified model.

apiKey is passed directly to the OpenRouter SDK via openrouter.WithSecurity; no environment variables are read. systemPrompt is sent as a leading system message on every request (see message.ToMessages). tools is the complete set of jungi-defined tools sent on every request. opts carries the provider-neutral generation settings; see model.Reasoning for how OpenRouter interprets it. transportOpts configures transport-level overrides (see WithMaxTokens, WithoutPromptCaching).

type Option

type Option func(*options)

Option configures transport-level behavior. Construct one via WithMaxTokens or WithoutPromptCaching and pass it to New.

func WithJSONSchema added in v0.2.0

func WithJSONSchema(name string, schema map[string]any) Option

WithJSONSchema requests structured JSON output conforming to the given schema. name is the schema name (a-z, A-Z, 0-9, underscores, dashes, max 64 chars) and schema is the JSON Schema object. When set, buildChatRequest attaches a strict JSON Schema response_format so the model returns valid JSON matching the schema.

func WithMaxTokens

func WithMaxTokens(n int64) Option

WithMaxTokens overrides the model config's MaxTokens for every request made by the constructed client. Use this to cap response length below the model's default budget, e.g. for lightweight one-shot evaluations.

func WithSessionID added in v0.2.0

func WithSessionID(id string) Option

WithSessionID pins all requests from the constructed client to the same OpenRouter provider for prompt-cache affinity and observability grouping. An empty value is ignored.

func WithoutPromptCaching

func WithoutPromptCaching() Option

WithoutPromptCaching disables prompt caching for the constructed client. The OpenRouter client then omits the request-level CacheControl directive.

type Response

type Response struct {
	Content    string
	Usage      usage.RequestUsage
	StopReason string
	ToolUses   []message.ToolUseRequest
}

Response holds the content and metadata from an API call.

StopReason indicates why the model stopped generating. When it equals "tool_use", the ToolUses slice contains the tool invocations the model is requesting.

Source Files

  • client.go
  • openrouter_client.go
  • options.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL