provider

package
v0.0.0-...-7bbc623 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateCost

func EstimateCost(model string, promptTokens, completionTokens int) float64

EstimateCost calculates the approximate cost in cents for a request.

Types

type AnthropicProvider

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

func NewAnthropicProvider

func NewAnthropicProvider(apiKey string, client *http.Client) *AnthropicProvider

func (*AnthropicProvider) Chat

func (*AnthropicProvider) ChatStream

func (p *AnthropicProvider) ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, <-chan error)

func (*AnthropicProvider) Name

func (p *AnthropicProvider) Name() string

type ChatChunk

type ChatChunk struct {
	Content          string `json:"content"`
	FinishReason     string `json:"finish_reason"`
	PromptTokens     int    `json:"prompt_tokens"`     // Usually only in first or last chunk
	CompletionTokens int    `json:"completion_tokens"` // Usually cumulative or in last chunk
}

type ChatRequest

type ChatRequest struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
	Stream   bool      `json:"stream"`
}

type ChatResponse

type ChatResponse struct {
	Content          string `json:"content"`
	Model            string `json:"model"`
	Provider         string `json:"provider"`
	PromptTokens     int    `json:"prompt_tokens"`
	CompletionTokens int    `json:"completion_tokens"`
}

type GeminiProvider

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

func NewGeminiProvider

func NewGeminiProvider(ctx context.Context, apiKey string) (*GeminiProvider, error)

func (*GeminiProvider) Chat

func (*GeminiProvider) ChatStream

func (p *GeminiProvider) ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, <-chan error)

func (*GeminiProvider) Name

func (p *GeminiProvider) Name() string

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type MockProvider

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

func NewMockProvider

func NewMockProvider(name string) *MockProvider

func (*MockProvider) Chat

func (p *MockProvider) Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)

func (*MockProvider) ChatStream

func (p *MockProvider) ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, <-chan error)

func (*MockProvider) Name

func (p *MockProvider) Name() string

type OllamaProvider

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

func NewOllamaProvider

func NewOllamaProvider(host string) *OllamaProvider

func (*OllamaProvider) Chat

func (*OllamaProvider) ChatStream

func (p *OllamaProvider) ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, <-chan error)

func (*OllamaProvider) Name

func (p *OllamaProvider) Name() string

type OpenAIProvider

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

func NewOpenAIProvider

func NewOpenAIProvider(apiKey string) *OpenAIProvider

func (*OpenAIProvider) Chat

func (*OpenAIProvider) ChatStream

func (p *OpenAIProvider) ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, <-chan error)

func (*OpenAIProvider) Name

func (p *OpenAIProvider) Name() string

type Provider

type Provider interface {
	// Name returns the provider identifier (e.g., "openai", "anthropic").
	Name() string

	// Chat dispatches a non-streaming request.
	Chat(ctx context.Context, req ChatRequest) (*ChatResponse, error)

	// ChatStream dispatches a streaming request.
	// It returns a channel of chunks and a channel for errors.
	ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, <-chan error)
}

Provider defines the interface for an upstream LLM backend.

type ResilientProvider

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

ResilientProvider wraps a Provider with retries, timeouts, and circuit breaking logic.

func NewResilientProvider

func NewResilientProvider(base Provider, maxRetries int, timeout time.Duration) *ResilientProvider

func (*ResilientProvider) Chat

func (*ResilientProvider) ChatStream

func (p *ResilientProvider) ChatStream(ctx context.Context, req ChatRequest) (<-chan ChatChunk, <-chan error)

func (*ResilientProvider) Name

func (p *ResilientProvider) Name() string

Jump to

Keyboard shortcuts

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