Documentation
¶
Index ¶
- func PrintModelMenu(p *util.Printer, title string, models []string, defaultModels []string)
- type APITester
- type Channel
- type ChannelTest
- func (ct *ChannelTest) PrintResults(results []TestResult) error
- func (ct *ChannelTest) TestAllApis(channels []*Channel) []TestResult
- func (ct *ChannelTest) TestAllChannels(ctx context.Context, configs []*TestConfig) []TestResult
- func (ct *ChannelTest) TestChannel(ctx context.Context, cfg *TestConfig) TestResult
- type ChannelTestConfig
- type ChannelTestOption
- func WithClient(client HTTPClient) ChannelTestOption
- func WithConfig(config *ChannelTestConfig) ChannelTestOption
- func WithPrinter(printer *util.Printer) ChannelTestOption
- func WithRequestBuilder(builder RequestBuilder) ChannelTestOption
- func WithResultProcessor(processor ResultProcessor) ChannelTestOption
- type ChannelType
- type DefaultRequestBuilder
- type DefaultResultProcessor
- type GeminiError
- type HTTPClient
- type Message
- type OpenAIError
- type OpenAIRequest
- type OpenAIResponse
- type RequestBuilder
- type RequestOptions
- type ResultProcessor
- type TestConfig
- type TestResult
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APITester ¶
type APITester interface { TestChannel(context.Context, *TestConfig) TestResult TestAllChannels(context.Context, []*TestConfig) []TestResult TestAllApis([]*Channel) []TestResult PrintResults([]TestResult) error }
APITester defines the main interface for API testing
func NewApiTest ¶
func NewApiTest(maxConcurrency int, opts ...ChannelTestOption) APITester
NewApiTest creates a new API test instance with options
type Channel ¶
type Channel struct { Key string `json:"key"` TestModel []string `json:"test_model"` URL string `json:"url"` Type ChannelType `json:"type"` }
Channel represents an API channel configuration
type ChannelTest ¶
type ChannelTest struct {
// contains filtered or unexported fields
}
ChannelTest represents a test for API channels
func NewChannelTest ¶
func NewChannelTest(maxConcurrency int, w io.Writer) *ChannelTest
NewChannelTest creates a new ChannelTest instance
func (*ChannelTest) PrintResults ¶
func (ct *ChannelTest) PrintResults(results []TestResult) error
PrintResults prints the test results in a formatted way
func (*ChannelTest) TestAllApis ¶
func (ct *ChannelTest) TestAllApis(channels []*Channel) []TestResult
TestAllApis is a compatibility method that calls TestAllChannels
func (*ChannelTest) TestAllChannels ¶
func (ct *ChannelTest) TestAllChannels(ctx context.Context, configs []*TestConfig) []TestResult
TestAllChannels tests multiple channels concurrently
func (*ChannelTest) TestChannel ¶
func (ct *ChannelTest) TestChannel(ctx context.Context, cfg *TestConfig) TestResult
TestChannel tests a single channel with the specified configuration
type ChannelTestConfig ¶
func DefaultConfig ¶
func DefaultConfig() *ChannelTestConfig
DefaultConfig returns the default configuration
type ChannelTestOption ¶
type ChannelTestOption func(*ChannelTest)
ChannelTestOption defines a function type for configuring ChannelTest
func WithClient ¶
func WithClient(client HTTPClient) ChannelTestOption
WithClient sets the HTTP client
func WithConfig ¶
func WithConfig(config *ChannelTestConfig) ChannelTestOption
WithConfig sets the configuration
func WithPrinter ¶
func WithPrinter(printer *util.Printer) ChannelTestOption
WithPrinter sets the printer
func WithRequestBuilder ¶
func WithRequestBuilder(builder RequestBuilder) ChannelTestOption
WithRequestBuilder sets the request builder
func WithResultProcessor ¶
func WithResultProcessor(processor ResultProcessor) ChannelTestOption
WithResultProcessor sets the result processor
type ChannelType ¶
type ChannelType int
ChannelType represents the type of API channel
const ( ChannelTypeGemini ChannelType = iota ChannelTypeOpenAI )
type DefaultRequestBuilder ¶
type DefaultRequestBuilder struct{}
DefaultRequestBuilder implements the RequestBuilder interface
func NewRequestBuilder ¶
func NewRequestBuilder() *DefaultRequestBuilder
NewRequestBuilder creates a new DefaultRequestBuilder
func (*DefaultRequestBuilder) BuildRequest ¶
func (b *DefaultRequestBuilder) BuildRequest(ctx context.Context, cfg *TestConfig) (*http.Request, error)
BuildRequest builds an HTTP request based on the test configuration
type DefaultResultProcessor ¶
type DefaultResultProcessor struct {
// contains filtered or unexported fields
}
DefaultResultProcessor implements the ResultProcessor interface
func (*DefaultResultProcessor) ProcessResponse ¶
func (p *DefaultResultProcessor) ProcessResponse(resp *http.Response) TestResult
ProcessResponse processes the HTTP response and returns a TestResult
type GeminiError ¶
type GeminiError struct { Error struct { Code int `json:"code"` Message string `json:"message"` Status string `json:"status"` Details []struct { Type string `json:"@type"` Reason string `json:"reason,omitempty"` Domain string `json:"domain,omitempty"` Metadata map[string]string `json:"metadata,omitempty"` Message string `json:"message,omitempty"` Locale string `json:"locale,omitempty"` } `json:"details"` } `json:"error"` }
GeminiError represents the error structure returned by Gemini API
type HTTPClient ¶
HTTPClient abstracts the HTTP client for better testing
type OpenAIError ¶
type OpenAIError struct { Error struct { Message string `json:"message"` Type string `json:"type"` Code string `json:"code"` } `json:"error"` }
OpenAIError represents the error structure returned by OpenAI API
type OpenAIRequest ¶
type OpenAIRequest struct { Model string `json:"model"` Messages []Message `json:"messages"` Stream bool `json:"stream"` MaxTokens int `json:"max_tokens,omitempty"` MaxCompletionTokens int `json:"max_completion_tokens,omitempty"` }
OpenAIRequest represents a request to the OpenAI API
type OpenAIResponse ¶
type OpenAIResponse struct {
Usage *Usage `json:"usage"`
}
Parse OpenAI response
type RequestBuilder ¶
RequestBuilder builds HTTP requests for different API types
type RequestOptions ¶
RequestOptions holds options for API requests
type ResultProcessor ¶
type ResultProcessor interface {
ProcessResponse(*http.Response) TestResult
}
ResultProcessor processes API responses
func NewResultProcessor ¶
func NewResultProcessor(key, model string) ResultProcessor
NewResultProcessor creates a new DefaultResultProcessor
type TestConfig ¶
type TestConfig struct { Channel *Channel Model string RequestOpts RequestOptions IsGemini bool }
TestConfig holds configuration for a single test