virtualmodel

package
v0.260224.1130 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MPL-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 ChatCompletionRequest

type ChatCompletionRequest struct {
	Messages    []Message `json:"messages"`
	Model       string    `json:"model"`
	Temperature *float64  `json:"temperature,omitempty"`
	MaxTokens   *int      `json:"max_tokens,omitempty"`
	Stream      bool      `json:"stream,omitempty"`
}

ChatCompletionRequest represents an OpenAI-compatible chat completion request

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int64    `json:"created"`
	Model   string   `json:"model"`
	Choices []Choice `json:"choices"`
	Usage   Usage    `json:"usage"`
}

ChatCompletionResponse represents an OpenAI-compatible chat completion response

type ChatCompletionStreamResponse

type ChatCompletionStreamResponse struct {
	ID      string         `json:"id"`
	Object  string         `json:"object"`
	Created int64          `json:"created"`
	Model   string         `json:"model"`
	Choices []StreamChoice `json:"choices"`
}

ChatCompletionStreamResponse represents a streaming chunk in OpenAI format

type Choice

type Choice struct {
	Index        int     `json:"index"`
	Message      Message `json:"message"`
	FinishReason string  `json:"finish_reason"`
}

Choice represents a choice in the response

type Delta

type Delta struct {
	Role    string `json:"role,omitempty"`
	Content string `json:"content,omitempty"`
}

Delta represents the delta in a streaming response

type Handler

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

Handler handles HTTP requests for virtual models

func NewHandler

func NewHandler(registry *Registry) *Handler

NewHandler creates a new virtual model handler

func (*Handler) ChatCompletions

func (h *Handler) ChatCompletions(c *gin.Context)

ChatCompletions handles the POST /virtual/v1/chat/completions endpoint

func (*Handler) ListModels

func (h *Handler) ListModels(c *gin.Context)

ListModels handles the GET /virtual/v1/models endpoint

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message represents a chat message

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 OpenAIModelsResponse

type OpenAIModelsResponse struct {
	Object string  `json:"object"`
	Data   []Model `json:"data"`
}

OpenAIModelsResponse represents OpenAI's models API response 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 Service

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

Service manages the virtual model service

func NewService

func NewService() *Service

NewService creates a new virtual model service

func (*Service) GetHandler

func (s *Service) GetHandler() *Handler

GetHandler returns the HTTP handler

func (*Service) GetModel

func (s *Service) GetModel(id string) *VirtualModel

GetModel retrieves a virtual model by ID

func (*Service) GetRegistry

func (s *Service) GetRegistry() *Registry

GetRegistry returns the model registry

func (*Service) ListModels

func (s *Service) ListModels() []Model

ListModels returns all registered models

func (*Service) RegisterModel

func (s *Service) RegisterModel(vm *VirtualModel) error

RegisterModel registers a new virtual model

func (*Service) SetupRoutes

func (s *Service) SetupRoutes(group *gin.RouterGroup)

SetupRoutes sets up the virtual model routes on a Gin router group

func (*Service) UnregisterModel

func (s *Service) UnregisterModel(id string)

UnregisterModel unregisters a virtual model

type StreamChoice

type StreamChoice struct {
	Index        int     `json:"index"`
	Delta        Delta   `json:"delta"`
	FinishReason *string `json:"finish_reason"`
}

StreamChoice represents a choice in a streaming response

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Usage represents token usage information

type VirtualModel

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

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) 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) 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
	Content      string
	Role         string
	FinishReason string
	Delay        time.Duration
	StreamChunks []string // For streaming: chunks to send
}

VirtualModelConfig holds the configuration for a virtual model

Jump to

Keyboard shortcuts

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