provider

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package provider implements LLM provider clients for various AI services.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProviderNotSupported = errors.New("provider not supported")
	ErrModelNotFound        = errors.New("model not found")
	ErrAPIKeyMissing        = errors.New("API key missing")
)

Sentinel errors for provider operations.

Functions

func DefaultShouldThinkFn

func DefaultShouldThinkFn(s string) bool

DefaultShouldThinkFn returns a default function that determines if thinking should be enabled.

Types

type AnthropicClient

type AnthropicClient ProviderClient

AnthropicClient is the interface for Anthropic provider operations.

type AnthropicOption

type AnthropicOption func(*anthropicOptions)

AnthropicOption is a function that configures Anthropic provider options.

func WithAnthropicBedrock

func WithAnthropicBedrock(useBedrock bool) AnthropicOption

WithAnthropicBedrock configures the Anthropic provider to use AWS Bedrock.

func WithAnthropicDisableCache

func WithAnthropicDisableCache() AnthropicOption

WithAnthropicDisableCache disables caching for Anthropic API requests.

func WithAnthropicReasoningEffort

func WithAnthropicReasoningEffort(effort string) AnthropicOption

WithAnthropicReasoningEffort sets the reasoning effort level for Anthropic models.

func WithAnthropicShouldThinkFn

func WithAnthropicShouldThinkFn(fn func(string) bool) AnthropicOption

WithAnthropicShouldThinkFn sets a custom function to determine if thinking should be enabled.

func WithVertexAI

func WithVertexAI(projectID, localtion string, localForCounting string) AnthropicOption

WithVertexAI configures the Anthropic provider to use Google Vertex AI.

type BedrockClient

type BedrockClient ProviderClient

BedrockClient is the interface for the Bedrock client

type BedrockOption

type BedrockOption func(*bedrockOptions)

BedrockOption is a function that configures Bedrock provider options.

type DeepSeekClient

type DeepSeekClient ProviderClient

DeepSeekClient is the interface for DeepSeek provider operations.

type DeepSeekOption

type DeepSeekOption func(*deepSeekOptions)

DeepSeekOption is a function that configures DeepSeek provider options.

func WithDeepSeekBaseURL

func WithDeepSeekBaseURL(baseURL string) DeepSeekOption

WithDeepSeekBaseURL sets a custom base URL for the DeepSeek API.

func WithDeepSeekExtraHeaders

func WithDeepSeekExtraHeaders(headers map[string]string) DeepSeekOption

WithDeepSeekExtraHeaders sets additional HTTP headers for DeepSeek API requests.

func WithDeepSeekModalities added in v1.10.0

func WithDeepSeekModalities(modalities []string) DeepSeekOption

WithDeepSeekModalities sets the output modalities. Values: []string{"text"} (default) or []string{"text", "audio"}

func WithDeepSeekPromptCacheKey added in v1.10.0

func WithDeepSeekPromptCacheKey(keys []string) DeepSeekOption

WithDeepSeekPromptCacheKey enables prompt caching with specific cache keys.

func WithDeepSeekReasoningEffort added in v1.10.0

func WithDeepSeekReasoningEffort(effort string) DeepSeekOption

WithDeepSeekReasoningEffort sets the reasoning effort for DeepSeek reasoning models. Values: "low", "medium", "high". Only applies to reasoning models like deepseek-reasoner.

func WithDeepSeekServiceTier added in v1.10.0

func WithDeepSeekServiceTier(tier string) DeepSeekOption

WithDeepSeekServiceTier sets the service tier for pricing. Values: "auto" (default), "flex"

func WithDeepSeekStore added in v1.10.0

func WithDeepSeekStore(store bool) DeepSeekOption

WithDeepSeekStore enables storing completions.

type EventType

type EventType string

EventType represents the type of event during streaming.

const (
	// EventContentStart indicates the start of content generation.
	EventContentStart EventType = "content_start"
	// EventToolUseStart indicates the start of a tool use.
	EventToolUseStart EventType = "tool_use_start"
	// EventToolUseDelta indicates a delta update for a tool use.
	EventToolUseDelta EventType = "tool_use_delta"
	// EventToolUseStop indicates the end of a tool use.
	EventToolUseStop EventType = "tool_use_stop"
	// EventContentDelta indicates a delta update for content.
	EventContentDelta EventType = "content_delta"
	// EventThinkingDelta indicates a delta update for thinking content.
	EventThinkingDelta EventType = "thinking_delta"
	// EventContentStop indicates the end of content generation.
	EventContentStop EventType = "content_stop"
	// EventComplete indicates the completion of the response.
	EventComplete EventType = "complete"
	// EventError indicates an error occurred.
	EventError EventType = "error"
	// EventWarning indicates a warning.
	EventWarning EventType = "warning"
)

