controller

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OneAPIOpenAI = iota + 1
	OneAPIAPI2D
	OneAPIAzure
	OneAPICloseAI
	OneAPIOpenAISB
	OneAPIOpenAIMax
	OneAPIOhMyGPT
	OneAPICustom
	OneAPIAils
	OneAPIAIProxy
	OneAPIPaLM
	OneAPIAPI2GPT
	OneAPIAIGC2D
	OneAPIAnthropic
	OneAPIBaidu
	OneAPIZhipu
	OneAPIAli
	OneAPIXunfei
	OneAPIAI360
	OneAPIOpenRouter
	OneAPIAIProxyLibrary
	OneAPIFastGPT
	OneAPITencent
	OneAPIGemini
	OneAPIMoonshot
	OneAPIBaichuan
	OneAPIMinimax
	OneAPIMistral
	OneAPIGroq
	OneAPIOllama
	OneAPILingYiWanWu
	OneAPIStepFun
	OneAPIAwsClaude
	OneAPICoze
	OneAPICohere
	OneAPIDeepSeek
	OneAPICloudflare
	OneAPIDeepL
	OneAPITogetherAI
	OneAPIDoubao
	OneAPINovita
	OneAPIVertextAI
	OneAPIProxy
	OneAPISiliconFlow
	OneAPIXAI
	OneAPIReplicate
	OneAPIBaiduV2
	OneAPIXunfeiV2
	OneAPIAliBailian
	OneAPIOpenAICompatible
	OneAPIGeminiOpenAICompatible
)

https://github.com/songquanpeng/one-api/blob/main/relay/channeltype/define.go

Variables

View Source
var (
	ErrChannelsNotFound  = errors.New("channels not found")
	ErrChannelsExhausted = errors.New("channels exhausted")
)

Functions

func AddChannel

func AddChannel(c *gin.Context)

func AddChannels

func AddChannels(c *gin.Context)

func AddGroupToken

func AddGroupToken(c *gin.Context)

func AddOneAPIChannel

func AddOneAPIChannel(ch OneAPIChannel) error

func AutoTestBannedModels

func AutoTestBannedModels()

func BuiltinModels

func BuiltinModels(c *gin.Context)

func ChannelBuiltinModels

func ChannelBuiltinModels(c *gin.Context)

func ChannelBuiltinModelsByType

func ChannelBuiltinModelsByType(c *gin.Context)

func ChannelDefaultModelsAndMapping

func ChannelDefaultModelsAndMapping(c *gin.Context)

func ChannelDefaultModelsAndMappingByType

func ChannelDefaultModelsAndMappingByType(c *gin.Context)

func ChannelEnabledModels

func ChannelEnabledModels(c *gin.Context)

func ChannelEnabledModelsByType

func ChannelEnabledModelsByType(c *gin.Context)

func ChannelTypeMetas

func ChannelTypeMetas(c *gin.Context)

func ChannelTypeNames

func ChannelTypeNames(c *gin.Context)

func ClearAllModelErrors

func ClearAllModelErrors(c *gin.Context)

func ClearChannelAllModelErrors

func ClearChannelAllModelErrors(c *gin.Context)

func ClearChannelModelErrors

func ClearChannelModelErrors(c *gin.Context)

func CreateGroup

func CreateGroup(c *gin.Context)

func DeleteChannel

func DeleteChannel(c *gin.Context)

func DeleteChannels

func DeleteChannels(c *gin.Context)

func DeleteGroup

func DeleteGroup(c *gin.Context)

func DeleteGroupToken

func DeleteGroupToken(c *gin.Context)

func DeleteGroupTokens

func DeleteGroupTokens(c *gin.Context)

func DeleteGroups

func DeleteGroups(c *gin.Context)

func DeleteHistoryLogs

func DeleteHistoryLogs(c *gin.Context)

func DeleteModelConfig

func DeleteModelConfig(c *gin.Context)

func DeleteModelConfigs

func DeleteModelConfigs(c *gin.Context)

func DeleteToken

func DeleteToken(c *gin.Context)

Delete handlers

func DeleteTokens

