Documentation
¶
Overview ¶
Package virtualmodel defines the protocol-agnostic primitives for virtual models. Concrete provider-specific implementations and registries live in the anthropic and openai sub-packages — this top-level package contains only the base interface and shared value types.
These primitives back the production /virtual/v1/* endpoint (onboarding, demos, dry-runs without a real upstream provider) and are also reused as an in-process LLM substitute by test packages such as server_validate and protocol_validate. The production endpoint is the package's primary surface; test consumers are secondary and use GenericRegistry directly rather than RegisterDefaults — see README.md "Positioning & registration discipline".
Index ¶
- Constants
- func EmitChunks(chunks []string, perChunkDelay time.Duration, ...)
- func ResolveChunkDelay(totalDelay time.Duration, chunkCount int) time.Duration
- func ToolCallDisplayContent(args map[string]interface{}) string
- type BaseMockModel
- type GenericRegistry
- func (r *GenericRegistry[T]) Clear()
- func (r *GenericRegistry[T]) Get(id string) T
- func (r *GenericRegistry[T]) Has(id string) bool
- func (r *GenericRegistry[T]) List() []T
- func (r *GenericRegistry[T]) ListModels() []Model
- func (r *GenericRegistry[T]) Register(vm T) error
- func (r *GenericRegistry[T]) Unregister(id string)
- type Model
- type SharedMockSpec
- type ToolCallConfig
- type VirtualModel
- type VirtualModelType
Constants ¶
const DefaultMockDescription = "A virtual model that returns fixed responses for testing"
DefaultMockDescription is the description returned by mock virtual models when their config does not provide an explicit one.
const DefaultMockOwnedBy = "tingly-box-virtual"
DefaultMockOwnedBy is the OwnedBy value reported by every built-in mock virtual model in the OpenAI-compatible models list.
const DefaultStreamChunkDelay = 50 * time.Millisecond
DefaultStreamChunkDelay is the per-chunk sleep used by stream helpers when no explicit total simulated delay is configured.
Variables ¶
This section is empty.
Functions ¶
func EmitChunks ¶ added in v0.260507.1
EmitChunks invokes emit for every chunk in order, sleeping perChunkDelay before each emission. It is the protocol-neutral inner loop shared by mock streams. Callers construct their own protocol-specific event types inside the emit closure.
func ResolveChunkDelay ¶ added in v0.260507.1
ResolveChunkDelay computes the per-chunk sleep duration for a stream.
- if totalDelay > 0 and chunkCount > 0 → totalDelay / chunkCount
- otherwise → DefaultStreamChunkDelay
This is the shared latency-distribution rule used by all mock streams across protocols.
func ToolCallDisplayContent ¶ added in v0.260414.2000
ToolCallDisplayContent extracts display text from tool call arguments. It checks for "message" and "question" keys, returning the first non-empty value found.
Types ¶
type BaseMockModel ¶ added in v0.260507.1
type BaseMockModel struct {
ID string
Name string
Description string
Type VirtualModelType
Delay time.Duration
}
BaseMockModel is the protocol-neutral half of an in-memory mock virtual model. Protocol-specific mocks embed it and only need to add their own Handle*/Handle*Stream methods. All identity / metadata methods of the VirtualModel interface live here.
func (*BaseMockModel) GetDescription ¶ added in v0.260507.1
func (b *BaseMockModel) GetDescription() string
func (*BaseMockModel) GetID ¶ added in v0.260507.1
func (b *BaseMockModel) GetID() string
func (*BaseMockModel) GetName ¶ added in v0.260507.1
func (b *BaseMockModel) GetName() string
func (*BaseMockModel) GetType ¶ added in v0.260507.1
func (b *BaseMockModel) GetType() VirtualModelType
func (*BaseMockModel) SimulatedDelay ¶ added in v0.260507.1
func (b *BaseMockModel) SimulatedDelay() time.Duration
func (*BaseMockModel) ToModel ¶ added in v0.260507.1
func (b *BaseMockModel) ToModel() Model
ToModel returns the OpenAI-compatible models-list entry for this mock.
type GenericRegistry ¶ added in v0.260507.1
type GenericRegistry[T VirtualModel] struct { // contains filtered or unexported fields }
GenericRegistry is a thread-safe registry of virtual models indexed by ID, parameterised by a protocol-specific VirtualModel sub-interface T. Each protocol sub-package (anthropic, openai, ...) instantiates its own Registry alias so models cannot leak across protocols.
func NewGenericRegistry ¶ added in v0.260507.1
func NewGenericRegistry[T VirtualModel]() *GenericRegistry[T]
NewGenericRegistry creates an empty registry.
func (*GenericRegistry[T]) Clear ¶ added in v0.260507.1
func (r *GenericRegistry[T]) Clear()
Clear removes all registered models.
func (*GenericRegistry[T]) Get ¶ added in v0.260507.1
func (r *GenericRegistry[T]) Get(id string) T
Get returns the virtual model for id, or the zero value of T if not registered.
func (*GenericRegistry[T]) Has ¶ added in v0.260507.1
func (r *GenericRegistry[T]) Has(id string) bool
Has reports whether a model with the given ID is registered.
func (*GenericRegistry[T]) List ¶ added in v0.260507.1
func (r *GenericRegistry[T]) List() []T
List returns all registered virtual models.
func (*GenericRegistry[T]) ListModels ¶ added in v0.260507.1
func (r *GenericRegistry[T]) ListModels() []Model
ListModels returns all registered models in the OpenAI-compatible Model format.
func (*GenericRegistry[T]) Register ¶ added in v0.260507.1
func (r *GenericRegistry[T]) Register(vm T) error
Register adds a virtual model. Returns an error if the ID is already taken.
func (*GenericRegistry[T]) Unregister ¶ added in v0.260507.1
func (r *GenericRegistry[T]) Unregister(id string)
Unregister removes a virtual model by ID. No-op if not present.
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 virtual model in the models list (OpenAI-compatible format).
type SharedMockSpec ¶ added in v0.260507.1
type SharedMockSpec struct {
}
SharedMockSpec describes a built-in mock that is identical across protocols (anthropic + openai). Each protocol's RegisterDefaults converts a SharedMockSpec into its own protocol-specific MockModelConfig.
Entries returned by SharedDefaultMocks are user-facing demo defaults: they are mounted into the production /virtual/v1/* endpoint and visible to end users via the virtual provider. Test-only fixtures must NOT be added here; tests should build their own GenericRegistry rather than pollute the production defaults set.
func SharedDefaultMocks ¶ added in v0.260507.1
func SharedDefaultMocks() []SharedMockSpec
SharedDefaultMocks returns the mocks registered by BOTH the Anthropic and OpenAI default registries. Per-protocol unique entries (e.g. virtual-claude-3 for Anthropic, virtual-gpt-4 for OpenAI, the compact transforms) live in their respective sub-packages.
type ToolCallConfig ¶
type ToolCallConfig struct {
Name string `json:"name" yaml:"name"`
Arguments map[string]interface{} `json:"arguments" yaml:"arguments"`
}
ToolCallConfig defines a tool call to be returned by the virtual model.
type VirtualModel ¶
type VirtualModel interface {
GetID() string
GetName() string
GetDescription() string
GetType() VirtualModelType
SimulatedDelay() time.Duration
ToModel() Model
}
VirtualModel is the base interface common to all virtual model types. Provider-specific extensions are defined in the anthropic and openai sub-packages, each adding the Handle methods for that protocol.
type VirtualModelType ¶
type VirtualModelType string
VirtualModelType represents the type/category of a virtual model.
const ( // VirtualModelTypeStatic represents static mock models that return fixed responses. VirtualModelTypeStatic VirtualModelType = "static" // VirtualModelTypeProxy represents proxy/transform models that modify requests before forwarding. VirtualModelTypeProxy VirtualModelType = "proxy" // VirtualModelTypeTool represents tool models that return tool_use blocks. VirtualModelTypeTool VirtualModelType = "tool" )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package anthropic provides Anthropic-protocol virtual models.
|
Package anthropic provides Anthropic-protocol virtual models. |
|
Package benchmark provides a load-testing client and an in-process server factory for the virtualmodel HTTP service.
|
Package benchmark provides a load-testing client and an in-process server factory for the virtualmodel HTTP service. |
|
examples/client
command
Stand-alone benchmark client driver: starts an in-process LocalServer (vmodel-backed) and drives it with the BenchmarkClient against both the OpenAI Chat and Anthropic Messages routes, printing a metrics summary.
|
Stand-alone benchmark client driver: starts an in-process LocalServer (vmodel-backed) and drives it with the BenchmarkClient against both the OpenAI Chat and Anthropic Messages routes, printing a metrics summary. |
|
examples/server
command
Stand-alone benchmark mock server: starts a local HTTP server backed by the production virtualmodel registries (with their default mock models pre-registered) so external benchmark drivers can hit a realistic vmodel surface over loopback.
|
Stand-alone benchmark mock server: starts a local HTTP server backed by the production virtualmodel registries (with their default mock models pre-registered) so external benchmark drivers can hit a realistic vmodel surface over loopback. |
|
Package openai provides OpenAI-protocol virtual models.
|
Package openai provides OpenAI-protocol virtual models. |
|
Package virtualserver provides the HTTP handler for virtual model endpoints.
|
Package virtualserver provides the HTTP handler for virtual model endpoints. |