Documentation
¶
Index ¶
- Constants
- type AnthropicMessageRequest
- type BenchmarkClient
- func (bc *BenchmarkClient) TestChatEndpoint(model string, messages []map[string]interface{}, concurrency int, ...) (*BenchmarkResult, error)
- func (bc *BenchmarkClient) TestMessagesEndpoint(model string, messages []map[string]interface{}, maxTokens int, ...) (*BenchmarkResult, error)
- func (bc *BenchmarkClient) TestModelsEndpoint(concurrency int, totalRequests int) (*BenchmarkResult, error)
- type BenchmarkOptions
- type BenchmarkResult
- type MockServer
- type Model
- type OpenAIChatRequest
- type Option
- func WithAnthropicDefaults() Option
- func WithApiKey(key string) Option
- func WithBothDefaults() Option
- func WithChatDelay(delayMs int) Option
- func WithChatResponse(response json.RawMessage) Option
- func WithChatResponseContent(content string) Option
- func WithChatResponses(responses []json.RawMessage, loop bool) Option
- func WithDefaultModels(models []Model) Option
- func WithDefaultOptions() Option
- func WithMessageDelay(delayMs int) Option
- func WithMessageResponse(response json.RawMessage) Option
- func WithMessageResponseContent(content string) Option
- func WithMessageResponses(responses []json.RawMessage, loop bool) Option
- func WithOpenAIDefaults() Option
- func WithPort(port int) Option
- func WithRandomDelay(minMs, maxMs int) Option
- type RequestResult
Examples ¶
Constants ¶
const ( DefaultPort = 12580 DefaultChatDelayMs = 100 DefaultMessageDelayMs = 150 DefaultRandomDelayMin = 10 DefaultRandomDelayMax = 100 )
Default configuration constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnthropicMessageRequest ¶
type BenchmarkClient ¶
type BenchmarkClient struct {
// contains filtered or unexported fields
}
func NewBenchmarkClient ¶
func NewBenchmarkClient(opts *BenchmarkOptions) *BenchmarkClient
func (*BenchmarkClient) TestChatEndpoint ¶
func (bc *BenchmarkClient) TestChatEndpoint(model string, messages []map[string]interface{}, concurrency int, totalRequests int) (*BenchmarkResult, error)
func (*BenchmarkClient) TestMessagesEndpoint ¶
func (bc *BenchmarkClient) TestMessagesEndpoint(model string, messages []map[string]interface{}, maxTokens int, concurrency int, totalRequests int) (*BenchmarkResult, error)
func (*BenchmarkClient) TestModelsEndpoint ¶
func (bc *BenchmarkClient) TestModelsEndpoint(concurrency int, totalRequests int) (*BenchmarkResult, error)
type BenchmarkOptions ¶
type BenchmarkResult ¶
type BenchmarkResult struct {
TotalRequests int `json:"totalRequests"`
SuccessRequests int `json:"successRequests"`
FailedRequests int `json:"failedRequests"`
TotalDuration time.Duration `json:"totalDuration"`
AvgResponseTime time.Duration `json:"avgResponseTime"`
MinResponseTime time.Duration `json:"minResponseTime"`
MaxResponseTime time.Duration `json:"maxResponseTime"`
RequestsPerSec float64 `json:"requestsPerSec"`
TotalBytes int64 `json:"totalBytes"`
ErrorRate float64 `json:"errorRate"`
StatusCodeCounts map[int]int `json:"statusCodeCounts"`
}
func (*BenchmarkResult) PrintSummary ¶
func (br *BenchmarkResult) PrintSummary()
type MockServer ¶
type MockServer struct {
// contains filtered or unexported fields
}
MockServer represents the mock server
Example ¶
// Create a mock server without authentication (default behavior) server := NewMockServer( WithPort(8082), WithOpenAIDefaults(), // No WithapiKey called - all requests allowed ) server.Start()
func NewMockServer ¶
func NewMockServer(opts ...Option) *MockServer
NewMockServer creates a new mock server with the given options
func (*MockServer) UseAuthMiddleware ¶
func (ms *MockServer) UseAuthMiddleware()
UseAuthMiddleware applies the auth middleware to all routes
Example ¶
// Create a mock server
server := NewMockServer(
WithPort(8083),
WithApiKey("my-secret-key"),
)
// Manually apply auth middleware (useful if you want to apply it conditionally)
server.UseAuthMiddleware()
server.Start()
type Model ¶
type Model struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
OwnedBy string `json:"owned_by"`
}
Model represents a model in the models list
type OpenAIChatRequest ¶
type OpenAIChatRequest struct {
Model string `json:"model"`
Messages []map[string]interface{} `json:"messages"`
Stream bool `json:"stream,omitempty"`
}
Use simple structs for requests instead of importing from SDKs
type Option ¶
type Option func(*serverConfig)
Option is a functional option for configuring the MockServer
func WithAnthropicDefaults ¶
func WithAnthropicDefaults() Option
WithAnthropicDefaults sets defaults for Anthropic endpoints
func WithApiKey ¶
WithApiKey sets the authentication key required for requests
Example ¶
// Create a mock server with authentication
server := NewMockServer(
WithPort(8081),
WithApiKey("test-api-key-123"),
WithOpenAIDefaults(),
)
// The auth middleware will be automatically applied when the server starts
// Clients must provide either:
// - Authorization: Bearer test-api-key-123
// - x-api-key: test-api-key-123
//
// If WithapiKey is not called or the key is empty, no authentication is required.
server.Start()
func WithBothDefaults ¶
func WithBothDefaults() Option
WithBothDefaults sets defaults for both OpenAI and Anthropic
func WithChatDelay ¶
WithChatDelay sets a fixed delay for chat responses (in milliseconds)
func WithChatResponse ¶
func WithChatResponse(response json.RawMessage) Option
WithChatResponse adds a single chat completion response (as raw JSON)
func WithChatResponseContent ¶
WithChatResponseContent adds a chat response from content string
func WithChatResponses ¶
func WithChatResponses(responses []json.RawMessage, loop bool) Option
WithChatResponses sets the default chat completion responses
func WithDefaultModels ¶
WithDefaultModels sets the default model list
func WithDefaultOptions ¶
func WithDefaultOptions() Option
WithDefaultOptions applies sensible defaults
func WithMessageDelay ¶
WithMessageDelay sets a fixed delay for message responses (in milliseconds)
func WithMessageResponse ¶
func WithMessageResponse(response json.RawMessage) Option
WithMessageResponse adds a single message response (as raw JSON)
func WithMessageResponseContent ¶
WithMessageResponseContent adds a message response from content string
func WithMessageResponses ¶
func WithMessageResponses(responses []json.RawMessage, loop bool) Option
WithMessageResponses sets the default message responses
func WithOpenAIDefaults ¶
func WithOpenAIDefaults() Option
WithOpenAIDefaults sets defaults for OpenAI endpoints
func WithRandomDelay ¶
WithRandomDelay sets a random delay range (in milliseconds)