func DeleteTokens(c *gin.Context)

func EnabledModels

func EnabledModels(c *gin.Context)

func GetAllBannedModelChannels

func GetAllBannedModelChannels(c *gin.Context)

func GetAllChannelModelErrorRates

func GetAllChannelModelErrorRates(c *gin.Context)

func GetAllChannels

func GetAllChannels(c *gin.Context)

func GetAllModelConfigs

func GetAllModelConfigs(c *gin.Context)

func GetChannel

func GetChannel(c *gin.Context)

func GetChannelModelErrorRates

func GetChannelModelErrorRates(c *gin.Context)

func GetChannels

func GetChannels(c *gin.Context)

func GetDashboard

func GetDashboard(c *gin.Context)

func GetGroup

func GetGroup(c *gin.Context)

func GetGroupDashboard

func GetGroupDashboard(c *gin.Context)

func GetGroupDashboardModels

func GetGroupDashboardModels(c *gin.Context)

func GetGroupLogDetail

func GetGroupLogDetail(c *gin.Context)

func GetGroupLogs

func GetGroupLogs(c *gin.Context)

func GetGroupModelCostRank

func GetGroupModelCostRank(c *gin.Context)

func GetGroupToken

func GetGroupToken(c *gin.Context)

func GetGroupTokens

func GetGroupTokens(c *gin.Context)

func GetGroupUsedModels

func GetGroupUsedModels(c *gin.Context)

func GetGroupUsedTokenNames

func GetGroupUsedTokenNames(c *gin.Context)

func GetGroups

func GetGroups(c *gin.Context)

func GetLogDetail

func GetLogDetail(c *gin.Context)

func GetLogs

func GetLogs(c *gin.Context)

Handler functions

func GetModelConfig

func GetModelConfig(c *gin.Context)

func GetModelConfigs

func GetModelConfigs(c *gin.Context)

func GetModelConfigsByModelsContains

func GetModelConfigsByModelsContains(c *gin.Context)

func GetModelCostRank

func GetModelCostRank(c *gin.Context)

func GetModelsErrorRate

func GetModelsErrorRate(c *gin.Context)

func GetOption

func GetOption(c *gin.Context)

func GetOptions

func GetOptions(c *gin.Context)

func GetRandomChannel

func GetRandomChannel(c *dbmodel.ModelCaches, model string, errorRates map[int64]float64, ignoreChannel ...int64) (*dbmodel.Channel, error)

func GetStatus

func GetStatus(c *gin.Context)

func GetSubscription

func GetSubscription(c *gin.Context)

subscription

func GetToken

func GetToken(c *gin.Context)

Single token handlers

func GetTokens

func GetTokens(c *gin.Context)

Token list handlers

func GetUsage

func GetUsage(c *gin.Context)

func GetUsedModels

func GetUsedModels(c *gin.Context)

func ImportChannelFromOneAPI

func ImportChannelFromOneAPI(c *gin.Context)

func ListModels

func ListModels(c *gin.Context)

func NewRelay

func NewRelay(mode relaymode.Mode) func(c *gin.Context)

func RelayHelper

func RelayHelper(meta *meta.Meta, c *gin.Context, relayController RelayController) (*controller.HandleResult, bool)

func RelayNotImplemented

func RelayNotImplemented(c *gin.Context)

func RetrieveModel

func RetrieveModel(c *gin.Context)

func SaveModelConfig

func SaveModelConfig(c *gin.Context)

func SaveModelConfigs

func SaveModelConfigs(c *gin.Context)

func SearchChannels

func SearchChannels(c *gin.Context)

func SearchConsumeError

func SearchConsumeError(c *gin.Context)

func SearchGroupLogs

func SearchGroupLogs(c *gin.Context)

func SearchGroupTokens

func SearchGroupTokens(c *gin.Context)

func SearchGroups

func SearchGroups(c *gin.Context)

func SearchLogs

func SearchLogs(c *gin.Context)

func SearchModelConfigs

func SearchModelConfigs(c *gin.Context)

func SearchTokens

func SearchTokens(c *gin.Context)

func SortBuiltinModelConfigsFunc

