Documentation
¶
Overview ¶
Package mock provides mock provider implementation for testing and development.
Index ¶
- type AudioURL
- type Config
- type ContentPart
- type FileMockRepository
- type ImageURL
- type InMemoryMockRepository
- func (r *InMemoryMockRepository) GetResponse(ctx context.Context, params ResponseParams) (string, error)
- func (r *InMemoryMockRepository) GetTurn(ctx context.Context, params ResponseParams) (*Turn, error)
- func (r *InMemoryMockRepository) SetResponse(scenarioID string, turnNumber int, response string)
- type Provider
- func (m *Provider) CalculateCost(inputTokens, outputTokens, cachedTokens int) types.CostInfo
- func (m *Provider) Close() error
- func (m *Provider) ID() string
- func (m *Provider) Predict(ctx context.Context, req providers.PredictionRequest) (providers.PredictionResponse, error)
- func (m *Provider) PredictStream(ctx context.Context, req providers.PredictionRequest) (<-chan providers.StreamChunk, error)
- func (m *Provider) ShouldIncludeRawOutput() bool
- func (m *Provider) SupportsStreaming() bool
- type ResponseParams
- type ResponseRepository
- type ScenarioConfig
- type ToolCall
- type ToolError
- type ToolProvider
- type ToolResponse
- type Turn
- type VideoURL
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioURL ¶ added in v1.1.3
type AudioURL struct {
URL string `yaml:"url"` // URL to the audio file (can be mock://, http://, https://, data:, or file path)
}
AudioURL represents audio content in a mock response.
type Config ¶ added in v1.1.3
type Config struct {
// Default response if no specific match is found
DefaultResponse string `yaml:"defaultResponse"`
// Scenario-specific responses keyed by scenario ID
Scenarios map[string]ScenarioConfig `yaml:"scenarios,omitempty"`
}
Config represents the structure of a mock configuration file. This allows scenario-specific and turn-specific responses to be defined.
type ContentPart ¶ added in v1.1.3
type ContentPart struct {
Type string `yaml:"type"` // "text", "image", "audio", or "video"
Text string `yaml:"text,omitempty"` // Text content (for type="text")
ImageURL *ImageURL `yaml:"image_url,omitempty"` // Image URL (for type="image")
AudioURL *AudioURL `yaml:"audio_url,omitempty"` // Audio URL (for type="audio")
VideoURL *VideoURL `yaml:"video_url,omitempty"` // Video URL (for type="video")
Metadata map[string]interface{} `yaml:"metadata,omitempty"` // Additional metadata
}
ContentPart represents a single content part in a multimodal mock response. This mirrors the structure of types.ContentPart but with YAML-friendly field names.
func (*ContentPart) ToContentPart ¶ added in v1.1.3
func (m *ContentPart) ToContentPart() *types.ContentPart
ToContentPart converts a ContentPart to types.ContentPart.
type FileMockRepository ¶
type FileMockRepository struct {
// contains filtered or unexported fields
}
FileMockRepository loads mock responses from a YAML configuration file. This is the default implementation for file-based mock configurations.
func NewFileMockRepository ¶
func NewFileMockRepository(configPath string) (*FileMockRepository, error)
NewFileMockRepository creates a repository that loads mock responses from a YAML file. The file should follow the Config structure with scenarios and turn-specific responses.
func (*FileMockRepository) GetResponse ¶
func (r *FileMockRepository) GetResponse(ctx context.Context, params ResponseParams) (string, error)
GetResponse retrieves a mock response based on the provided parameters. It follows this priority order: 1. Scenario + Turn specific response 2. Scenario default response 3. Global default response 4. Generic fallback message
func (*FileMockRepository) GetTurn ¶
func (r *FileMockRepository) GetTurn(ctx context.Context, params ResponseParams) (*Turn, error)
GetTurn retrieves a structured mock turn response that may include tool calls. This method supports both backward-compatible string responses and new structured Turn responses.
type ImageURL ¶ added in v1.1.3
type ImageURL struct {
URL string `yaml:"url"` // URL to the image (can be mock://, http://, https://, data:, or file path)
Detail *string `yaml:"detail,omitempty"` // Detail level: "low", "high", "auto"
}
ImageURL represents image content in a mock response.
type InMemoryMockRepository ¶
type InMemoryMockRepository struct {
// contains filtered or unexported fields
}
InMemoryMockRepository stores mock responses in memory. This is useful for testing and programmatic configuration without files.
func NewInMemoryMockRepository ¶
func NewInMemoryMockRepository(defaultResponse string) *InMemoryMockRepository
NewInMemoryMockRepository creates an in-memory repository with a default response.
func (*InMemoryMockRepository) GetResponse ¶
func (r *InMemoryMockRepository) GetResponse(ctx context.Context, params ResponseParams) (string, error)
GetResponse retrieves a mock response based on the provided parameters.
func (*InMemoryMockRepository) GetTurn ¶
func (r *InMemoryMockRepository) GetTurn(ctx context.Context, params ResponseParams) (*Turn, error)
GetTurn retrieves a structured mock turn response. InMemoryMockRepository currently only supports simple text responses.
func (*InMemoryMockRepository) SetResponse ¶
func (r *InMemoryMockRepository) SetResponse(scenarioID string, turnNumber int, response string)
SetResponse sets a mock response for a specific scenario and turn. Use turnNumber = 0 for scenario default, or -1 for global default.
type Provider ¶ added in v1.1.3
type Provider struct {
// contains filtered or unexported fields
}
Provider is a provider implementation for testing and development. It returns mock responses without making any API calls, using a repository pattern to source responses from various backends (files, memory, databases).
Provider is designed to be reusable across different contexts:
- Arena testing: scenario and turn-specific responses
- SDK examples: simple deterministic responses
- Unit tests: programmatic response configuration
func NewProvider ¶ added in v1.1.3
NewProvider creates a new mock provider with default in-memory responses. This constructor maintains backward compatibility with existing code.
func NewProviderWithRepository ¶ added in v1.1.3
func NewProviderWithRepository(id, model string, includeRawOutput bool, repo ResponseRepository) *Provider
NewProviderWithRepository creates a mock provider with a custom response repository. This allows for advanced scenarios like file-based or database-backed mock responses.
func (*Provider) CalculateCost ¶ added in v1.1.3
CalculateCost calculates cost breakdown for given token counts.
func (*Provider) Predict ¶ added in v1.1.3
func (m *Provider) Predict(ctx context.Context, req providers.PredictionRequest) (providers.PredictionResponse, error)
Predict returns a mock response using the configured repository.
func (*Provider) PredictStream ¶ added in v1.1.3
func (m *Provider) PredictStream(ctx context.Context, req providers.PredictionRequest) (<-chan providers.StreamChunk, error)
PredictStream returns a mock streaming response using the configured repository.
func (*Provider) ShouldIncludeRawOutput ¶ added in v1.1.3
ShouldIncludeRawOutput returns whether raw API responses should be included.
func (*Provider) SupportsStreaming ¶ added in v1.1.3
SupportsStreaming indicates whether the provider supports streaming.
type ResponseParams ¶ added in v1.1.3
type ResponseParams struct {
ScenarioID string // Optional: ID of the scenario being executed
TurnNumber int // Optional: Turn number in a multi-turn conversation
ProviderID string // Optional: ID of the provider being mocked
ModelName string // Optional: Model name being mocked
}
ResponseParams contains parameters for looking up mock responses. Different implementations may use different subsets of these fields.
type ResponseRepository ¶ added in v1.1.3
type ResponseRepository interface {
// GetResponse retrieves a mock response for the given context.
// Parameters can include scenario ID, turn number, provider ID, etc.
// Returns the response text and any error encountered.
GetResponse(ctx context.Context, params ResponseParams) (string, error)
// GetTurn retrieves a mock turn response that may include tool calls.
// This extends GetResponse to support structured turn data with tool call simulation.
GetTurn(ctx context.Context, params ResponseParams) (*Turn, error)
}
ResponseRepository provides an interface for retrieving mock responses. This abstraction allows mock data to come from various sources (files, databases, etc.) and makes MockProvider reusable across different contexts (Arena, SDK examples, unit tests).
type ScenarioConfig ¶ added in v1.1.3
type ScenarioConfig struct {
// Default response for this scenario (overrides global default)
DefaultResponse string `yaml:"defaultResponse,omitempty"`
// Turn-specific responses keyed by turn number (1-indexed)
// Supports both simple string responses (backward compatibility) and structured Turn responses
Turns map[int]interface{} `yaml:"turns,omitempty"`
// Tool execution responses for repository-backed tool mocking
ToolResponses map[string][]ToolResponse `yaml:"tool_responses,omitempty"`
}
ScenarioConfig defines mock responses for a specific scenario.
type ToolCall ¶ added in v1.1.3
type ToolCall struct {
Name string `yaml:"name"` // Name of the tool to call
Arguments map[string]interface{} `yaml:"arguments"` // Arguments to pass to the tool
}
ToolCall represents a simulated tool call from the LLM.
type ToolError ¶ added in v1.1.3
type ToolError struct {
Type string `yaml:"type"` // Error type/category
Message string `yaml:"message"` // Error message
}
ToolError represents an error response for tool execution.
type ToolProvider ¶ added in v1.1.3
type ToolProvider struct {
*Provider
}
ToolProvider extends MockProvider to support tool/function calling. It implements the ToolSupport interface to enable tool call simulation while maintaining compatibility with the existing MockProvider API.
func NewToolProvider ¶ added in v1.1.3
func NewToolProvider(id, model string, includeRawOutput bool, additionalConfig map[string]interface{}) *ToolProvider
NewToolProvider creates a new mock provider with tool support. This uses default in-memory responses for backward compatibility.
func NewToolProviderWithRepository ¶ added in v1.1.3
func NewToolProviderWithRepository(id, model string, includeRawOutput bool, repo ResponseRepository) *ToolProvider
NewToolProviderWithRepository creates a mock provider with tool support using a custom response repository for advanced scenarios.
func (*ToolProvider) BuildTooling ¶ added in v1.1.3
func (m *ToolProvider) BuildTooling(descriptors []*providers.ToolDescriptor) (interface{}, error)
BuildTooling implements the ToolSupport interface. For mock providers, we just return the tools as-is since we don't need to transform them into a provider-specific format.
func (*ToolProvider) PredictWithTools ¶ added in v1.1.3
func (m *ToolProvider) PredictWithTools(ctx context.Context, req providers.PredictionRequest, tools interface{}, toolChoice string) (providers.PredictionResponse, []types.MessageToolCall, error)
PredictWithTools implements the ToolSupport interface. This method handles the initial predict request with tools available, potentially returning tool calls based on the mock configuration.
type ToolResponse ¶ added in v1.1.3
type ToolResponse struct {
CallArgs map[string]interface{} `yaml:"call_args"` // Match these arguments
Result interface{} `yaml:"result,omitempty"` // Return this result
Error *ToolError `yaml:"error,omitempty"` // Or return this error
}
MockToolResponse represents a configured response for tool execution.
type Turn ¶ added in v1.1.3
type Turn struct {
Type string `yaml:"type"` // "text", "tool_calls", or "multimodal"
Content string `yaml:"content,omitempty"` // Text content for the response
Parts []ContentPart `yaml:"parts,omitempty"` // Multimodal content parts (text, image, audio, video)
ToolCalls []ToolCall `yaml:"tool_calls,omitempty"` // Tool calls to simulate
}
Turn represents a structured mock response that may include tool calls and multimodal content. This extends simple text responses to support tool call simulation and multimodal content parts.
func (*Turn) ToContentParts ¶ added in v1.1.3
func (t *Turn) ToContentParts() []types.ContentPart
ToContentParts converts Turn to a slice of types.ContentPart. This handles both legacy text-only responses and new multimodal responses.