providers

package
v0.18.1 Latest Latest
Warning

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

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

Documentation

Overview

Package providers implements LLM client providers for various APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(provider string, cfg llm.ClientConfig) (llm.Client, error)

NewClient creates an LLM client for the specified provider. Supported providers: "openai", "openai-responses", "anthropic", "gemini", "ollama".

func NewEmbedder

func NewEmbedder(provider string, cfg OpenAIEmbedderConfig) (llm.Embedder, error)

NewEmbedder creates an Embedder for the specified provider. Supported providers: "openai", "gemini", "ollama". Returns an error for "anthropic" (no embedding API).

Types

type AnthropicClient

type AnthropicClient struct {
	// contains filtered or unexported fields
}

AnthropicClient implements llm.Client for the Anthropic Messages API.

func NewAnthropicClient

func NewAnthropicClient(cfg llm.ClientConfig) *AnthropicClient

NewAnthropicClient creates a new Anthropic client.

When cfg.AuthScheme == "aws_sigv4", the client's http.Transport is wrapped with the SigV4 signer (issue #202 Phase 2) and the per-request x-api-key header is skipped. This routes outbound requests at any AWS SigV4-fronted gateway that speaks the Anthropic Messages wire format (custom proxies, Bedrock-compat proxies). Operators provide AWS credentials via the standard environment variables (AWS_ACCESS_KEY_ID / _SECRET_ / _SESSION_TOKEN) and the region via cfg.AWSRegion. APIKey is ignored on this path.

All other AuthScheme values (including the empty default) preserve the pre-#202 contract: x-api-key + anthropic-version headers, no transport wrapping.

func (*AnthropicClient) Chat

Chat sends a non-streaming messages request.

func (*AnthropicClient) ChatStream

func (c *AnthropicClient) ChatStream(ctx context.Context, req *llm.ChatRequest) (<-chan llm.StreamDelta, error)

ChatStream sends a streaming messages request.

func (*AnthropicClient) ModelID

func (c *AnthropicClient) ModelID() string

type OAuthClient

type OAuthClient struct {
	// contains filtered or unexported fields
}

OAuthClient wraps a ResponsesClient with automatic OAuth token refresh. It implements llm.Client and transparently refreshes expired tokens before each API call. ChatGPT OAuth tokens are scoped to the Responses API, not the Chat Completions API, so this client uses the Responses API format.

func NewOAuthClient

func NewOAuthClient(cfg llm.ClientConfig, provider string, oauthConfig oauth.ProviderConfig) *OAuthClient

NewOAuthClient creates a new OAuth-aware client that uses the Responses API. The token is loaded from stored credentials and refreshed automatically.

func (*OAuthClient) Chat

Chat sends a Responses API request, refreshing the token if needed.

func (*OAuthClient) ChatStream

func (c *OAuthClient) ChatStream(ctx context.Context, req *llm.ChatRequest) (<-chan llm.StreamDelta, error)

ChatStream sends a streaming Responses API request, refreshing the token if needed.

func (*OAuthClient) ModelID

func (c *OAuthClient) ModelID() string

ModelID returns the model identifier.

type OllamaClient

type OllamaClient struct {
	*OpenAIClient
}

OllamaClient wraps OpenAIClient with Ollama-specific defaults. Ollama provides an OpenAI-compatible API at localhost:11434/v1.

func NewOllamaClient

func NewOllamaClient(cfg llm.ClientConfig) *OllamaClient

NewOllamaClient creates a client that talks to a local Ollama server.

type OllamaEmbedder

type OllamaEmbedder struct {
	*OpenAIEmbedder
}

OllamaEmbedder wraps OpenAIEmbedder with Ollama-specific defaults. Ollama provides an OpenAI-compatible /v1/embeddings endpoint.

func NewOllamaEmbedder

func NewOllamaEmbedder(cfg OpenAIEmbedderConfig) *OllamaEmbedder

NewOllamaEmbedder creates an embedder that talks to a local Ollama server.

type OpenAIClient

type OpenAIClient struct {
	// contains filtered or unexported fields
}

OpenAIClient implements llm.Client for the OpenAI Chat Completions API. Also works with Azure OpenAI and any OpenAI-compatible endpoint.

func NewOpenAIClient

func NewOpenAIClient(cfg llm.ClientConfig) *OpenAIClient

NewOpenAIClient creates a new OpenAI client.

When cfg.AuthScheme == "aws_sigv4" the client's http.Transport is wrapped with the SigV4 signer (issue #202 Phase 2) and the per- request Authorization: Bearer header is skipped. Routes outbound at AWS Bedrock's OpenAI compatibility endpoint or any other SigV4-fronted OpenAI-shaped gateway. AWS credentials resolve via AWS_ACCESS_KEY_ID / _SECRET_ / _SESSION_TOKEN env; region via cfg.AWSRegion. APIKey is ignored on this path.

Empty AuthScheme preserves the pre-#202 contract byte-for-byte.