type GeminiClient

type GeminiClient ProviderClient

GeminiClient is the interface for Gemini provider operations.

type GeminiOption

type GeminiOption func(*geminiOptions)

GeminiOption is a function that configures Gemini provider options.

func WithGeminiDisableCache

func WithGeminiDisableCache() GeminiOption

WithGeminiDisableCache disables caching for Gemini API requests.

type KiloClient added in v1.10.0

type KiloClient ProviderClient

type KiloOption added in v1.10.0

type KiloOption func(*kiloOptions)

KiloOption is a function that configures Kilo provider options.

func WithKiloBaseURL added in v1.10.0

func WithKiloBaseURL(url string) KiloOption

WithKiloBaseURL sets a custom base URL for the Kilo API.

func WithKiloExtraHeaders added in v1.10.0

func WithKiloExtraHeaders(headers map[string]string) KiloOption

WithKiloExtraHeaders sets extra headers for the Kilo API.

func WithKiloModalities added in v1.10.0

func WithKiloModalities(modalities []string) KiloOption

WithKiloModalities sets the output modalities. Values: []string{"text"} (default) or []string{"text", "audio"}

func WithKiloPromptCacheKey added in v1.10.0

func WithKiloPromptCacheKey(keys []string) KiloOption

WithKiloPromptCacheKey enables prompt caching with specific cache keys.

func WithKiloReasoningEffort added in v1.10.0

func WithKiloReasoningEffort(effort string) KiloOption

WithKiloReasoningEffort sets the reasoning effort for Kilo reasoning models. Values: "low", "medium", "high". Only applies to reasoning models.

func WithKiloServiceTier added in v1.10.0

func WithKiloServiceTier(tier string) KiloOption

WithKiloServiceTier sets the service tier for pricing. Values: "auto" (default), "flex"

func WithKiloStore added in v1.10.0

func WithKiloStore(store bool) KiloOption

WithKiloStore enables storing completions.

type OpenAIClient

type OpenAIClient ProviderClient

OpenAIClient is the interface for OpenAI provider operations.

type OpenAIOption

type OpenAIOption func(*openaiOptions)

OpenAIOption is a function that configures OpenAI provider options.

func WithOpenAIBaseURL

func WithOpenAIBaseURL(baseURL string) OpenAIOption

WithOpenAIBaseURL sets a custom base URL for the OpenAI API.

func WithOpenAIDisableCache

func WithOpenAIDisableCache() OpenAIOption

WithOpenAIDisableCache disables caching for OpenAI API requests.

func WithOpenAIExtraHeaders

func WithOpenAIExtraHeaders(headers map[string]string) OpenAIOption

WithOpenAIExtraHeaders sets additional HTTP headers for OpenAI API requests.

func WithOpenAIModalities added in v1.10.0

func WithOpenAIModalities(modalities []string) OpenAIOption

WithOpenAIModalities enables audio output modalities Values: []string{"text"} (default) or []string{"text", "audio"}

func WithOpenAIPromptCacheKey added in v1.10.0

func WithOpenAIPromptCacheKey(keys []string) OpenAIOption

WithOpenAIPromptCacheKey enables prompt caching with specific cache keys

func WithOpenAIServiceTier added in v1.10.0

func WithOpenAIServiceTier(tier string) OpenAIOption

WithOpenAIServiceTier sets the service tier for priority vs flex pricing Values: "auto" (default) or "flex"

func WithOpenAIStore added in v1.10.0

func WithOpenAIStore(store bool) OpenAIOption

WithOpenAIStore enables storing completions

func WithReasoningEffort

func WithReasoningEffort(effort string) OpenAIOption

WithReasoningEffort sets the reasoning effort level for OpenAI reasoning models.

type Provider

