app

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Credentials   []config.Credential
	VendorModels  []config.VendorModel
	APIClient     *proxy.APIClient
	ModelSelector selector.Selector
	APIHandlers   *handlers.APIHandlers
}

App centralizes the application's dependencies and configuration

func NewApp

func NewApp() (*App, error)

NewApp creates a new App instance with all dependencies

func (*App) SetupRoutes

func (a *App) SetupRoutes() http.Handler

SetupRoutes configures all routes for the application

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Messages []Message `json:"messages" example:"[]"`
	Model    string    `json:"model" example:"gpt-4o"`
	Stream   bool      `json:"stream,omitempty" example:"false"`
	// Added OpenAI-compatible fields
	MaxTokens        int                  `json:"max_tokens,omitempty" example:"100"`
	Temperature      float64              `json:"temperature,omitempty" example:"0.7"`
	TopP             float64              `json:"top_p,omitempty" example:"1"`
	N                int                  `json:"n,omitempty" example:"1"`
	Stop             []string             `json:"stop,omitempty"`
	PresencePenalty  float64              `json:"presence_penalty,omitempty" example:"0"`
	FrequencyPenalty float64              `json:"frequency_penalty,omitempty" example:"0"`
	LogitBias        map[string]float64   `json:"logit_bias,omitempty"`
	User             string               `json:"user,omitempty" example:"user-123"`
	Functions        []FunctionDefinition `json:"functions,omitempty"`
	FunctionCall     string               `json:"function_call,omitempty" example:"auto"`
	Tools            []Tool               `json:"tools,omitempty"`
	ToolChoice       string               `json:"tool_choice,omitempty" example:"auto"`
	ResponseFormat   map[string]string    `json:"response_format,omitempty"`
}

ChatCompletionRequest represents a request to the chat completions API

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID                string   `json:"id" example:"chatcmpl-abc123"`
	Object            string   `json:"object" example:"chat.completion"`
	Created           int64    `json:"created" example:"1677652288"`
	Model             string   `json:"model" example:"gpt-4o"`
	SystemFingerprint string   `json:"system_fingerprint,omitempty" example:"fp_abc123"`
	Choices           []Choice `json:"choices"`
	Usage             Usage    `json:"usage"`
	ServiceTier       string   `json:"service_tier,omitempty" example:"default"`
}

ChatCompletionResponse represents a response from the chat completions API

type Choice

type Choice struct {
	Index        int     `json:"index" example:"0"`
	Message      Message `json:"message"`
	LogProbs     string  `json:"logprobs" example:"null"`
	FinishReason string  `json:"finish_reason" example:"stop"`
}

Choice represents a completion choice

type ErrorInfo

type ErrorInfo struct {
	Message string `json:"message" example:"Invalid model specified"`
	Type    string `json:"type" example:"invalid_request_error"`
	Param   string `json:"param" example:"model"`
	Code    string `json:"code,omitempty" example:"invalid_model"`
}

ErrorInfo contains details about an error

type ErrorResponse

type ErrorResponse struct {
	Error ErrorInfo `json:"error"`
}

ErrorResponse represents an error response

type FunctionDefinition

type FunctionDefinition struct {
	Name        string                 `json:"name" example:"get_weather"`
	Description string                 `json:"description,omitempty" example:"Get the current weather in a location"`
	Parameters  map[string]interface{} `json:"parameters,omitempty"`
}

FunctionDefinition represents an available function definition

type Message

type Message struct {
	Role       string     `json:"role" example:"user"`
	Content    string     `json:"content" example:"Hello, how are you?"`
	Name       string     `json:"name,omitempty" example:"John"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
	ToolCallID string     `json:"tool_call_id,omitempty"`
}

Message represents a chat message

type Model

type Model struct {
	ID      string `json:"id" example:"gpt-4o"`
	Object  string `json:"object" example:"model"`
	Created int64  `json:"created" example:"1677610602"`
	OwnedBy string `json:"owned_by" example:"openai"`
}

Model represents a language model

type ModelsResponse

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

ModelsResponse represents the response from the models endpoint

type TokenDetails

type TokenDetails struct {
	CachedTokens             int `json:"cached_tokens" example:"0"`
	AudioTokens              int `json:"audio_tokens" example:"0"`
	ReasoningTokens          int `json:"reasoning_tokens,omitempty" example:"0"`
	AcceptedPredictionTokens int `json:"accepted_prediction_tokens,omitempty" example:"0"`
	RejectedPredictionTokens int `json:"rejected_prediction_tokens,omitempty" example:"0"`
}

TokenDetails represents detailed token usage information

type Tool

type Tool struct {
	Type     string                 `json:"type" example:"function"`
	Function map[string]interface{} `json:"function,omitempty"`
}

Tool represents a tool available to the model

type ToolCall

type ToolCall struct {
	ID       string                 `json:"id" example:"call_8qty38"`
	Type     string                 `json:"type" example:"function"`
	Function map[string]interface{} `json:"function"`
}

ToolCall represents a call to a tool

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens" example:"10"`
	CompletionTokens int `json:"completion_tokens" example:"20"`
	TotalTokens      int `json:"total_tokens" example:"30"`
	// Added additional usage details for OpenAI compatibility
	PromptTokensDetails     TokenDetails `json:"prompt_tokens_details"`
	CompletionTokensDetails TokenDetails `json:"completion_tokens_details"`
}

Usage represents token usage information

Jump to

Keyboard shortcuts

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