func (*OpenAIClient) Chat

Chat sends a non-streaming chat completion request.

func (*OpenAIClient) ChatStream

func (c *OpenAIClient) ChatStream(ctx context.Context, req *llm.ChatRequest) (<-chan llm.StreamDelta, error)

ChatStream sends a streaming chat completion request.

func (*OpenAIClient) ModelID

func (c *OpenAIClient) ModelID() string

type OpenAIEmbedder

type OpenAIEmbedder struct {
	// contains filtered or unexported fields
}

OpenAIEmbedder implements llm.Embedder using the OpenAI Embeddings API.

func NewOpenAIEmbedder

func NewOpenAIEmbedder(cfg OpenAIEmbedderConfig) *OpenAIEmbedder

NewOpenAIEmbedder creates an OpenAI embedder.

func (*OpenAIEmbedder) Dimensions

func (e *OpenAIEmbedder) Dimensions() int

func (*OpenAIEmbedder) Embed

Embed produces embeddings for the given texts using POST /v1/embeddings.

type OpenAIEmbedderConfig

type OpenAIEmbedderConfig struct {
	APIKey  string
	OrgID   string
	BaseURL string
	Model   string
	Dims    int
}

OpenAIEmbedderConfig configures the OpenAI embedder.

type ResponsesClient

type ResponsesClient struct {
	// contains filtered or unexported fields
}

ResponsesClient implements llm.Client using the OpenAI Responses API. This is used with ChatGPT OAuth tokens which are scoped to the Responses API endpoint (chatgpt.com/backend-api) rather than the Chat Completions API.

func NewResponsesClient

func NewResponsesClient(cfg llm.ClientConfig) *ResponsesClient

NewResponsesClient creates a new Responses API client.

Auth mirrors NewOpenAIClient so a config-selected "openai-responses" provider composes with the same auth_scheme values (#383): aws_sigv4 wraps the transport with the Bedrock SigV4 signer and skips the native Bearer header; apikey_header / apikey_header_only send the key in a gateway header. Empty AuthScheme (the ChatGPT OAuth path) preserves the plain Bearer behavior byte-for-byte.

func (*ResponsesClient) Chat

Chat sends a Responses API request. The ChatGPT Codex backend requires streaming, so this method always uses stream=true internally and collects the full response from the streamed deltas.

func (*ResponsesClient) ChatStream

func (c *ResponsesClient) ChatStream(ctx context.Context, req *llm.ChatRequest) (<-chan llm.StreamDelta, error)

ChatStream sends a streaming Responses API request.

func (*ResponsesClient) ModelID

func (c *ResponsesClient) ModelID() string

type SigV4Credentials added in v0.16.0

type SigV4Credentials struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
}

SigV4Credentials carries the resolved AWS credentials the signer uses. Populated either explicitly by the caller or via SigV4CredentialsFromEnv. SessionToken is set when the underlying credentials are temporary (STS AssumeRole, IRSA, EC2 instance metadata) and adds the x-amz-security-token header to every request.

func SigV4CredentialsFromEnv added in v0.16.0

func SigV4CredentialsFromEnv() (SigV4Credentials, bool)

SigV4CredentialsFromEnv reads the standard AWS env vars. Returns (creds, true) when AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are both set; (zero, false) otherwise. AWS_SESSION_TOKEN is optional.

Web identity / IRSA / EC2 instance metadata are NOT resolved here — those need STS round-trips and the inbound aws_sigv4 provider's hand-rolled STS client (forge-core/auth/providers/aws_sigv4/sts_client.go) would be the model to copy. Tracked as a Phase 2 follow-up; the majority of Bedrock deployments today set AWS_* env vars (or AWS_PROFILE that resolves to them) before launching the agent.

type SigV4Transport added in v0.16.0

type SigV4Transport struct {
	Underlying  http.RoundTripper
	Credentials func() (SigV4Credentials, error)
	Region      string
	Service     string
	// contains filtered or unexported fields
}

SigV4Transport is an http.RoundTripper that signs each outbound request with AWS Signature V4 before forwarding to the underlying transport.

Credentials are read once per request via the Credentials getter so the transport plays well with rotating creds (an external watcher can update a sync.Atomic-wrapped value the getter reads). Region and Service are static — they describe the AWS endpoint being signed for, not the caller's identity.

Underlying is what we delegate the round trip to after signing — composes cleanly with the existing otelhttp + egress-enforcer transports because we mutate headers only.

func (*SigV4Transport) RoundTrip added in v0.16.0

func (t *SigV4Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip signs req with SigV4 and forwards it to the underlying transport. Clones the request before mutating headers (the http.RoundTripper contract) and reads the body fully into memory because SigV4 hashes the payload — there is no streaming-signature option in the bedrock service.

Body limits: chunked-streaming + unsigned payload is supported by SigV4 but Bedrock doesn't accept it. Reading the body in full is the price of pointing at Bedrock; bound your request sizes upstream.

Jump to

Keyboard shortcuts

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