type Provider interface {
	// SendMessages sends a list of messages to the provider and returns a response.
	SendMessages(ctx context.Context, messages []message.Message, tools []toolsPkg.BaseTool) (*ProviderResponse, error)

	// StreamResponse streams a response from the provider.
	StreamResponse(ctx context.Context, messages []message.Message, tools []toolsPkg.BaseTool) <-chan ProviderEvent

	// Model returns the current model being used.
	Model() models.Model

	// CountTokens counts tokens for provided messages using underlying client OR fallback to default estimation strategy,
	// returns tokens count and whether a threshold has been hit based on the model context size,
	// threshold can be used to track an approaching limit to trigger compaction or other activities
	CountTokens(ctx context.Context, threshold float64, messages []message.Message, tools []toolsPkg.BaseTool) (tokens int64, hit bool)

	// AdjustMaxTokens calculates and sets new max_tokens if needed to be used by underlying client
	AdjustMaxTokens(estimatedTokens int64) int64
}

Provider defines the interface for LLM providers.

func NewProvider

func NewProvider(providerName models.ModelProvider, opts ...ProviderClientOption) (Provider, error)

NewProvider creates a new provider instance for the given provider name.

type ProviderClient

type ProviderClient interface {
	// contains filtered or unexported methods
}

ProviderClient is the interface for provider-specific clients.

type ProviderClientOption

type ProviderClientOption func(*providerClientOptions)

ProviderClientOption is a function that configures provider client options.

func WithAPIKey

func WithAPIKey(apiKey string) ProviderClientOption

WithAPIKey sets the API key for the provider.

func WithAnthropicOptions

func WithAnthropicOptions(anthropicOptions ...AnthropicOption) ProviderClientOption

WithAnthropicOptions sets Anthropic-specific options.

func WithBaseURL

func WithBaseURL(baseURL string) ProviderClientOption

WithBaseURL sets the base URL for the provider.

func WithBedrockOptions

func WithBedrockOptions(bedrockOptions ...BedrockOption) ProviderClientOption

WithBedrockOptions sets Bedrock-specific options.

func WithDeepSeekOptions

func WithDeepSeekOptions(deepSeekOptions ...DeepSeekOption) ProviderClientOption

WithDeepSeekOptions sets DeepSeek-specific options.

func WithGeminiOptions

func WithGeminiOptions(geminiOptions ...GeminiOption) ProviderClientOption

WithGeminiOptions sets Gemini-specific options.

func WithHeaders

func WithHeaders(headers map[string]string) ProviderClientOption

WithHeaders sets custom headers for the provider.

func WithKiloOptions added in v1.10.0

func WithKiloOptions(kiloOptions ...KiloOption) ProviderClientOption

WithKiloOptions sets Kilo-specific options.

func WithMaxTokens

func WithMaxTokens(maxTokens int64) ProviderClientOption

WithMaxTokens sets the maximum tokens for the provider.

func WithModel

func WithModel(model models.Model) ProviderClientOption

WithModel sets the model for the provider.

func WithOpenAIOptions

func WithOpenAIOptions(openaiOptions ...OpenAIOption) ProviderClientOption

WithOpenAIOptions sets OpenAI-specific options.

func WithSystemMessage

func WithSystemMessage(systemMessage string) ProviderClientOption

WithSystemMessage sets the system message for the provider.

type ProviderEvent

type ProviderEvent struct {
	Type EventType

	Content  string
	Thinking string
	Response *ProviderResponse
	ToolCall *message.ToolCall
	Error    error
}

ProviderEvent represents an event during streaming response.

type ProviderResponse

type ProviderResponse struct {
	Content      string
	ToolCalls    []message.ToolCall
	Usage        TokenUsage
	FinishReason message.FinishReason
}

ProviderResponse represents a complete response from a provider.

type TokenUsage

type TokenUsage struct {
	InputTokens         int64
	OutputTokens        int64
	CacheCreationTokens int64
	CacheReadTokens     int64
	TotalTokens         int64
}

TokenUsage represents token consumption for a provider request.

type VertexAIClient

type VertexAIClient ProviderClient

VertexAIClient is the interface for Vertex AI provider operations.

Directories

Path Synopsis
Package sse provides SSE (Server-Sent Events) decoding for Kilo Gateway's non-standard streaming protocol with concatenated data:, reasoning, and fragmented tool_calls.
Package sse provides SSE (Server-Sent Events) decoding for Kilo Gateway's non-standard streaming protocol with concatenated data:, reasoning, and fragmented tool_calls.

Jump to

Keyboard shortcuts

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