Documentation
¶
Overview ¶
Package virtualserver provides the HTTP handler for virtual model endpoints. It serves OpenAI Chat and Anthropic Messages API formats backed by a virtualmodel.Registry of deterministic VirtualModel instances.
Index ¶
- type AnthropicContent
- type AnthropicDelta
- type AnthropicMessage
- type AnthropicMessageRequest
- type AnthropicMessageResponse
- type AnthropicStreamEvent
- type AnthropicTool
- type AnthropicUsage
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionStreamResponse
- type Choice
- type Delta
- type FunctionCall
- type Handler
- type Message
- type OpenAIModelsResponse
- type Service
- func (s *Service) GetHandler() *Handler
- func (s *Service) GetModel(id string) virtualmodel.VirtualModel
- func (s *Service) GetRegistry() *virtualmodel.Registry
- func (s *Service) ListModels() []virtualmodel.Model
- func (s *Service) RegisterModel(vm virtualmodel.VirtualModel) error
- func (s *Service) SetupRoutes(group *gin.RouterGroup)
- func (s *Service) UnregisterModel(id string)
- type StreamChoice
- type ToolCall
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnthropicContent ¶
type AnthropicContent struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
}
AnthropicContent is a content block in an Anthropic response.
type AnthropicDelta ¶
type AnthropicDelta struct {
Type string `json:"type,omitempty"`
Text string `json:"text,omitempty"`
StopReason string `json:"stop_reason,omitempty"`
}
AnthropicDelta is a delta in an Anthropic streaming response.
type AnthropicMessage ¶
type AnthropicMessage = anthropic.BetaMessageParam
Request types aliased from protocol / Anthropic SDK
type AnthropicMessageRequest ¶
type AnthropicMessageRequest = protocol.AnthropicBetaMessagesRequest
Request types aliased from protocol / Anthropic SDK
type AnthropicMessageResponse ¶
type AnthropicMessageResponse struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role"`
Model string `json:"model"`
Content []AnthropicContent `json:"content"`
StopReason string `json:"stop_reason"`
Usage AnthropicUsage `json:"usage"`
}
AnthropicMessageResponse is an Anthropic-compatible message response.
type AnthropicStreamEvent ¶
type AnthropicStreamEvent struct {
Type string `json:"type"`
Message *AnthropicMessageResponse `json:"message,omitempty"`
Index int `json:"index,omitempty"`
Delta *AnthropicDelta `json:"delta,omitempty"`
Usage *AnthropicUsage `json:"usage,omitempty"`
}
AnthropicStreamEvent is a streaming event in Anthropic format.
type AnthropicTool ¶
type AnthropicTool = anthropic.BetaToolParam
Request types aliased from protocol / Anthropic SDK
type AnthropicUsage ¶
type AnthropicUsage struct {
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
}
AnthropicUsage holds token usage in Anthropic format.
type ChatCompletionRequest ¶
type ChatCompletionRequest = protocol.OpenAIChatCompletionRequest
ChatCompletionRequest is an OpenAI-compatible chat completion request.
type ChatCompletionResponse ¶
type ChatCompletionResponse = openai.ChatCompletion
Response types aliased from OpenAI SDK
type ChatCompletionStreamResponse ¶
type ChatCompletionStreamResponse = openai.ChatCompletionChunk
Response types aliased from OpenAI SDK
type Delta ¶
type Delta = openai.ChatCompletionChunkChoiceDelta
Response types aliased from OpenAI SDK
type FunctionCall ¶
type FunctionCall = openai.ChatCompletionMessageFunctionToolCallFunction
Response types aliased from OpenAI SDK
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for virtual model endpoints.
func NewHandler ¶
func NewHandler(registry *virtualmodel.Registry) *Handler
NewHandler creates a new Handler backed by the given registry.
func (*Handler) ChatCompletions ¶
ChatCompletions handles POST /virtual/v1/chat/completions.
func (*Handler) ListModels ¶
ListModels handles GET /virtual/v1/models.
type OpenAIModelsResponse ¶
type OpenAIModelsResponse struct {
Object string `json:"object"`
Data []virtualmodel.Model `json:"data"`
}
OpenAIModelsResponse is the OpenAI models list response format.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages the virtual model service.
func NewService ¶
func NewService() *Service
NewService creates a fully initialized Service with default models registered.
func (*Service) GetHandler ¶
GetHandler returns the HTTP handler.
func (*Service) GetModel ¶
func (s *Service) GetModel(id string) virtualmodel.VirtualModel
GetModel retrieves a virtual model by ID.
func (*Service) GetRegistry ¶
func (s *Service) GetRegistry() *virtualmodel.Registry
GetRegistry returns the model registry.
func (*Service) ListModels ¶
func (s *Service) ListModels() []virtualmodel.Model
ListModels returns all registered models.
func (*Service) RegisterModel ¶
func (s *Service) RegisterModel(vm virtualmodel.VirtualModel) error
RegisterModel registers a new virtual model.
func (*Service) SetupRoutes ¶
func (s *Service) SetupRoutes(group *gin.RouterGroup)
SetupRoutes sets up virtual model routes on a Gin router group.
func (*Service) UnregisterModel ¶
UnregisterModel unregisters a virtual model.
type StreamChoice ¶
type StreamChoice = openai.ChatCompletionChunkChoice
Response types aliased from OpenAI SDK
type ToolCall ¶
type ToolCall = openai.ChatCompletionMessageFunctionToolCall
Response types aliased from OpenAI SDK