llmproviders

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package llmproviders provides LLM provider integration for TokMan agents

Index

Constants

View Source
const DefaultRetryBackoff = 1 * time.Second

DefaultRetryBackoff is the base delay between retries.

View Source
const MaxRetries = 3

MaxRetries is the default maximum number of retries for LLM requests.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnthropicProvider

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

AnthropicProvider implements the Provider interface for Anthropic

func NewAnthropicProvider

func NewAnthropicProvider(apiKey, model string) *AnthropicProvider

NewAnthropicProvider creates a new Anthropic provider

func (*AnthropicProvider) Complete

func (*AnthropicProvider) Embed

func (p *AnthropicProvider) Embed(ctx context.Context, text string) ([]float64, error)

func (*AnthropicProvider) Name

func (p *AnthropicProvider) Name() string

func (*AnthropicProvider) StreamComplete

func (p *AnthropicProvider) StreamComplete(ctx context.Context, req CompletionRequest) (<-chan StreamChunk, error)

type CompletionRequest

type CompletionRequest struct {
	Model       string
	Messages    []Message
	Temperature float64
	MaxTokens   int
	TopP        float64
	Stop        []string
	Tools       []ToolDefinition
}

CompletionRequest holds a completion request

type CompletionResponse

type CompletionResponse struct {
	ID      string
	Model   string
	Content string
	Usage   UsageInfo
}

CompletionResponse holds a completion response

type FunctionDefinition

type FunctionDefinition struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Parameters  map[string]interface{} `json:"parameters"`
}

FunctionDefinition represents a function definition

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
	Name    string `json:"name,omitempty"`
}

Message represents a chat message

type OllamaProvider

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

OllamaProvider implements the Provider interface for local Ollama

func NewOllamaProvider

func NewOllamaProvider(model string) *OllamaProvider

NewOllamaProvider creates a new Ollama provider

func (*OllamaProvider) Complete

func (*OllamaProvider) Embed

func (p *OllamaProvider) Embed(ctx context.Context, text string) ([]float64, error)

func (*OllamaProvider) Name

func (p *OllamaProvider) Name() string

func (*OllamaProvider) StreamComplete

func (p *OllamaProvider) StreamComplete(ctx context.Context, req CompletionRequest) (<-chan StreamChunk, error)

type OpenAIProvider

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

OpenAIProvider implements the Provider interface for OpenAI

func NewOpenAIProvider

func NewOpenAIProvider(apiKey, model string) *OpenAIProvider

NewOpenAIProvider creates a new OpenAI provider

func (*OpenAIProvider) Complete

func (*OpenAIProvider) Embed

func (p *OpenAIProvider) Embed(ctx context.Context, text string) ([]float64, error)

func (*OpenAIProvider) Name

func (p *OpenAIProvider) Name() string

func (*OpenAIProvider) StreamComplete

func (p *OpenAIProvider) StreamComplete(ctx context.Context, req CompletionRequest) (<-chan StreamChunk, error)

type Provider

type Provider interface {
	Name() string
	Complete(ctx context.Context, req CompletionRequest) (*CompletionResponse, error)
	StreamComplete(ctx context.Context, req CompletionRequest) (<-chan StreamChunk, error)
	Embed(ctx context.Context, text string) ([]float64, error)
}

Provider defines an LLM provider interface

type ProviderConfig

type ProviderConfig struct {
	APIKey  string
	Model   string
	BaseURL string
}

ProviderConfig holds provider configuration

type ProviderFactory

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

ProviderFactory creates providers by type

func NewProviderFactory

func NewProviderFactory() *ProviderFactory

NewProviderFactory creates a new factory

func (*ProviderFactory) Create

func (pf *ProviderFactory) Create(name string) (Provider, error)

Create creates a provider by name wrapped with circuit breaker protection.

func (*ProviderFactory) Register

func (pf *ProviderFactory) Register(name string, config ProviderConfig)

Register registers a provider configuration

type ProviderWithBreaker

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

ProviderWithBreaker wraps a Provider with circuit breaker protection and retry logic.

func WrapProvider

func WrapProvider(p Provider, breaker *circuitbreaker.Breaker) *ProviderWithBreaker

WrapProvider creates a ProviderWithBreaker that adds circuit breaker protection and exponential backoff retry to any Provider.

func (*ProviderWithBreaker) Complete

Complete executes a completion request with circuit breaker protection and retry.

func (*ProviderWithBreaker) Embed

func (pw *ProviderWithBreaker) Embed(ctx context.Context, text string) ([]float64, error)

Embed proxies to the wrapped provider with circuit breaker protection.

func (*ProviderWithBreaker) Name

func (pw *ProviderWithBreaker) Name() string

Name returns the wrapped provider name.

func (*ProviderWithBreaker) StreamComplete

func (pw *ProviderWithBreaker) StreamComplete(ctx context.Context, req CompletionRequest) (<-chan StreamChunk, error)

StreamComplete proxies to the wrapped provider (no retry for streaming).

type StreamChunk

type StreamChunk struct {
	Content string
	Done    bool
}

StreamChunk represents a streaming response chunk

type ToolDefinition

type ToolDefinition struct {
	Type     string             `json:"type"`
	Function FunctionDefinition `json:"function"`
}

ToolDefinition represents a tool definition for function calling

type UsageInfo

type UsageInfo struct {
	PromptTokens     int
	CompletionTokens int
	TotalTokens      int
}

UsageInfo holds token usage information

Jump to

Keyboard shortcuts

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