virtualmodel

package
v0.260411.2300-preview Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitIntoChunks

func SplitIntoChunks(content string) []string

SplitIntoChunks splits content into word-based chunks for streaming

Types

type DelayConfig

type DelayConfig struct {
	// Delay before the first SSE chunk is emitted (controls TTFT).
	MinFirstTokenDelayMs int
	MaxFirstTokenDelayMs int

	// Delay between the last content chunk and [DONE] (controls stream duration / TPS).
	MinEndDelayMs int
	MaxEndDelayMs int
}

DelayConfig configures the random delay ranges for a DelayProvider.

func DefaultDelayConfig

func DefaultDelayConfig() DelayConfig

DefaultDelayConfig returns sensible defaults: 50–500ms TTFT, 100–1000ms end delay.

type DelayProvider

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

DelayProvider is an embedded OpenAI-compatible HTTP server with configurable random delays. It accepts any chat completions request, streams the fixed response "I am testing and random sleep", and produces realistic TTFT / TPS / latency values for metrics E2E testing.

Use it as a typ.Provider in routing rules so requests flow through the full proxy pipeline (routing → OpenAI client → metrics tracking).

func NewDelayProvider

func NewDelayProvider() *DelayProvider

NewDelayProvider creates and starts a DelayProvider with default config.

func NewDelayProviderWithConfig

func NewDelayProviderWithConfig(cfg DelayConfig) *DelayProvider

NewDelayProviderWithConfig creates and starts a DelayProvider with a custom config.

func (*DelayProvider) Close

func (dp *DelayProvider) Close()

Close shuts down the embedded HTTP server.

func (*DelayProvider) Provider

func (dp *DelayProvider) Provider(name string) *typ.Provider

Provider returns a *typ.Provider configured to route to this delay server. name is used as both UUID and Name; it must be unique within the test config.

func (*DelayProvider) URL

func (dp *DelayProvider) URL() string

URL returns the base URL of the embedded server.

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 Registry

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

Registry manages virtual models

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new virtual model registry

func (*Registry) Clear

func (r *Registry) Clear()

Clear clears all registered models

func (*Registry) Get

func (r *Registry) Get(id string) *VirtualModel

Get retrieves a virtual model by ID

func (*Registry) List

func (r *Registry) List() []*VirtualModel

List returns all registered virtual models

func (*Registry) ListModels

func (r *Registry) ListModels() []Model

ListModels returns all registered models as Model slices

func (*Registry) Register

func (r *Registry) Register(vm *VirtualModel) error

Register registers a virtual model

func (*Registry) RegisterDefaults

func (r *Registry) RegisterDefaults()

RegisterDefaults registers default virtual models

func (*Registry) Unregister

func (r *Registry) Unregister(id string)

Unregister unregisters a virtual model

type ToolCallConfig

type ToolCallConfig struct {
	// Tool name (e.g., "ask_user_question", "web_search", "code_interpreter")
	Name string `json:"name" yaml:"name"`
	// Tool arguments as a map (will be serialized to JSON)
	// For ask_user_question: {"question": "...", "options": [...]}
	// For web_search: {"query": "..."}
	Arguments map[string]interface{} `json:"arguments" yaml:"arguments"`
}

ToolCallConfig defines a tool call to be returned by the virtual model This is a generic configuration that can represent any tool call

type VirtualModel

type VirtualModel struct {
	Config *VirtualModelConfig
}

VirtualModel represents a registered virtual model

func NewVirtualModel

func NewVirtualModel(cfg *VirtualModelConfig) *VirtualModel

NewVirtualModel creates a new virtual model

func (*VirtualModel) GetContent

func (vm *VirtualModel) GetContent() string

GetContent returns the response content

func (*VirtualModel) GetDelay

func (vm *VirtualModel) GetDelay() time.Duration

GetDelay returns the response delay

func (*VirtualModel) GetDelegateModel

func (vm *VirtualModel) GetDelegateModel() string

GetDelegateModel returns the delegate model for proxy mode

func (*VirtualModel) GetID

func (vm *VirtualModel) GetID() string

GetID returns the model ID

func (*VirtualModel) GetName

func (vm *VirtualModel) GetName() string

GetName returns the model name

func (*VirtualModel) GetStreamChunks

func (vm *VirtualModel) GetStreamChunks() []string

GetStreamChunks returns the streaming chunks

func (*VirtualModel) GetToolCall

func (vm *VirtualModel) GetToolCall() *ToolCallConfig

GetToolCall returns the tool call configuration

func (*VirtualModel) GetTransformer

func (vm *VirtualModel) GetTransformer() protocol.Transformer

GetTransformer returns the transformer for proxy mode

func (*VirtualModel) GetType

func (vm *VirtualModel) GetType() VirtualModelType

GetType returns the model type

func (*VirtualModel) IsProxy

func (vm *VirtualModel) IsProxy() bool

IsProxy returns true if this is a proxy model

func (*VirtualModel) IsStatic

func (vm *VirtualModel) IsStatic() bool

IsStatic returns true if this is a static model

func (*VirtualModel) IsTool

func (vm *VirtualModel) IsTool() bool

IsTool returns true if this is a tool-type model

func (*VirtualModel) ToModel

func (vm *VirtualModel) ToModel() Model

ToModel converts to Model type for API response

type VirtualModelConfig

type VirtualModelConfig struct {
	ID           string
	Name         string
	Description  string
	Type         VirtualModelType // "static", "tool", or "proxy"
	Content      string           // For static models
	Role         string
	FinishReason string
	Delay        time.Duration
	StreamChunks []string // For streaming: chunks to send

	// For tool-type models
	ToolCall *ToolCallConfig

	// For proxy-type models
	DelegateModel string               // Real model to delegate to (e.g., "claude-3-5-sonnet-20241022")
	Transformer   protocol.Transformer // Optional transformer for proxy mode
}

VirtualModelConfig holds the configuration for a virtual model

type VirtualModelType

type VirtualModelType string

VirtualModelType represents the type of virtual model

const (
	VirtualModelTypeStatic VirtualModelType = "static" // Original: fixed response
	VirtualModelTypeTool   VirtualModelType = "tool"   // Returns tool calls
	VirtualModelTypeProxy  VirtualModelType = "proxy"  // Proxy mode with transformer
)

Jump to

Keyboard shortcuts

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