mock

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 MockConfig structure with scenarios and turn-specific responses.

func (*FileMockRepository) GetResponse

func (r *FileMockRepository) GetResponse(ctx context.Context, params MockResponseParams) (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 MockResponseParams) (*MockTurn, error)

GetTurn retrieves a structured mock turn response that may include tool calls. This method supports both backward-compatible string responses and new structured MockTurn responses.

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 MockResponseParams) (string, error)

GetResponse retrieves a mock response based on the provided parameters.

func (*InMemoryMockRepository) GetTurn

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 MockAudioURL

type MockAudioURL struct {
	URL string `yaml:"url"` // URL to the audio file (can be mock://, http://, https://, data:, or file path)
}

MockAudioURL represents audio content in a mock response.

type MockConfig

type MockConfig struct {
	// Default response if no specific match is found
	DefaultResponse string `yaml:"defaultResponse"`

	// Scenario-specific responses keyed by scenario ID
	Scenarios map[string]ScenarioMockConfig `yaml:"scenarios,omitempty"`
}

MockConfig represents the structure of a mock configuration file. This allows scenario-specific and turn-specific responses to be defined.

type MockContentPart

type MockContentPart struct {
	Type     string                 `yaml:"type"`                // "text", "image", "audio", or "video"
	Text     string                 `yaml:"text,omitempty"`      // Text content (for type="text")
	ImageURL *MockImageURL          `yaml:"image_url,omitempty"` // Image URL (for type="image")
	AudioURL *MockAudioURL          `yaml:"audio_url,omitempty"` // Audio URL (for type="audio")
	VideoURL *MockVideoURL          `yaml:"video_url,omitempty"` // Video URL (for type="video")
	Metadata map[string]interface{} `yaml:"metadata,omitempty"`  // Additional metadata
}

MockContentPart represents a single content part in a multimodal mock response. This mirrors the structure of types.ContentPart but with YAML-friendly field names.

func (*MockContentPart) ToContentPart

func (m *MockContentPart) ToContentPart() *types.ContentPart

ToContentPart converts a MockContentPart to types.ContentPart.

type MockImageURL

type MockImageURL 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"
}

MockImageURL represents image content in a mock response.

type MockProvider

type MockProvider struct {
	// contains filtered or unexported fields
}

MockProvider 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).

MockProvider 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 NewMockProvider

func NewMockProvider(id, model string, includeRawOutput bool) *MockProvider

NewMockProvider creates a new mock provider with default in-memory responses. This constructor maintains backward compatibility with existing code.

func NewMockProviderWithRepository

func NewMockProviderWithRepository(id, model string, includeRawOutput bool, repo MockResponseRepository) *MockProvider

NewMockProviderWithRepository creates a mock provider with a custom response repository. This allows for advanced scenarios like file-based or database-backed mock responses.

func (*MockProvider) CalculateCost

func (m *MockProvider) CalculateCost(inputTokens, outputTokens, cachedTokens int) types.CostInfo

CalculateCost calculates cost breakdown for given token counts.

func (*MockProvider) Close

func (m *MockProvider) Close() error

Close is a no-op for the mock provider.

func (*MockProvider) ID

func (m *MockProvider) ID() string

ID returns the provider ID.

func (*MockProvider) Predict

Predict returns a mock response using the configured repository.

func (*MockProvider) PredictStream

func (m *MockProvider) PredictStream(ctx context.Context, req providers.PredictionRequest) (<-chan providers.StreamChunk, error)

PredictStream returns a mock streaming response using the configured repository.

func (*MockProvider) ShouldIncludeRawOutput

func (m *MockProvider) ShouldIncludeRawOutput() bool

ShouldIncludeRawOutput returns whether raw API responses should be included.

func (*MockProvider) SupportsStreaming

func (m *MockProvider) SupportsStreaming() bool

SupportsStreaming indicates whether the provider supports streaming.

type MockResponseParams

type MockResponseParams 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
}

MockResponseParams contains parameters for looking up mock responses. Different implementations may use different subsets of these fields.

type MockResponseRepository

type MockResponseRepository 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 MockResponseParams) (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 MockResponseParams) (*MockTurn, error)
}

MockResponseRepository 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 MockToolCall

type MockToolCall struct {
	Name      string                 `yaml:"name"`      // Name of the tool to call
	Arguments map[string]interface{} `yaml:"arguments"` // Arguments to pass to the tool
}

MockToolCall represents a simulated tool call from the LLM.

type MockToolError

type MockToolError struct {
	Type    string `yaml:"type"`    // Error type/category
	Message string `yaml:"message"` // Error message
}

MockToolError represents an error response for tool execution.

type MockToolProvider

type MockToolProvider struct {
	*MockProvider
}

MockToolProvider 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 NewMockToolProvider

func NewMockToolProvider(id, model string, includeRawOutput bool, additionalConfig map[string]interface{}) *MockToolProvider

NewMockToolProvider creates a new mock provider with tool support. This uses default in-memory responses for backward compatibility.

func NewMockToolProviderWithRepository

func NewMockToolProviderWithRepository(id, model string, includeRawOutput bool, repo MockResponseRepository) *MockToolProvider

NewMockToolProviderWithRepository creates a mock provider with tool support using a custom response repository for advanced scenarios.

func (*MockToolProvider) BuildTooling

func (m *MockToolProvider) 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 (*MockToolProvider) PredictWithTools

func (m *MockToolProvider) 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 MockToolResponse

type MockToolResponse struct {
	CallArgs map[string]interface{} `yaml:"call_args"`        // Match these arguments
	Result   interface{}            `yaml:"result,omitempty"` // Return this result
	Error    *MockToolError         `yaml:"error,omitempty"`  // Or return this error
}

MockToolResponse represents a configured response for tool execution.

type MockTurn

type MockTurn struct {
	Type      string            `yaml:"type"`                 // "text", "tool_calls", or "multimodal"
	Content   string            `yaml:"content,omitempty"`    // Text content for the response
	Parts     []MockContentPart `yaml:"parts,omitempty"`      // Multimodal content parts (text, image, audio, video)
	ToolCalls []MockToolCall    `yaml:"tool_calls,omitempty"` // Tool calls to simulate
}

MockTurn 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 (*MockTurn) ToContentParts

func (t *MockTurn) ToContentParts() []types.ContentPart

ToContentParts converts MockTurn to a slice of types.ContentPart. This handles both legacy text-only responses and new multimodal responses.

type MockVideoURL

type MockVideoURL struct {
	URL string `yaml:"url"` // URL to the video file (can be mock://, http://, https://, data:, or file path)
}

MockVideoURL represents video content in a mock response.

type ScenarioMockConfig

type ScenarioMockConfig 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 MockTurn responses
	Turns map[int]interface{} `yaml:"turns,omitempty"`

	// Tool execution responses for repository-backed tool mocking
	ToolResponses map[string][]MockToolResponse `yaml:"tool_responses,omitempty"`
}

ScenarioMockConfig defines mock responses for a specific scenario.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL