Documentation
¶
Overview ¶
Package mock provides mock provider implementation for testing and development.
Index ¶
- Constants
- 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 MockStreamSession
- func (m *MockStreamSession) Close() error
- func (m *MockStreamSession) Done() <-chan struct{}
- func (m *MockStreamSession) EmitChunk(chunk *providers.StreamChunk)
- func (m *MockStreamSession) EndInput()
- func (m *MockStreamSession) Error() error
- func (m *MockStreamSession) GetChunks() []*types.MediaChunk
- func (m *MockStreamSession) GetTexts() []string
- func (m *MockStreamSession) Response() <-chan providers.StreamChunk
- func (m *MockStreamSession) SendChunk(ctx context.Context, chunk *types.MediaChunk) error
- func (m *MockStreamSession) SendSystemContext(ctx context.Context, text string) error
- func (m *MockStreamSession) SendText(ctx context.Context, text string) error
- func (m *MockStreamSession) WithAutoRespond(text string) *MockStreamSession
- func (m *MockStreamSession) WithCloseAfterResponse(closeAfter bool) *MockStreamSession
- func (m *MockStreamSession) WithCloseAfterTurns(turns int, noResponse ...bool) *MockStreamSession
- func (m *MockStreamSession) WithError(err error) *MockStreamSession
- func (m *MockStreamSession) WithInterruptOnTurn(turnNumber int) *MockStreamSession
- func (m *MockStreamSession) WithResponseChunks(chunks []providers.StreamChunk) *MockStreamSession
- func (m *MockStreamSession) WithSendChunkError(err error) *MockStreamSession
- func (m *MockStreamSession) WithSendTextError(err error) *MockStreamSession
- 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 StreamingProvider
- func (p *StreamingProvider) CreateStreamSession(ctx context.Context, req *providers.StreamingInputConfig) (providers.StreamInputSession, error)
- func (p *StreamingProvider) GetSession() *MockStreamSession
- func (p *StreamingProvider) GetSessions() []*MockStreamSession
- func (p *StreamingProvider) GetStreamingCapabilities() providers.StreamingCapabilities
- func (p *StreamingProvider) SupportsStreamInput() []string
- func (p *StreamingProvider) WithAutoRespond(responseText string) *StreamingProvider
- func (p *StreamingProvider) WithCloseAfterTurns(turns int, noResponse ...bool) *StreamingProvider
- func (p *StreamingProvider) WithCreateSessionError(err error) *StreamingProvider
- func (p *StreamingProvider) WithInterruptOnTurn(turnNumber int) *StreamingProvider
- type ToolCall
- type ToolProvider
- func (m *ToolProvider) BuildTooling(descriptors []*providers.ToolDescriptor) (interface{}, error)
- func (m *ToolProvider) PredictStreamWithTools(ctx context.Context, req providers.PredictionRequest, tools interface{}, ...) (<-chan providers.StreamChunk, error)
- func (m *ToolProvider) PredictWithTools(ctx context.Context, req providers.PredictionRequest, tools interface{}, ...) (providers.PredictionResponse, []types.MessageToolCall, error)
- type Turn
- type VideoURL
Constants ¶
const (
// DefaultMockStreamingResponse is the default response text for auto-respond mode.
DefaultMockStreamingResponse = "Mock streaming response"
)
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"`
// Selfplay persona responses keyed by persona ID
// Used when generating user messages in selfplay mode
Selfplay map[string]ScenarioConfig `yaml:"selfplay,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.
For selfplay user turns (when ArenaRole == "self_play_user"), it looks up responses from the selfplay section using PersonaID. For regular turns, it uses scenario 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 MockStreamSession ¶ added in v1.1.6
type MockStreamSession struct {
// contains filtered or unexported fields
}
MockStreamSession implements providers.StreamInputSession for testing duplex scenarios.
func NewMockStreamSession ¶ added in v1.1.6
func NewMockStreamSession() *MockStreamSession
NewMockStreamSession creates a new mock stream session.
func (*MockStreamSession) Close ¶ added in v1.1.6
func (m *MockStreamSession) Close() error
Close implements StreamInputSession.Close.
func (*MockStreamSession) Done ¶ added in v1.1.6
func (m *MockStreamSession) Done() <-chan struct{}
Done implements StreamInputSession.Done.
func (*MockStreamSession) EmitChunk ¶ added in v1.1.6
func (m *MockStreamSession) EmitChunk(chunk *providers.StreamChunk)
EmitChunk sends a response chunk (for testing).
func (*MockStreamSession) EndInput ¶ added in v1.1.6
func (m *MockStreamSession) EndInput()
EndInput signals the end of input for the current turn. For mock sessions with auto-respond enabled, this triggers the response.
func (*MockStreamSession) Error ¶ added in v1.1.6
func (m *MockStreamSession) Error() error
Error implements StreamInputSession.Error.
func (*MockStreamSession) GetChunks ¶ added in v1.1.6
func (m *MockStreamSession) GetChunks() []*types.MediaChunk
GetChunks returns all received media chunks (for testing).
func (*MockStreamSession) GetTexts ¶ added in v1.1.6
func (m *MockStreamSession) GetTexts() []string
GetTexts returns all received text messages (for testing).
func (*MockStreamSession) Response ¶ added in v1.1.6
func (m *MockStreamSession) Response() <-chan providers.StreamChunk
Response implements StreamInputSession.Response.
func (*MockStreamSession) SendChunk ¶ added in v1.1.6
func (m *MockStreamSession) SendChunk(ctx context.Context, chunk *types.MediaChunk) error
SendChunk implements StreamInputSession.SendChunk.
func (*MockStreamSession) SendSystemContext ¶ added in v1.1.6
func (m *MockStreamSession) SendSystemContext(ctx context.Context, text string) error
SendSystemContext implements StreamInputSession.SendSystemContext. Unlike SendText, this does NOT trigger a response from the model.
func (*MockStreamSession) SendText ¶ added in v1.1.6
func (m *MockStreamSession) SendText(ctx context.Context, text string) error
SendText implements StreamInputSession.SendText.
func (*MockStreamSession) WithAutoRespond ¶ added in v1.1.6
func (m *MockStreamSession) WithAutoRespond(text string) *MockStreamSession
WithAutoRespond configures the session to automatically respond to inputs. The session stays open to handle multiple turns - call Close() when done.
func (*MockStreamSession) WithCloseAfterResponse ¶ added in v1.1.6
func (m *MockStreamSession) WithCloseAfterResponse(closeAfter bool) *MockStreamSession
WithCloseAfterResponse configures whether to close the response channel after auto-responding.
func (*MockStreamSession) WithCloseAfterTurns ¶ added in v1.1.6
func (m *MockStreamSession) WithCloseAfterTurns(turns int, noResponse ...bool) *MockStreamSession
WithCloseAfterTurns configures the session to close unexpectedly after N turns. This simulates Gemini dropping the connection mid-conversation. If noResponse is true, the session closes WITHOUT sending the final response (mimics Gemini closing after interrupted turnComplete).
func (*MockStreamSession) WithError ¶ added in v1.1.6
func (m *MockStreamSession) WithError(err error) *MockStreamSession
WithError sets the error returned by Error().
func (*MockStreamSession) WithInterruptOnTurn ¶ added in v1.1.6
func (m *MockStreamSession) WithInterruptOnTurn(turnNumber int) *MockStreamSession
WithInterruptOnTurn configures the session to simulate an interruption on a specific turn. This mimics Gemini detecting user speech while the model is responding. The turn is 1-indexed (first turn = 1).
func (*MockStreamSession) WithResponseChunks ¶ added in v1.1.6
func (m *MockStreamSession) WithResponseChunks(chunks []providers.StreamChunk) *MockStreamSession
WithResponseChunks configures custom response chunks to emit.
func (*MockStreamSession) WithSendChunkError ¶ added in v1.1.6
func (m *MockStreamSession) WithSendChunkError(err error) *MockStreamSession
WithSendChunkError configures SendChunk to return an error.
func (*MockStreamSession) WithSendTextError ¶ added in v1.1.6
func (m *MockStreamSession) WithSendTextError(err error) *MockStreamSession
WithSendTextError configures SendText to return an error.
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) Close ¶ added in v1.1.3
Close is a no-op for the mock provider. NOSONAR: Intentionally empty - mock provider has no resources to clean up
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
PersonaID string // Optional: ID of the persona for selfplay user responses
ArenaRole string // Optional: Role in arena (e.g., "self_play_user")
}
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"`
}
ScenarioConfig defines mock responses for a specific scenario.
type StreamingProvider ¶ added in v1.1.6
type StreamingProvider struct {
*Provider
// contains filtered or unexported fields
}
StreamingProvider extends Provider with StreamInputSupport for duplex testing.
func NewStreamingProvider ¶ added in v1.1.6
func NewStreamingProvider(id, model string, includeRawOutput bool) *StreamingProvider
NewStreamingProvider creates a mock provider with duplex streaming support.
func NewStreamingProviderWithRepository ¶ added in v1.1.6
func NewStreamingProviderWithRepository( id, model string, includeRawOutput bool, repo ResponseRepository, ) *StreamingProvider
NewStreamingProviderWithRepository creates a mock streaming provider with a custom repository.
func (*StreamingProvider) CreateStreamSession ¶ added in v1.1.6
func (p *StreamingProvider) CreateStreamSession( ctx context.Context, req *providers.StreamingInputConfig, ) (providers.StreamInputSession, error)
CreateStreamSession implements StreamInputSupport.CreateStreamSession.
func (*StreamingProvider) GetSession ¶ added in v1.1.6
func (p *StreamingProvider) GetSession() *MockStreamSession
GetSession returns the first/most recent mock session for testing access to sent chunks/texts. For multiple sessions, use GetSessions() instead.
func (*StreamingProvider) GetSessions ¶ added in v1.1.6
func (p *StreamingProvider) GetSessions() []*MockStreamSession
GetSessions returns all created sessions for testing.
func (*StreamingProvider) GetStreamingCapabilities ¶ added in v1.1.6
func (p *StreamingProvider) GetStreamingCapabilities() providers.StreamingCapabilities
GetStreamingCapabilities implements StreamInputSupport.GetStreamingCapabilities.
func (*StreamingProvider) SupportsStreamInput ¶ added in v1.1.6
func (p *StreamingProvider) SupportsStreamInput() []string
SupportsStreamInput implements StreamInputSupport.SupportsStreamInput.
func (*StreamingProvider) WithAutoRespond ¶ added in v1.1.6
func (p *StreamingProvider) WithAutoRespond(responseText string) *StreamingProvider
WithAutoRespond configures the provider to create sessions that auto-respond to inputs.
func (*StreamingProvider) WithCloseAfterTurns ¶ added in v1.1.6
func (p *StreamingProvider) WithCloseAfterTurns(turns int, noResponse ...bool) *StreamingProvider
WithCloseAfterTurns configures the provider to create sessions that close unexpectedly after N turns. This simulates Gemini dropping the connection. If noResponse is true, the session closes WITHOUT sending the final response.
func (*StreamingProvider) WithCreateSessionError ¶ added in v1.1.6
func (p *StreamingProvider) WithCreateSessionError(err error) *StreamingProvider
WithCreateSessionError configures CreateStreamSession to return an error.
func (*StreamingProvider) WithInterruptOnTurn ¶ added in v1.1.6
func (p *StreamingProvider) WithInterruptOnTurn(turnNumber int) *StreamingProvider
WithInterruptOnTurn configures the provider to create sessions that simulate an interruption on a specific turn. This mimics Gemini detecting user speech while the model is responding.
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 ToolProvider ¶ added in v1.1.3
type ToolProvider struct {
*StreamingProvider
}
ToolProvider extends MockProvider to support tool/function calling and duplex streaming. It implements the ToolSupport interface to enable tool call simulation while maintaining compatibility with the existing MockProvider API. By embedding StreamingProvider, it also supports StreamInputSupport for duplex scenarios.
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 and duplex streaming. 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 and duplex streaming 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) PredictStreamWithTools ¶ added in v1.1.5
func (m *ToolProvider) PredictStreamWithTools( ctx context.Context, req providers.PredictionRequest, tools interface{}, toolChoice string, ) (<-chan providers.StreamChunk, error)
PredictStreamWithTools performs a streaming predict request with tool support. For mock providers, this delegates to PredictWithTools and wraps the response in chunks.
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 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.