Documentation
ΒΆ
Index ΒΆ
- func AnthropicResponse(content, model string) string
- func AssertResponse(t interface{ ... }, response *Response, ...)
- func AssertStreamChunk(t interface{ ... }, chunk StreamChunk, expectedContent, expectedDelta string, ...)
- func ConcurrentTestHelper(t interface{ ... }, numGoroutines int, operation func(int) error)
- func ErrorResponse(code int, message string) string
- func OllamaResponse(content, model string) string
- func OpenAIResponse(content, model string) string
- func OpenAIStreamResponse(deltas []string, model string) string
- func WithTimeout(timeout time.Duration) (context.Context, context.CancelFunc)
- type AnthropicAdapter
- func (a *AnthropicAdapter) Generate(ctx context.Context, config Config) (*Response, error)
- func (a *AnthropicAdapter) GenerateStream(ctx context.Context, config Config) (<-chan StreamChunk, error)
- func (a *AnthropicAdapter) Name() string
- func (a *AnthropicAdapter) ValidateConfig(config Config) error
- type Client
- func (c *Client) Generate(ctx context.Context, config Config) (*Response, error)
- func (c *Client) GenerateStream(ctx context.Context, config Config) (<-chan StreamChunk, error)
- func (c *Client) GenerateStreamWithProvider(ctx context.Context, providerName string, config Config) (<-chan StreamChunk, error)
- func (c *Client) GenerateWithFallback(ctx context.Context, providerNames []string, config Config) (*Response, error)
- func (c *Client) GenerateWithProvider(ctx context.Context, providerName string, config Config) (*Response, error)
- func (c *Client) ListProviders() []string
- func (c *Client) RegisterProvider(name string, provider Provider) error
- func (c *Client) SetDefaultProvider(name string) error
- type Config
- type GoogleAdapter
- type Message
- type MockHTTPServer
- type MockProvider
- type MockResponse
- type OllamaAdapter
- type OpenAIAdapter
- type Provider
- type Response
- type StreamChunk
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func AnthropicResponse ΒΆ
AnthropicResponse creates a mock Anthropic response
func AssertResponse ΒΆ
func AssertResponse(t interface {
Helper()
Errorf(format string, args ...interface{})
}, response *Response, expectedContent, expectedModel, expectedProvider string)
AssertResponse validates a response matches expected values
func AssertStreamChunk ΒΆ
func AssertStreamChunk(t interface {
Helper()
Errorf(format string, args ...interface{})
}, chunk StreamChunk, expectedContent, expectedDelta string, expectedDone bool)
AssertStreamChunk validates a stream chunk
func ConcurrentTestHelper ΒΆ
func ConcurrentTestHelper(t interface {
Helper()
Errorf(format string, args ...interface{})
}, numGoroutines int, operation func(int) error)
ConcurrentTestHelper helps test concurrent operations
func ErrorResponse ΒΆ
ErrorResponse creates a mock error response
func OllamaResponse ΒΆ
OllamaResponse creates a mock Ollama response
func OpenAIResponse ΒΆ
OpenAIResponse creates a mock OpenAI response
func OpenAIStreamResponse ΒΆ
OpenAIStreamResponse creates a mock OpenAI streaming response
func WithTimeout ΒΆ
WithTimeout creates a context with timeout for testing
Types ΒΆ
type AnthropicAdapter ΒΆ
type AnthropicAdapter struct {
// contains filtered or unexported fields
}
func (*AnthropicAdapter) GenerateStream ΒΆ
func (a *AnthropicAdapter) GenerateStream(ctx context.Context, config Config) (<-chan StreamChunk, error)
func (*AnthropicAdapter) Name ΒΆ
func (a *AnthropicAdapter) Name() string
func (*AnthropicAdapter) ValidateConfig ΒΆ
func (a *AnthropicAdapter) ValidateConfig(config Config) error
type Client ΒΆ
type Client struct {
// contains filtered or unexported fields
}
func (*Client) GenerateStream ΒΆ
func (*Client) GenerateStreamWithProvider ΒΆ
func (*Client) GenerateWithFallback ΒΆ
func (*Client) GenerateWithProvider ΒΆ
func (*Client) ListProviders ΒΆ
func (*Client) RegisterProvider ΒΆ
func (*Client) SetDefaultProvider ΒΆ
type Config ΒΆ
type Config struct {
Token string `json:"token"`
Model string `json:"model"`
BaseURL string `json:"base_url"`
ResponseFormat string `json:"response_format,omitempty"`
Schema map[string]interface{} `json:"schema,omitempty"`
SystemPrompt string `json:"system_prompt,omitempty"`
Messages []Message `json:"messages"`
Options map[string]interface{} `json:"options,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
}
func TestConfigWithJSONSchema ΒΆ
TestConfigWithJSONSchema creates a test config with JSON response format
func TestConfigWithSystemPrompt ΒΆ
TestConfigWithSystemPrompt creates a test config with system prompt
type GoogleAdapter ΒΆ
type GoogleAdapter struct {
// contains filtered or unexported fields
}
func (*GoogleAdapter) GenerateStream ΒΆ
func (a *GoogleAdapter) GenerateStream(ctx context.Context, config Config) (<-chan StreamChunk, error)
func (*GoogleAdapter) Name ΒΆ
func (a *GoogleAdapter) Name() string
func (*GoogleAdapter) ValidateConfig ΒΆ
func (a *GoogleAdapter) ValidateConfig(config Config) error
type Message ΒΆ
func TestMessage ΒΆ
TestMessage creates a test message
type MockHTTPServer ΒΆ
type MockHTTPServer struct {
*httptest.Server
RequestCount int
LastRequest *http.Request
LastBody string
Responses []MockResponse
}
MockHTTPServer creates a mock HTTP server for testing providers
func NewMockHTTPServer ΒΆ
func NewMockHTTPServer(responses []MockResponse) *MockHTTPServer
NewMockHTTPServer creates a new mock HTTP server
type MockProvider ΒΆ
type MockProvider struct {
// contains filtered or unexported fields
}
MockProvider implements the Provider interface for testing
func FailingMockProvider ΒΆ
func FailingMockProvider(errorMessage string) *MockProvider
FailingMockProvider creates a provider that always fails
func SlowMockProvider ΒΆ
func SlowMockProvider(delay time.Duration) *MockProvider
SlowMockProvider creates a provider that responds slowly (for timeout testing)
func StreamingMockProvider ΒΆ
func StreamingMockProvider(chunks []StreamChunk) *MockProvider
StreamingMockProvider creates a provider that returns streaming responses
func (*MockProvider) GenerateStream ΒΆ
func (m *MockProvider) GenerateStream(ctx context.Context, config Config) (<-chan StreamChunk, error)
func (*MockProvider) Name ΒΆ
func (m *MockProvider) Name() string
func (*MockProvider) ValidateConfig ΒΆ
func (m *MockProvider) ValidateConfig(config Config) error
type MockResponse ΒΆ
type OllamaAdapter ΒΆ
type OllamaAdapter struct {
// contains filtered or unexported fields
}
func (*OllamaAdapter) GenerateStream ΒΆ
func (a *OllamaAdapter) GenerateStream(ctx context.Context, config Config) (<-chan StreamChunk, error)
func (*OllamaAdapter) Name ΒΆ
func (a *OllamaAdapter) Name() string
func (*OllamaAdapter) ValidateConfig ΒΆ
func (a *OllamaAdapter) ValidateConfig(config Config) error
type OpenAIAdapter ΒΆ
type OpenAIAdapter struct {
// contains filtered or unexported fields
}
func (*OpenAIAdapter) GenerateStream ΒΆ
func (a *OpenAIAdapter) GenerateStream(ctx context.Context, config Config) (<-chan StreamChunk, error)
func (*OpenAIAdapter) Name ΒΆ
func (a *OpenAIAdapter) Name() string
func (*OpenAIAdapter) ValidateConfig ΒΆ
func (a *OpenAIAdapter) ValidateConfig(config Config) error
type Provider ΒΆ
type Provider interface {
Name() string
Generate(ctx context.Context, config Config) (*Response, error)
GenerateStream(ctx context.Context, config Config) (<-chan StreamChunk, error)
ValidateConfig(config Config) error
}
func NewAnthropicProvider ΒΆ
func NewAnthropicProvider() Provider
func NewGoogleProvider ΒΆ
func NewGroqProvider ΒΆ
func NewGroqProvider() Provider
func NewOllamaProvider ΒΆ
func NewOllamaProvider() Provider
func NewOpenAIProvider ΒΆ
func NewOpenAIProvider() Provider
func NewOpenRouterProvider ΒΆ
func NewOpenRouterProvider() Provider
type Response ΒΆ
type Response struct {
Content string `json:"content"`
Usage map[string]interface{} `json:"usage,omitempty"`
Model string `json:"model"`
FinishReason string `json:"finish_reason,omitempty"`
Provider string `json:"provider,omitempty"`
Raw map[string]interface{} `json:"raw,omitempty"`
}
func TestResponse ΒΆ
TestResponse creates a test response
type StreamChunk ΒΆ
type StreamChunk struct {
Content string `json:"content"`
Delta string `json:"delta"`
Done bool `json:"done"`
FinishReason string `json:"finish_reason,omitempty"`
Error error `json:"error,omitempty"`
}
func TestStreamChunk ΒΆ
func TestStreamChunk(content, delta string, done bool) StreamChunk
TestStreamChunk creates a test stream chunk