simple

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package simple contains the common adapter used by provider packages whose documented endpoint is OpenAI Chat-compatible and uses either bearer or no authentication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(selected model.Model, key auth.APIKey, definition Definition, options ...Option) (inference.Client, error)

func NewAnthropicCounter

func NewAnthropicCounter(provider llm.Provider) (contextcount.ContextCounter, error)

func NewCounter

func NewCounter(provider llm.Provider) (contextcount.ContextCounter, error)

Types

type Definition

type Definition = compat.Definition

type Option

type Option = compat.Option

func WithBodyField

func WithBodyField(name string, value any) Option

WithBodyField is kept in the internal adapter so provider packages can expose only the stable fields their upstream documents, without importing compat.

func WithBodyPatch

func WithBodyPatch(patch func(map[string]json.RawMessage) error) Option

WithBodyPatch applies a provider-local patch after the common body fields are merged. Patches CHAIN in application order rather than replacing one another: compat.WithBodyPatch assigns, so the second of two patches silently discarded the first, and gitlab already relies on ordering it does not control (it appends its own model-rewriting patch AFTER the caller's options). Chaining here — the one place every provider package reaches WithBodyPatch through — makes an added patch additive, which is what a validating patch such as WithThinkingBudget's requires to be reliable.

func WithHeader

func WithHeader(name, value string) Option

func WithReasoningEffort

func WithReasoningEffort(value string) Option

func WithReasoningEnabled

func WithReasoningEnabled(enabled bool) Option

func WithServiceTier

func WithServiceTier(value string) Option

func WithThinking

func WithThinking(enabled bool) Option

func WithThinkingBudget

func WithThinkingBudget(budget int) Option

WithThinkingBudget injects a raw thinking.budget_tokens body field for the OpenAI-compatible and Anthropic-dialect targets that document it, and holds the result to Anthropic's rule that max_tokens must be GREATER than thinking.budget_tokens — violating it draws an HTTP 400 with that exact wording, confirmed live against api.anthropic.com.

The rule is enforced from a body patch rather than from the option itself because only the patch sees both numbers: the budget is fixed when the option is built, while the output cap is written by the codec when a request is encoded. The failure therefore surfaces from Invoke/Stream, but still before any bytes leave the process.

func WithThinkingEnabled

func WithThinkingEnabled(enabled bool) Option

type ThinkingBudgetError

type ThinkingBudgetError struct {
	Field        string
	MaxTokens    int
	BudgetTokens int
}

ThinkingBudgetError is a fail-closed rejection, before any I/O, of a request whose reasoning budget is not smaller than its output cap. Field names the body member that carried the cap, because the three dialects this adapter speaks spell it differently and the caller needs to know which one it set. Both numbers are on the error: a message naming only one of them would not say what to change.

func (*ThinkingBudgetError) Error

func (e *ThinkingBudgetError) Error() string

Jump to

Keyboard shortcuts

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