base

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package base provides common functionality and utilities for AI providers. It includes base implementations, shared components, and standardized patterns that can be used by specific provider implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseProvider

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

BaseProvider provides common functionality for all providers

func NewBaseProvider

func NewBaseProvider(name string, config types.ProviderConfig, client *http.Client, logger *log.Logger) *BaseProvider

NewBaseProvider creates a new base provider

func (*BaseProvider) Authenticate

func (p *BaseProvider) Authenticate(ctx context.Context, authConfig types.AuthConfig) error

Authenticate handles API key authentication

func (*BaseProvider) Configure

func (p *BaseProvider) Configure(config types.ProviderConfig) error

Configure updates the provider configuration

func (*BaseProvider) Description

func (p *BaseProvider) Description() string

func (*BaseProvider) GenerateChatCompletion

func (p *BaseProvider) GenerateChatCompletion(ctx context.Context, options types.GenerateOptions) (types.ChatCompletionStream, error)

GenerateChatCompletion generates a mock chat completion

func (*BaseProvider) GetConfig

func (p *BaseProvider) GetConfig() types.ProviderConfig

GetConfig returns the current provider configuration

func (*BaseProvider) GetDefaultModel

func (p *BaseProvider) GetDefaultModel() string

func (*BaseProvider) GetMetrics

func (p *BaseProvider) GetMetrics() types.ProviderMetrics

func (*BaseProvider) GetModels

func (p *BaseProvider) GetModels(ctx context.Context) ([]types.Model, error)

func (*BaseProvider) GetToolFormat

func (p *BaseProvider) GetToolFormat() types.ToolFormat

func (*BaseProvider) HealthCheck

func (p *BaseProvider) HealthCheck(ctx context.Context) error

func (*BaseProvider) IncrementRequestCount

func (p *BaseProvider) IncrementRequestCount()

IncrementRequestCount increments the request counter

func (*BaseProvider) InvokeServerTool

func (p *BaseProvider) InvokeServerTool(ctx context.Context, toolName string, params interface{}) (interface{}, error)

InvokeServerTool invokes a server tool (not implemented in base provider)

func (*BaseProvider) IsAuthenticated

func (p *BaseProvider) IsAuthenticated() bool

func (*BaseProvider) LogRequest

func (p *BaseProvider) LogRequest(method, url string, headers map[string]string, body interface{})

LogRequest logs an HTTP request

func (*BaseProvider) LogResponse

func (p *BaseProvider) LogResponse(resp *http.Response, duration time.Duration)

LogResponse logs detailed response information

func (*BaseProvider) Logout

func (p *BaseProvider) Logout(ctx context.Context) error

func (*BaseProvider) Name

func (p *BaseProvider) Name() string

func (*BaseProvider) RecordError

func (p *BaseProvider) RecordError(err error)

RecordError records a failed API call

func (*BaseProvider) RecordSuccess

func (p *BaseProvider) RecordSuccess(latency time.Duration, tokensUsed int64)

RecordSuccess records a successful API call

func (*BaseProvider) SupportsResponsesAPI

func (p *BaseProvider) SupportsResponsesAPI() bool

func (*BaseProvider) SupportsStreaming

func (p *BaseProvider) SupportsStreaming() bool

func (*BaseProvider) SupportsToolCalling

func (p *BaseProvider) SupportsToolCalling() bool

func (*BaseProvider) Type

func (p *BaseProvider) Type() types.ProviderType

func (*BaseProvider) UpdateConfig

func (p *BaseProvider) UpdateConfig(config types.ProviderConfig)

UpdateConfig updates provider configuration

func (*BaseProvider) UpdateHealthStatus

func (p *BaseProvider) UpdateHealthStatus(healthy bool, message string)

UpdateHealthStatus updates the health status

func (*BaseProvider) UpdateHealthStatusResponseTime

func (p *BaseProvider) UpdateHealthStatusResponseTime(responseTime float64)

UpdateHealthStatusResponseTime updates the health status response time

type BaseProviderStub

type BaseProviderStub struct {
	*BaseProvider
}

BaseProviderStub wraps BaseProvider to implement Provider interface

func NewBaseProviderStub

func NewBaseProviderStub(name string, config types.ProviderConfig, client *http.Client, logger *log.Logger) *BaseProviderStub

func (*BaseProviderStub) Authenticate

func (b *BaseProviderStub) Authenticate(ctx context.Context, authConfig types.AuthConfig) error

func (*BaseProviderStub) Configure

func (b *BaseProviderStub) Configure(config types.ProviderConfig) error

func (*BaseProviderStub) Description

func (b *BaseProviderStub) Description() string

func (*BaseProviderStub) GenerateChatCompletion

func (b *BaseProviderStub) GenerateChatCompletion(ctx context.Context, options types.GenerateOptions) (types.ChatCompletionStream, error)

func (*BaseProviderStub) GetConfig

func (b *BaseProviderStub) GetConfig() types.ProviderConfig

func (*BaseProviderStub) GetDefaultModel

func (b *BaseProviderStub) GetDefaultModel() string

func (*BaseProviderStub) GetMetrics

func (b *BaseProviderStub) GetMetrics() types.ProviderMetrics

func (*BaseProviderStub) GetModels

func (b *BaseProviderStub) GetModels(ctx context.Context) ([]types.Model, error)

GetModels returns models from the base provider

func (*BaseProviderStub) GetToolFormat

func (b *BaseProviderStub) GetToolFormat() types.ToolFormat

func (*BaseProviderStub) HealthCheck

func (b *BaseProviderStub) HealthCheck(ctx context.Context) error

func (*BaseProviderStub) InvokeServerTool

func (b *BaseProviderStub) InvokeServerTool(ctx context.Context, toolName string, params interface{}) (interface{}, error)

func (*BaseProviderStub) IsAuthenticated

func (b *BaseProviderStub) IsAuthenticated() bool

func (*BaseProviderStub) Logout

func (b *BaseProviderStub) Logout(ctx context.Context) error

func (*BaseProviderStub) Name

func (b *BaseProviderStub) Name() string

Name returns the stub provider name

func (*BaseProviderStub) SupportsResponsesAPI

func (b *BaseProviderStub) SupportsResponsesAPI() bool

func (*BaseProviderStub) SupportsStreaming

func (b *BaseProviderStub) SupportsStreaming() bool

func (*BaseProviderStub) SupportsToolCalling

func (b *BaseProviderStub) SupportsToolCalling() bool

func (*BaseProviderStub) Type

type MockStream

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

MockStream implementation

func (*MockStream) Close

func (ms *MockStream) Close() error

func (*MockStream) Next

func (ms *MockStream) Next() (types.ChatCompletionChunk, error)

Jump to

Keyboard shortcuts

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