Documentation
¶
Overview ¶
Package model is the pluggable model seam. It defines an OpenAI-compatible chat interface with tool calling — exactly the surface Eino's openai ChatModel wraps — so the agent loop is written once against Model and the concrete backend (litellm proxy, a mock, or a future Eino component) drops in behind it.
Index ¶
Constants ¶
const ( ProviderOpenAI = "openai" ProviderAnthropic = "anthropic" )
Provider names for New.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnthropicModel ¶
type AnthropicModel struct {
BaseURL string // e.g. https://api.anthropic.com/v1 or the z.ai anthropic base (+/v1)
APIKey string
Version string // anthropic-version header; default "2023-06-01"
HTTPClient *http.Client
}
AnthropicModel talks directly to the Anthropic Messages API (`/v1/messages`) — Anthropic itself for Claude, or z.ai's Anthropic-compatible endpoint for GLM 5.2 (`glm-5.2-ant`). It implements the same model.Model seam as OpenAIModel, so quarry needs NO external litellm sidecar to reach a model: point it at a base URL, give it a key, and the agent loop runs. Budget governance (litellm's other job) is enforced by the router + run budgets.
func NewAnthropicModel ¶
func NewAnthropicModel(baseURL, apiKey string) *AnthropicModel
NewAnthropicModel builds a client. baseURL should include the version prefix the endpoint expects (…/v1); "messages" is appended.
func (*AnthropicModel) Chat ¶
func (m *AnthropicModel) Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
Chat performs one completion, translating the seam's OpenAI-shaped ChatRequest to/from the Anthropic Messages format.
type ChatRequest ¶
type ChatRequest struct {
Model string
Messages []Message
Tools []ToolDef
Temperature float64
MaxTokens int
}
ChatRequest is a single completion request.
type ChatResponse ¶
type ChatResponse struct {
Message Message
Model string
FinishReason string // stop | tool_calls | length | ...
Usage Usage
}
ChatResponse is a single completion.
type Message ¶
type Message struct {
Role string `json:"role"` // system | user | assistant | tool
Content string `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // assistant → tool requests
ToolCallID string `json:"tool_call_id,omitempty"` // tool result → which call
Name string `json:"name,omitempty"`
}
Message is one chat message. A single clean shape covers system/user/ assistant/tool roles.
type MockModel ¶
type MockModel struct {
Handler func(turn int, req ChatRequest) (ChatResponse, error)
// contains filtered or unexported fields
}
MockModel is a scriptable Model for tests. Handler receives each request (and its 0-based turn index) and returns the response, letting a test drive a full multi-turn tool-calling trajectory deterministically. It is safe for concurrent use so it can back parallel scientists; note that under concurrency the turn index reflects call order, so mocks that must be deterministic across goroutines should route on the request shape rather than the turn index.
func (*MockModel) Chat ¶
func (m *MockModel) Chat(_ context.Context, req ChatRequest) (ChatResponse, error)
type Model ¶
type Model interface {
Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
}
Model is the seam every agent call goes through.
func New ¶
New builds a concrete Model for the given provider — quarry's self-contained model access, no external sidecar required. "anthropic" → the native Messages client (Claude or z.ai's Anthropic-compatible GLM); anything else → the OpenAI-compatible client (a provider's OpenAI endpoint, or a litellm proxy).
type OpenAIModel ¶
type OpenAIModel struct {
BaseURL string // e.g. http://127.0.0.1:4000/v1
APIKey string // virtual key issued by the proxy (budget-scoped)
HTTPClient *http.Client
}
OpenAIModel talks to an OpenAI-compatible chat/completions endpoint — in quarry that is the litellm proxy sidecar. The proxy enforces the $-budget governor and routes to GLM / Claude / etc., so this client stays a thin, dependency-free transport.
func NewOpenAIModel ¶
func NewOpenAIModel(baseURL, apiKey string) *OpenAIModel
NewOpenAIModel builds a client. baseURL should point at the proxy's OpenAI-compatible base (with or without a trailing /v1).
func (*OpenAIModel) Chat ¶
func (m *OpenAIModel) Chat(ctx context.Context, req ChatRequest) (ChatResponse, error)
Chat performs one completion.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Arguments string `json:"arguments"` // raw JSON string, as the model emitted it
}
ToolCall is a model-requested tool invocation.