Documentation
¶
Overview ¶
Package factory provides the provider factory pattern for creating and managing AI provider instances. It includes provider registration, configuration validation, and dynamic provider instantiation.
Package factory provides provider factory functionality for AI providers. It includes registration, creation, and management of different AI provider implementations.
Package factory provides provider registration and factory functions for AI providers. It includes default provider registrations and specialized factory functions.
Package factory provides validation and configuration parsing utilities for AI providers. It includes provider configuration validation and helper functions for config map parsing.
Index ¶
- func CreateChatProvider(providerType types.ProviderType, config types.ProviderConfig) (types.ChatProvider, error)
- func CreateModelProvider(providerType types.ProviderType, config types.ProviderConfig) (types.ModelProvider, error)
- func CreateProviderFromConfig(factory *DefaultProviderFactory, configMap map[string]interface{}) (types.Provider, error)
- func InitializeDefaultProviders(factory *DefaultProviderFactory)
- func RegisterDefaultProviders(factory *DefaultProviderFactory)
- func ValidateProviderConfig(config types.ProviderConfig) error
- type DefaultProviderFactory
- func (f *DefaultProviderFactory) CreateProvider(providerType types.ProviderType, config types.ProviderConfig) (types.Provider, error)
- func (f *DefaultProviderFactory) GetHTTPClient(baseURL string) *pkghttp.HTTPClient
- func (f *DefaultProviderFactory) GetHTTPClientStats() pkghttp.ClientStats
- func (f *DefaultProviderFactory) GetHTTPClientWithConfig(baseURL string, config pkghttp.HTTPClientConfig) *pkghttp.HTTPClient
- func (f *DefaultProviderFactory) GetHTTPClientWithTimeout(baseURL string, timeout time.Duration) *pkghttp.HTTPClient
- func (f *DefaultProviderFactory) GetSupportedProviders() []types.ProviderType
- func (f *DefaultProviderFactory) RegisterProvider(providerType types.ProviderType, ...)
- func (f *DefaultProviderFactory) SetMetricsCollector(collector types.MetricsCollector)
- func (f *DefaultProviderFactory) ShutdownHTTPClients(ctx context.Context) error
- type FactoryMockStream
- type SimpleProviderStub
- func (p *SimpleProviderStub) Authenticate(ctx context.Context, authConfig types.AuthConfig) error
- func (p *SimpleProviderStub) Configure(config types.ProviderConfig) error
- func (p *SimpleProviderStub) Description() string
- func (p *SimpleProviderStub) GenerateChatCompletion(ctx context.Context, options types.GenerateOptions) (types.ChatCompletionStream, error)
- func (p *SimpleProviderStub) GetConfig() types.ProviderConfig
- func (p *SimpleProviderStub) GetDefaultModel() string
- func (p *SimpleProviderStub) GetMetrics() types.ProviderMetrics
- func (p *SimpleProviderStub) GetModels(ctx context.Context) ([]types.Model, error)
- func (p *SimpleProviderStub) GetToolFormat() types.ToolFormat
- func (p *SimpleProviderStub) HealthCheck(ctx context.Context) error
- func (p *SimpleProviderStub) InvokeServerTool(ctx context.Context, toolName string, params interface{}) (interface{}, error)
- func (p *SimpleProviderStub) IsAuthenticated() bool
- func (p *SimpleProviderStub) Logout(ctx context.Context) error
- func (p *SimpleProviderStub) Name() string
- func (p *SimpleProviderStub) SupportsResponsesAPI() bool
- func (p *SimpleProviderStub) SupportsStreaming() bool
- func (p *SimpleProviderStub) SupportsToolCalling() bool
- func (p *SimpleProviderStub) Type() types.ProviderType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateChatProvider ¶
func CreateChatProvider(providerType types.ProviderType, config types.ProviderConfig) (types.ChatProvider, error)
CreateChatProvider creates a ChatProvider instance. This demonstrates interface segregation - clients can depend only on ChatProvider when they only need chat completion capabilities.
func CreateModelProvider ¶
func CreateModelProvider(providerType types.ProviderType, config types.ProviderConfig) (types.ModelProvider, error)
CreateModelProvider creates a ModelProvider instance. This demonstrates interface segregation - clients can depend only on ModelProvider when they only need model discovery capabilities.
func CreateProviderFromConfig ¶
func CreateProviderFromConfig(factory *DefaultProviderFactory, configMap map[string]interface{}) (types.Provider, error)
func InitializeDefaultProviders ¶
func InitializeDefaultProviders(factory *DefaultProviderFactory)
InitializeDefaultProviders registers stub providers only for providers without real implementations This function is used for testing providers that don't have actual implementations yet. For providers with real implementations, use RegisterDefaultProviders instead.
func RegisterDefaultProviders ¶
func RegisterDefaultProviders(factory *DefaultProviderFactory)
RegisterDefaultProviders registers all default providers with the factory
func ValidateProviderConfig ¶
func ValidateProviderConfig(config types.ProviderConfig) error
Types ¶
type DefaultProviderFactory ¶
type DefaultProviderFactory struct {
// contains filtered or unexported fields
}
DefaultProviderFactory is the default factory implementation
func NewProviderFactory ¶
func NewProviderFactory() *DefaultProviderFactory
NewProviderFactory creates a new provider factory
func (*DefaultProviderFactory) CreateProvider ¶
func (f *DefaultProviderFactory) CreateProvider(providerType types.ProviderType, config types.ProviderConfig) (types.Provider, error)
CreateProvider creates a provider instance
func (*DefaultProviderFactory) GetHTTPClient ¶ added in v1.0.60
func (f *DefaultProviderFactory) GetHTTPClient(baseURL string) *pkghttp.HTTPClient
GetHTTPClient returns a shared HTTP client for the given base URL. This method provides access to the global HTTP client pool, enabling HTTP/2 connection sharing across providers targeting the same host.
The client pool is keyed by base URL (scheme://host), so providers targeting the same host will share the same underlying HTTP client.
func (*DefaultProviderFactory) GetHTTPClientStats ¶ added in v1.0.60
func (f *DefaultProviderFactory) GetHTTPClientStats() pkghttp.ClientStats
GetHTTPClientStats returns statistics about the HTTP client pool.
func (*DefaultProviderFactory) GetHTTPClientWithConfig ¶ added in v1.0.60
func (f *DefaultProviderFactory) GetHTTPClientWithConfig(baseURL string, config pkghttp.HTTPClientConfig) *pkghttp.HTTPClient
GetHTTPClientWithConfig returns a shared HTTP client for the given base URL with the specified configuration. The first caller's configuration will be used for all subsequent requests to the same base URL.
func (*DefaultProviderFactory) GetHTTPClientWithTimeout ¶ added in v1.0.60
func (f *DefaultProviderFactory) GetHTTPClientWithTimeout(baseURL string, timeout time.Duration) *pkghttp.HTTPClient
GetHTTPClientWithTimeout returns a shared HTTP client for the given base URL with a specific timeout. The first caller's timeout will be used for all subsequent requests to the same base URL.
func (*DefaultProviderFactory) GetSupportedProviders ¶
func (f *DefaultProviderFactory) GetSupportedProviders() []types.ProviderType
GetSupportedProviders returns all supported provider types
func (*DefaultProviderFactory) RegisterProvider ¶
func (f *DefaultProviderFactory) RegisterProvider(providerType types.ProviderType, factoryFunc func(types.ProviderConfig) types.Provider)
RegisterProvider registers a new provider type
func (*DefaultProviderFactory) SetMetricsCollector ¶ added in v1.0.7
func (f *DefaultProviderFactory) SetMetricsCollector(collector types.MetricsCollector)
SetMetricsCollector sets the metrics collector for the factory When set, all providers created by this factory will have the collector configured
func (*DefaultProviderFactory) ShutdownHTTPClients ¶ added in v1.0.60
func (f *DefaultProviderFactory) ShutdownHTTPClients(ctx context.Context) error
ShutdownHTTPClients closes all idle connections in the HTTP client pool. This should be called when shutting down the application to ensure all connections are properly closed.
type FactoryMockStream ¶
type FactoryMockStream struct{}
FactoryMockStream implements types.ChatCompletionStream
func (*FactoryMockStream) Close ¶
func (m *FactoryMockStream) Close() error
func (*FactoryMockStream) Next ¶
func (m *FactoryMockStream) Next() (types.ChatCompletionChunk, error)
type SimpleProviderStub ¶
type SimpleProviderStub struct {
// contains filtered or unexported fields
}
SimpleProviderStub implements types.Provider interface
func (*SimpleProviderStub) Authenticate ¶
func (p *SimpleProviderStub) Authenticate(ctx context.Context, authConfig types.AuthConfig) error
func (*SimpleProviderStub) Configure ¶
func (p *SimpleProviderStub) Configure(config types.ProviderConfig) error
func (*SimpleProviderStub) Description ¶
func (p *SimpleProviderStub) Description() string
func (*SimpleProviderStub) GenerateChatCompletion ¶
func (p *SimpleProviderStub) GenerateChatCompletion(ctx context.Context, options types.GenerateOptions) (types.ChatCompletionStream, error)
func (*SimpleProviderStub) GetConfig ¶
func (p *SimpleProviderStub) GetConfig() types.ProviderConfig
func (*SimpleProviderStub) GetDefaultModel ¶
func (p *SimpleProviderStub) GetDefaultModel() string
func (*SimpleProviderStub) GetMetrics ¶
func (p *SimpleProviderStub) GetMetrics() types.ProviderMetrics
func (*SimpleProviderStub) GetToolFormat ¶
func (p *SimpleProviderStub) GetToolFormat() types.ToolFormat
func (*SimpleProviderStub) HealthCheck ¶
func (p *SimpleProviderStub) HealthCheck(ctx context.Context) error
func (*SimpleProviderStub) InvokeServerTool ¶
func (p *SimpleProviderStub) InvokeServerTool(ctx context.Context, toolName string, params interface{}) (interface{}, error)
func (*SimpleProviderStub) IsAuthenticated ¶
func (p *SimpleProviderStub) IsAuthenticated() bool
func (*SimpleProviderStub) Name ¶
func (p *SimpleProviderStub) Name() string
Name returns the provider name
func (*SimpleProviderStub) SupportsResponsesAPI ¶
func (p *SimpleProviderStub) SupportsResponsesAPI() bool
func (*SimpleProviderStub) SupportsStreaming ¶
func (p *SimpleProviderStub) SupportsStreaming() bool
func (*SimpleProviderStub) SupportsToolCalling ¶
func (p *SimpleProviderStub) SupportsToolCalling() bool
func (*SimpleProviderStub) Type ¶
func (p *SimpleProviderStub) Type() types.ProviderType