mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-17 13:43:42 +08:00
🔖 chore: migration constants
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"one-api/common"
|
||||
"one-api/common/config"
|
||||
"one-api/common/logger"
|
||||
"one-api/common/requester"
|
||||
"one-api/common/utils"
|
||||
@@ -93,7 +94,7 @@ func fetchChannelById(channelId int) (*model.Channel, error) {
|
||||
if err != nil {
|
||||
return nil, errors.New("无效的渠道 Id")
|
||||
}
|
||||
if channel.Status != common.ChannelStatusEnabled {
|
||||
if channel.Status != config.ChannelStatusEnabled {
|
||||
return nil, errors.New("该渠道已被禁用")
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"one-api/common"
|
||||
"one-api/common/config"
|
||||
"one-api/common/logger"
|
||||
"one-api/model"
|
||||
"one-api/relay/relay_util"
|
||||
@@ -50,7 +51,7 @@ func Relay(c *gin.Context) {
|
||||
channel := relay.getProvider().GetChannel()
|
||||
go processChannelRelayError(c.Request.Context(), channel.Id, channel.Name, apiErr)
|
||||
|
||||
retryTimes := common.RetryTimes
|
||||
retryTimes := config.RetryTimes
|
||||
if done || !shouldRetry(c, apiErr.StatusCode) {
|
||||
logger.LogError(c.Request.Context(), fmt.Sprintf("relay error happen, status code is %d, won't retry in this case", apiErr.StatusCode))
|
||||
retryTimes = 0
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"one-api/common"
|
||||
"one-api/common/config"
|
||||
"one-api/controller"
|
||||
"one-api/model"
|
||||
provider "one-api/providers/midjourney"
|
||||
@@ -112,7 +113,7 @@ func coverMidjourneyTaskDto(originTask *model.Midjourney) (midjourneyTask provid
|
||||
midjourneyTask.FinishTime = originTask.FinishTime
|
||||
midjourneyTask.ImageUrl = ""
|
||||
if originTask.ImageUrl != "" {
|
||||
midjourneyTask.ImageUrl = common.ServerAddress + "/mj/image/" + originTask.MjId
|
||||
midjourneyTask.ImageUrl = config.ServerAddress + "/mj/image/" + originTask.MjId
|
||||
if originTask.Status != "SUCCESS" {
|
||||
midjourneyTask.ImageUrl += "?rand=" + strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package relay
|
||||
import (
|
||||
"net/http"
|
||||
"one-api/common"
|
||||
"one-api/common/config"
|
||||
"one-api/model"
|
||||
"one-api/providers/azure"
|
||||
"one-api/providers/openai"
|
||||
@@ -20,7 +21,7 @@ func RelayOnly(c *gin.Context) {
|
||||
}
|
||||
|
||||
channel := provider.GetChannel()
|
||||
if channel.Type != common.ChannelTypeOpenAI && channel.Type != common.ChannelTypeAzure {
|
||||
if channel.Type != config.ChannelTypeOpenAI && channel.Type != config.ChannelTypeAzure {
|
||||
common.AbortWithMessage(c, http.StatusServiceUnavailable, "provider must be of type azureopenai or openai")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"one-api/common"
|
||||
"one-api/common/config"
|
||||
"one-api/common/utils"
|
||||
"one-api/model"
|
||||
|
||||
@@ -57,7 +58,7 @@ func NewChatCacheProps(c *gin.Context, allow bool) *ChatCacheProps {
|
||||
return props
|
||||
}
|
||||
|
||||
if common.ChatCacheEnabled && c.GetBool("chat_cache") {
|
||||
if config.ChatCacheEnabled && c.GetBool("chat_cache") {
|
||||
props.Cache = true
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ func (p *ChatCacheProps) StoreCache(channelId, promptTokens, completionTokens in
|
||||
p.CompletionTokens = completionTokens
|
||||
p.ModelName = modelName
|
||||
|
||||
return p.Driver.Set(p.getHash(), p, int64(common.ChatCacheExpireMinute))
|
||||
return p.Driver.Set(p.getHash(), p, int64(config.ChatCacheExpireMinute))
|
||||
}
|
||||
|
||||
func (p *ChatCacheProps) GetCache() *ChatCacheProps {
|
||||
@@ -125,7 +126,7 @@ func (p *ChatCacheProps) GetCache() *ChatCacheProps {
|
||||
}
|
||||
|
||||
func (p *ChatCacheProps) needCache() bool {
|
||||
return common.ChatCacheEnabled && p.Cache
|
||||
return config.ChatCacheEnabled && p.Cache
|
||||
}
|
||||
|
||||
func (p *ChatCacheProps) getHash() string {
|
||||
|
||||
@@ -3,7 +3,7 @@ package relay_util
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"one-api/common"
|
||||
"one-api/common/config"
|
||||
"one-api/common/logger"
|
||||
"one-api/common/utils"
|
||||
"one-api/model"
|
||||
@@ -107,7 +107,7 @@ func (p *Pricing) GetPrice(modelName string) *model.Price {
|
||||
|
||||
return &model.Price{
|
||||
Type: model.TokensPriceType,
|
||||
ChannelType: common.ChannelTypeUnknown,
|
||||
ChannelType: config.ChannelTypeUnknown,
|
||||
Input: model.DefaultPrice,
|
||||
Output: model.DefaultPrice,
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"math"
|
||||
"net/http"
|
||||
"one-api/common"
|
||||
"one-api/common/config"
|
||||
"one-api/common/logger"
|
||||
"one-api/model"
|
||||
"one-api/types"
|
||||
@@ -45,7 +46,7 @@ func NewQuota(c *gin.Context, modelName string, promptTokens int) (*Quota, *type
|
||||
if quota.price.Type == model.TimesPriceType {
|
||||
quota.preConsumedQuota = int(1000 * quota.inputRatio)
|
||||
} else {
|
||||
quota.preConsumedQuota = int(float64(quota.promptTokens+common.PreConsumedQuota) * quota.inputRatio)
|
||||
quota.preConsumedQuota = int(float64(quota.promptTokens+config.PreConsumedQuota) * quota.inputRatio)
|
||||
}
|
||||
|
||||
errWithCode := quota.preQuotaConsumption()
|
||||
|
||||
@@ -1,35 +1,37 @@
|
||||
package relay_util
|
||||
|
||||
import "one-api/common"
|
||||
import (
|
||||
"one-api/common/config"
|
||||
)
|
||||
|
||||
var UnknownOwnedBy = "未知"
|
||||
var ModelOwnedBy map[int]string
|
||||
|
||||
func init() {
|
||||
ModelOwnedBy = map[int]string{
|
||||
common.ChannelTypeOpenAI: "OpenAI",
|
||||
common.ChannelTypeAnthropic: "Anthropic",
|
||||
common.ChannelTypeBaidu: "Baidu",
|
||||
common.ChannelTypePaLM: "Google PaLM",
|
||||
common.ChannelTypeGemini: "Google Gemini",
|
||||
common.ChannelTypeZhipu: "Zhipu",
|
||||
common.ChannelTypeAli: "Ali",
|
||||
common.ChannelTypeXunfei: "Xunfei",
|
||||
common.ChannelType360: "360",
|
||||
common.ChannelTypeTencent: "Tencent",
|
||||
common.ChannelTypeBaichuan: "Baichuan",
|
||||
common.ChannelTypeMiniMax: "MiniMax",
|
||||
common.ChannelTypeDeepseek: "Deepseek",
|
||||
common.ChannelTypeMoonshot: "Moonshot",
|
||||
common.ChannelTypeMistral: "Mistral",
|
||||
common.ChannelTypeGroq: "Groq",
|
||||
common.ChannelTypeLingyi: "Lingyiwanwu",
|
||||
common.ChannelTypeMidjourney: "Midjourney",
|
||||
common.ChannelTypeCloudflareAI: "Cloudflare AI",
|
||||
common.ChannelTypeCohere: "Cohere",
|
||||
common.ChannelTypeStabilityAI: "Stability AI",
|
||||
common.ChannelTypeCoze: "Coze",
|
||||
common.ChannelTypeOllama: "Ollama",
|
||||
common.ChannelTypeHunyuan: "Hunyuan",
|
||||
config.ChannelTypeOpenAI: "OpenAI",
|
||||
config.ChannelTypeAnthropic: "Anthropic",
|
||||
config.ChannelTypeBaidu: "Baidu",
|
||||
config.ChannelTypePaLM: "Google PaLM",
|
||||
config.ChannelTypeGemini: "Google Gemini",
|
||||
config.ChannelTypeZhipu: "Zhipu",
|
||||
config.ChannelTypeAli: "Ali",
|
||||
config.ChannelTypeXunfei: "Xunfei",
|
||||
config.ChannelType360: "360",
|
||||
config.ChannelTypeTencent: "Tencent",
|
||||
config.ChannelTypeBaichuan: "Baichuan",
|
||||
config.ChannelTypeMiniMax: "MiniMax",
|
||||
config.ChannelTypeDeepseek: "Deepseek",
|
||||
config.ChannelTypeMoonshot: "Moonshot",
|
||||
config.ChannelTypeMistral: "Mistral",
|
||||
config.ChannelTypeGroq: "Groq",
|
||||
config.ChannelTypeLingyi: "Lingyiwanwu",
|
||||
config.ChannelTypeMidjourney: "Midjourney",
|
||||
config.ChannelTypeCloudflareAI: "Cloudflare AI",
|
||||
config.ChannelTypeCohere: "Cohere",
|
||||
config.ChannelTypeStabilityAI: "Stability AI",
|
||||
config.ChannelTypeCoze: "Coze",
|
||||
config.ChannelTypeOllama: "Ollama",
|
||||
config.ChannelTypeHunyuan: "Hunyuan",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user