provider

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Code generated by enum generator; DO NOT EDIT.

Index

Constants

View Source
const DefaultMaxTokens = 1024

DefaultMaxTokens defines the default value for max tokens if not specified or negative

View Source
const DefaultTemperature = 0.7

DefaultTemperature defines the default temperature if not specified or negative

Variables

View Source
var (
	ProviderTypeUnknown   = ProviderType{/* contains filtered or unexported fields */}
	ProviderTypeOpenAI    = ProviderType{/* contains filtered or unexported fields */}
	ProviderTypeAnthropic = ProviderType{/* contains filtered or unexported fields */}
	ProviderTypeGoogle    = ProviderType{/* contains filtered or unexported fields */}
	ProviderTypeCustom    = ProviderType{/* contains filtered or unexported fields */}
)

Public constants for providerType values

View Source
var ProviderTypeNames = []string{
	"unknown",
	"openai",
	"anthropic",
	"google",
	"custom",
}

ProviderTypeNames contains all possible enum names

ProviderTypeValues contains all possible enum values

Functions

func ProviderTypeIter added in v0.12.0

func ProviderTypeIter() func(yield func(ProviderType) bool)

ProviderTypeIter returns a function compatible with Go 1.23's range-over-func syntax. It yields all ProviderType values in declaration order. Example:

for v := range ProviderTypeIter() {
    // use v
}

Types

type Anthropic

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

Anthropic implements Provider interface for Anthropic

func NewAnthropic

func NewAnthropic(opts Options) *Anthropic

NewAnthropic creates a new Anthropic provider

func (*Anthropic) Enabled

func (a *Anthropic) Enabled() bool

Enabled returns whether this provider is enabled

func (*Anthropic) Generate

func (a *Anthropic) Generate(ctx context.Context, prompt string) (string, error)

Generate sends a prompt to Anthropic and returns the generated text

func (*Anthropic) Name

func (a *Anthropic) Name() string

Name returns the provider name

type CustomOpenAI

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

CustomOpenAI implements Provider interface for OpenAI-compatible providers it wraps the OpenAI provider with custom base URL and name

func NewCustomOpenAI

func NewCustomOpenAI(opts CustomOptions) *CustomOpenAI

NewCustomOpenAI creates a new custom OpenAI-compatible provider

func (*CustomOpenAI) Enabled

func (c *CustomOpenAI) Enabled() bool

Enabled returns whether this provider is enabled

func (*CustomOpenAI) Generate

func (c *CustomOpenAI) Generate(ctx context.Context, prompt string) (string, error)

Generate sends a prompt to the custom provider and returns the generated text

func (*CustomOpenAI) Name

func (c *CustomOpenAI) Name() string

Name returns the custom provider name

type CustomOptions

type CustomOptions struct {
	Name         string       // custom provider name
	BaseURL      string       // base URL for the API
	APIKey       string       // API key for authentication
	Model        string       // model name to use
	Enabled      bool         // whether provider is enabled
	MaxTokens    int          // maximum number of tokens to generate
	Temperature  float32      // controls randomness (0-1, default: 0.7)
	EndpointType EndpointType // endpoint type (auto, responses, chat_completions)
	HTTPClient   HTTPClient   // optional HTTP client for dependency injection
}

CustomOptions defines options for custom OpenAI-compatible providers

type EndpointType added in v0.14.0

type EndpointType string

EndpointType represents the API endpoint type for OpenAI-compatible providers

const (
	// EndpointTypeAuto automatically selects endpoint based on model name
	EndpointTypeAuto EndpointType = "auto"
	// EndpointTypeResponses forces use of v1/responses endpoint
	EndpointTypeResponses EndpointType = "responses"
	// EndpointTypeChatCompletions forces use of v1/chat/completions endpoint
	EndpointTypeChatCompletions EndpointType = "chat_completions"
)

type Google

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

Google implements Provider interface for Google's Gemini models

func NewGoogle

func NewGoogle(opts Options) *Google

NewGoogle creates a new Google provider

func (*Google) Enabled

func (g *Google) Enabled() bool

Enabled returns whether this provider is enabled

func (*Google) Generate

func (g *Google) Generate(ctx context.Context, prompt string) (string, error)

Generate sends a prompt to Google and returns the generated text

func (*Google) Name

func (g *Google) Name() string

Name returns the provider name

type HTTPClient added in v0.14.0

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is an interface for making HTTP requests, allows for dependency injection and testing

type OpenAI

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

OpenAI implements Provider interface for OpenAI

func NewOpenAI

func NewOpenAI(opts Options) *OpenAI

NewOpenAI creates a new OpenAI provider

func (*OpenAI) Enabled