func SortBuiltinModelConfigsFunc(i, j *BuiltinModelConfig) int

func TestAllChannels

func TestAllChannels(c *gin.Context)

func TestChannel

func TestChannel(c *gin.Context)

func TestChannelModels

func TestChannelModels(c *gin.Context)

func UpdateAllChannelsBalance

func UpdateAllChannelsBalance(c *gin.Context)

func UpdateChannel

func UpdateChannel(c *gin.Context)

func UpdateChannelBalance

func UpdateChannelBalance(c *gin.Context)

func UpdateChannelStatus

func UpdateChannelStatus(c *gin.Context)

func UpdateChannelsBalance

func UpdateChannelsBalance(frequency time.Duration)

func UpdateGroup

func UpdateGroup(c *gin.Context)

func UpdateGroupRPM

func UpdateGroupRPM(c *gin.Context)

func UpdateGroupRPMRatio

func UpdateGroupRPMRatio(c *gin.Context)

func UpdateGroupStatus

func UpdateGroupStatus(c *gin.Context)

func UpdateGroupTPM

func UpdateGroupTPM(c *gin.Context)

func UpdateGroupTPMRatio

func UpdateGroupTPMRatio(c *gin.Context)

func UpdateGroupToken

func UpdateGroupToken(c *gin.Context)

func UpdateGroupTokenName

func UpdateGroupTokenName(c *gin.Context)

func UpdateGroupTokenStatus

func UpdateGroupTokenStatus(c *gin.Context)

func UpdateOption

func UpdateOption(c *gin.Context)

func UpdateOptions

func UpdateOptions(c *gin.Context)

func UpdateToken

func UpdateToken(c *gin.Context)

Update handlers

func UpdateTokenName

func UpdateTokenName(c *gin.Context)

func UpdateTokenStatus

func UpdateTokenStatus(c *gin.Context)

Types

type AddChannelRequest

type AddChannelRequest struct {
	ModelMapping map[string]string    `json:"model_mapping"`
	Config       *model.ChannelConfig `json:"config"`
	Name         string               `json:"name"`
	Key          string               `json:"key"`
	BaseURL      string               `json:"base_url"`
	Other        string               `json:"other"`
	Models       []string             `json:"models"`
	Type         int                  `json:"type"`
	Priority     int32                `json:"priority"`
	Status       int                  `json:"status"`
}

func (*AddChannelRequest) ToChannel

func (r *AddChannelRequest) ToChannel() (*model.Channel, error)

func (*AddChannelRequest) ToChannels

func (r *AddChannelRequest) ToChannels() ([]*model.Channel, error)

type AddTokenRequest

type AddTokenRequest struct {
	Name      string   `json:"name"`
	Subnets   []string `json:"subnets"`
	Models    []string `json:"models"`
	ExpiredAt int64    `json:"expiredAt"`
	Quota     float64  `json:"quota"`
}

func (*AddTokenRequest) ToToken

func (at *AddTokenRequest) ToToken() *model.Token

type BuiltinModelConfig

type BuiltinModelConfig model.ModelConfig

func (*BuiltinModelConfig) MarshalJSON

func (c *BuiltinModelConfig) MarshalJSON() ([]byte, error)

type ChannelConfig

type ChannelConfig struct {
	Region            string `json:"region,omitempty"`
	SK                string `json:"sk,omitempty"`
	AK                string `json:"ak,omitempty"`
	UserID            string `json:"user_id,omitempty"`
	APIVersion        string `json:"api_version,omitempty"`
	LibraryID         string `json:"library_id,omitempty"`
	VertexAIProjectID string `json:"vertex_ai_project_id,omitempty"`
	VertexAIADC       string `json:"vertex_ai_adc,omitempty"`
}

type CreateGroupRequest

type CreateGroupRequest struct {
	RPM      map[string]int64 `json:"rpm"`
	RPMRatio float64          `json:"rpm_ratio"`
	TPM      map[string]int64 `json:"tpm"`
	TPMRatio float64          `json:"tpm_ratio"`
}

type GetModelConfigsByModelsContainsRequest

