Documentation
¶
Overview ¶
Package providers contains implementations of different LLM providers for text summarization.
Index ¶
- Constants
- func MockServer(t *testing.T, config MockResponseConfig) *httptest.Server
- type AnthropicMessage
- type AnthropicProvider
- type AnthropicRequest
- type AnthropicResponse
- type CapturingProvider
- type Config
- type GoogleContent
- type GoogleProvider
- type GoogleRequest
- type GoogleResponse
- type LLMProvider
- type MockResponseConfig
- type OpenAIMessage
- type OpenAIProvider
- type OpenAIRequest
- type OpenAIResponse
- type ProviderFactory
- type TestProvider
- type XAIMessage
- type XAIProvider
- type XAIRequest
- type XAIResponse
Constants ¶
const ( // Provider constants ProviderAnthropic = "anthropic" ProviderOpenAI = "openai" ProviderGoogle = "google" ProviderXAI = "xai" // Default settings DefaultTimeout = 30 * time.Second DefaultMaxInputLength = 8000 )
Variables ¶
This section is empty.
Functions ¶
func MockServer ¶
func MockServer(t *testing.T, config MockResponseConfig) *httptest.Server
MockServer creates a test server that returns the configured response
Types ¶
type AnthropicMessage ¶
AnthropicMessage represents the request structure for Anthropic's API
type AnthropicProvider ¶
type AnthropicProvider struct {
Config
// contains filtered or unexported fields
}
AnthropicProvider implements the LLMProvider interface for Anthropic's Claude
func NewAnthropicProvider ¶
func NewAnthropicProvider(config Config) *AnthropicProvider
NewAnthropicProvider creates a new instance of the Anthropic provider
func (*AnthropicProvider) Name ¶
func (p *AnthropicProvider) Name() string
Name returns the provider name
type AnthropicRequest ¶
type AnthropicRequest struct {
Model string `json:"model"`
Messages []AnthropicMessage `json:"messages"`
MaxTokens int `json:"max_tokens"`
}
AnthropicRequest represents a request to Anthropic's API
type AnthropicResponse ¶
type AnthropicResponse struct {
Content []struct {
Text string `json:"text"`
} `json:"content"`
Error *struct {
Type string `json:"type"`
Message string `json:"message"`
} `json:"error,omitempty"`
}
AnthropicResponse represents a response from Anthropic's API
type CapturingProvider ¶
type CapturingProvider struct {
// contains filtered or unexported fields
}
CapturingProvider is a provider that captures the inputs for testing
func NewCapturingProvider ¶
func NewCapturingProvider(name, returnString string, returnError error) *CapturingProvider
NewCapturingProvider creates a new CapturingProvider
func (*CapturingProvider) GetCapturedMaxLength ¶
func (p *CapturingProvider) GetCapturedMaxLength() int
GetCapturedMaxLength returns the maxLength that was passed to Summarize
func (*CapturingProvider) GetCapturedText ¶
func (p *CapturingProvider) GetCapturedText() string
GetCapturedText returns the text that was passed to Summarize
func (*CapturingProvider) Name ¶
func (p *CapturingProvider) Name() string
Name returns the provider name
type GoogleContent ¶
type GoogleContent struct {
Parts []struct {
Text string `json:"text"`
} `json:"parts"`
}
GoogleContent represents content in Google's Gemini API format
type GoogleProvider ¶
type GoogleProvider struct {
Config
// contains filtered or unexported fields
}
GoogleProvider implements the LLMProvider interface for Google's Gemini models
func NewGoogleProvider ¶
func NewGoogleProvider(config Config) *GoogleProvider
NewGoogleProvider creates a new instance of the Google provider
type GoogleRequest ¶
type GoogleRequest struct {
Contents []struct {
Parts []struct {
Text string `json:"text"`
} `json:"parts"`
Role string `json:"role,omitempty"`
} `json:"contents"`
GenerationConfig struct {
MaxOutputTokens int `json:"maxOutputTokens"`
} `json:"generationConfig"`
}
GoogleRequest represents a request to Google's Gemini API
type GoogleResponse ¶
type GoogleResponse struct {
Candidates []struct {
Content struct {
Parts []struct {
Text string `json:"text"`
} `json:"parts"`
} `json:"content"`
} `json:"candidates"`
Error *struct {
Code int `json:"code"`
Message string `json:"message"`
Status string `json:"status"`
} `json:"error,omitempty"`
}
GoogleResponse represents a response from Google's Gemini API
type LLMProvider ¶
type LLMProvider interface {
// Summarize takes a text input and returns a condensed summary
Summarize(ctx context.Context, text string, maxLength int) (string, error)
// Name returns the provider name
Name() string
}
LLMProvider defines the interface for different LLM service providers
type MockResponseConfig ¶
type MockResponseConfig struct {
StatusCode int
ResponseBody interface{}
Headers map[string]string
}
MockResponseConfig holds configuration for mock API responses
type OpenAIMessage ¶
OpenAIMessage represents a message in OpenAI's chat format
type OpenAIProvider ¶
type OpenAIProvider struct {
Config
// contains filtered or unexported fields
}
OpenAIProvider implements the LLMProvider interface for OpenAI's models
func NewOpenAIProvider ¶
func NewOpenAIProvider(config Config) *OpenAIProvider
NewOpenAIProvider creates a new instance of the OpenAI provider
type OpenAIRequest ¶
type OpenAIRequest struct {
Model string `json:"model"`
Messages []OpenAIMessage `json:"messages"`
MaxTokens int `json:"max_tokens"`
}
OpenAIRequest represents a request to OpenAI's API
type OpenAIResponse ¶
type OpenAIResponse struct {
Choices []struct {
Message struct {
Content string `json:"content"`
} `json:"message"`
} `json:"choices"`
Error *struct {
Message string `json:"message"`
Type string `json:"type"`
} `json:"error,omitempty"`
}
OpenAIResponse represents a response from OpenAI's API
type ProviderFactory ¶
type ProviderFactory struct {
// ProviderConfigs stores configuration for each provider
ProviderConfigs map[string]Config
}
ProviderFactory creates and returns appropriate LLM providers
func NewProviderFactory ¶
func NewProviderFactory(configs map[string]Config) *ProviderFactory
NewProviderFactory creates a new provider factory
func (*ProviderFactory) GetAllProviders ¶
func (f *ProviderFactory) GetAllProviders() []LLMProvider
GetAllProviders returns all available providers based on configured providers
func (*ProviderFactory) GetProvider ¶
func (f *ProviderFactory) GetProvider(providerName string) (LLMProvider, error)
GetProvider returns an initialized provider instance for the specified provider name
func (*ProviderFactory) GetProviderChain ¶
func (f *ProviderFactory) GetProviderChain(preferenceOrder []string) []LLMProvider
GetProviderChain returns an ordered list of providers to try in sequence The ordered list is created based on the given preference order
type TestProvider ¶
type TestProvider struct {
// contains filtered or unexported fields
}
TestProvider is a simple implementation of LLMProvider for testing
func NewTestProvider ¶
func NewTestProvider(name string, returnString string, returnError error) *TestProvider
NewTestProvider creates a new TestProvider
type XAIMessage ¶
XAIMessage represents a message in X.AI's chat format (OpenAI compatible)
type XAIProvider ¶
type XAIProvider struct {
Config
// contains filtered or unexported fields
}
XAIProvider implements the LLMProvider interface for X.AI's Grok
func NewXAIProvider ¶
func NewXAIProvider(config Config) *XAIProvider
NewXAIProvider creates a new instance of the X.AI provider
type XAIRequest ¶
type XAIRequest struct {
Model string `json:"model"`
Messages []XAIMessage `json:"messages"`
MaxTokens int `json:"max_tokens"`
}
XAIRequest represents a request to X.AI's API (OpenAI compatible)
type XAIResponse ¶
type XAIResponse struct {
Choices []struct {
Message struct {
Content string `json:"content"`
} `json:"message"`
} `json:"choices"`
Error *struct {
Message string `json:"message"`
Type string `json:"type"`
} `json:"error,omitempty"`
}
XAIResponse represents a response from X.AI's API (OpenAI compatible)