func (o *OpenAI) Enabled() bool

Enabled returns whether this provider is enabled

func (*OpenAI) Generate

func (o *OpenAI) Generate(ctx context.Context, prompt string) (string, error)

Generate sends a prompt to OpenAI and returns the generated text

func (*OpenAI) Name

func (o *OpenAI) Name() string

Name returns the provider name

type Options

type Options struct {
	APIKey            string
	Enabled           bool
	Model             string
	MaxTokens         int          // maximum number of tokens to generate
	Temperature       float32      // controls randomness (0-1, default: 0.7)
	ReasoningEffort   string       // reasoning effort level: minimal, low, medium (default), high (OpenAI only)
	HTTPClient        HTTPClient   // optional HTTP client for dependency injection, defaults to &http.Client{} if nil
	BaseURL           string       // optional base URL for custom endpoints (OpenAI-compatible providers only)
	ForceEndpointType EndpointType // optional manual endpoint selection (auto, responses, chat_completions)
}

Options defines common options for all providers

func (Options) Validate added in v0.4.0

func (o Options) Validate(providerType ProviderType) error

Validate checks if the provider options are valid

type Provider

type Provider interface {
	Name() string
	Generate(ctx context.Context, prompt string) (string, error)
	Enabled() bool
}

Provider defines the interface for LLM providers

func CreateProvider added in v0.3.3

func CreateProvider(providerType ProviderType, opts Options) (Provider, error)

CreateProvider creates a standard provider (OpenAI, Anthropic, Google) based on the provider type and options. It validates required fields and returns appropriate errors if validation fails.

func FindProviderByName added in v0.12.0

func FindProviderByName(name string, providers []Provider) Provider

FindProviderByName searches for a provider by name (case-insensitive partial match) among the given providers. It returns the first enabled provider that matches. If no match is found, it returns the first enabled provider as a fallback. Returns nil if no enabled providers are available.

func NewRetryableProvider added in v0.11.0

func NewRetryableProvider(p Provider, opts RetryOptions) Provider

NewRetryableProvider creates a provider wrapper with retry logic

func WrapProviderWithRetry added in v0.11.0

func WrapProviderWithRetry(p Provider, opts RetryOptions) Provider

WrapProviderWithRetry wraps a provider with retry logic if configured

func WrapProvidersWithRetry added in v0.11.0

func WrapProvidersWithRetry(providers []Provider, opts RetryOptions) []Provider

WrapProvidersWithRetry wraps multiple providers with retry logic

type ProviderType added in v0.12.0

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

ProviderType is the exported type for the enum

func MustProviderType added in v0.12.0

func MustProviderType(v string) ProviderType

MustProviderType is like ParseProviderType but panics if string is invalid

func ParseProviderType added in v0.12.0

func ParseProviderType(v string) (ProviderType, error)

ParseProviderType converts string to providerType enum value

func (ProviderType) Index added in v0.12.0

func (e ProviderType) Index() uint8

Index returns the underlying integer value

func (ProviderType) MarshalText added in v0.12.0

func (e ProviderType) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*ProviderType) Scan added in v0.12.0

func (e *ProviderType) Scan(value any) error

Scan implements the sql.Scanner interface

func (ProviderType) String added in v0.12.0

func (e ProviderType) String() string

func (*ProviderType) UnmarshalText added in v0.12.0

func (e *ProviderType) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

func (ProviderType) Value added in v0.12.0

func (e ProviderType) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type Reasoning added in v0.14.3

type Reasoning struct {
	Effort string `json:"effort"` // minimal, low, medium, high
}

Reasoning represents reasoning configuration for responses API

type Result

type Result struct {
	Provider string
	Text     string
	Error    error
}

Result represents a generation result from a provider

func (Result) Format

func (r Result) Format() string

Format formats a result for output with a provider header

type RetryOptions added in v0.11.0

type RetryOptions struct {
	Attempts int
	Delay    time.Duration
	MaxDelay time.Duration
	Factor   float64
}

RetryOptions configures retry behavior

type RetryableProvider added in v0.11.0

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

RetryableProvider wraps a provider with retry logic for transient failures. The wrapped provider must be safe for concurrent use if the RetryableProvider will be used concurrently. The retry logic itself is thread-safe.

func (*RetryableProvider) Enabled added in v0.11.0

func (r *RetryableProvider) Enabled() bool

Enabled returns whether this provider is enabled

func (*RetryableProvider) Generate added in v0.11.0

func (r *RetryableProvider) Generate(ctx context.Context, prompt string) (string, error)

Generate sends a prompt to the provider with retry logic

func (*RetryableProvider) Name added in v0.11.0

func (r *RetryableProvider) Name() string

Name returns the provider name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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