type GetModelConfigsByModelsContainsRequest struct {
	Models []string `json:"models"`
}

type GroupResponse

type GroupResponse struct {
	*model.Group
	AccessedAt time.Time `json:"accessed_at,omitempty"`
}

func (*GroupResponse) MarshalJSON

func (g *GroupResponse) MarshalJSON() ([]byte, error)

type ImportChannelFromOneAPIRequest

type ImportChannelFromOneAPIRequest struct {
	DSN string `json:"dsn"`
}

type OneAPIChannel

type OneAPIChannel struct {
	Type         int               `gorm:"default:0"                              json:"type"`
	Key          string            `gorm:"type:text"                              json:"key"`
	Status       int               `gorm:"default:1"                              json:"status"`
	Name         string            `gorm:"index"                                  json:"name"`
	BaseURL      string            `gorm:"column:base_url;default:''"`
	Models       string            `json:"models"`
	ModelMapping map[string]string `gorm:"type:varchar(1024);serializer:fastjson"`
	Priority     int32             `gorm:"bigint;default:0"`
	Config       ChannelConfig     `gorm:"serializer:fastjson"`
}

func (*OneAPIChannel) TableName

func (c *OneAPIChannel) TableName() string

type OpenAIModelPermission

type OpenAIModelPermission struct {
	Group              *string `json:"group"`
	ID                 string  `json:"id"`
	Object             string  `json:"object"`
	Organization       string  `json:"organization"`
	Created            int     `json:"created"`
	AllowCreateEngine  bool    `json:"allow_create_engine"`
	AllowSampling      bool    `json:"allow_sampling"`
	AllowLogprobs      bool    `json:"allow_logprobs"`
	AllowSearchIndices bool    `json:"allow_search_indices"`
	AllowView          bool    `json:"allow_view"`
	AllowFineTuning    bool    `json:"allow_fine_tuning"`
	IsBlocking         bool    `json:"is_blocking"`
}

type OpenAIModels

type OpenAIModels struct {
	Parent     *string                 `json:"parent"`
	ID         string                  `json:"id"`
	Object     string                  `json:"object"`
	OwnedBy    string                  `json:"owned_by"`
	Root       string                  `json:"root"`
	Permission []OpenAIModelPermission `json:"permission"`
	Created    int                     `json:"created"`
}

type RelayController

type RelayController func(*meta.Meta, *gin.Context) *controller.HandleResult

type SaveModelConfigsRequest

type SaveModelConfigsRequest struct {
	CreatedAt int64 `json:"created_at"`
	UpdatedAt int64 `json:"updated_at"`
	*model.ModelConfig
}

type StatusData

type StatusData struct {
	StartTime int64 `json:"startTime"`
}

type TokenResponse

type TokenResponse struct {
	*model.Token
	AccessedAt time.Time `json:"accessed_at"`
}

TokenResponse represents the response structure for token endpoints

func (*TokenResponse) MarshalJSON

func (t *TokenResponse) MarshalJSON() ([]byte, error)

type UpdateChannelStatusRequest

type UpdateChannelStatusRequest struct {
	Status int `json:"status"`
}

type UpdateGroupRPMRatioRequest

type UpdateGroupRPMRatioRequest struct {
	RPMRatio float64 `json:"rpm_ratio"`
}

type UpdateGroupRPMRequest

type UpdateGroupRPMRequest struct {
	RPM map[string]int64 `json:"rpm"`
}

type UpdateGroupStatusRequest

type UpdateGroupStatusRequest struct {
	Status int `json:"status"`
}

type UpdateGroupTPMRatioRequest

type UpdateGroupTPMRatioRequest struct {
	TPMRatio float64 `json:"tpm_ratio"`
}

type UpdateGroupTPMRequest

type UpdateGroupTPMRequest struct {
	TPM map[string]int64 `json:"tpm"`
}

type UpdateTokenNameRequest

type UpdateTokenNameRequest struct {
	Name string `json:"name"`
}

type UpdateTokenStatusRequest

type UpdateTokenStatusRequest struct {
	Status int `json:"status"`
}

Jump to

Keyboard shortcuts

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