Skip to content

Commit

Permalink
Merge pull request #41 from mylxsw/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mylxsw authored Jan 4, 2024
2 parents 67139e9 + 26b473d commit 2cb6d42
Show file tree
Hide file tree
Showing 28 changed files with 1,449 additions and 407 deletions.
9 changes: 9 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,12 @@ virtual-model-beichou-prompt: ""
#price-table-file: /data/webroot/aidea-server/etc/coins-table.yaml
price-table-file: ""

######## 免费模型 ########
# 是否启用免费聊天功能,启用后,未登录可以免费使用部分模型
free-chat-enabled: false
# 每日免费次数,基于客户端 IP 限制
free-chat-daily-limit: 5
# 每日全局免费次数,总的限制次数,不管是哪个 IP
free-chat-daily-global-limit: 1000
# 免费模型,所有的请求都会被替换为该模型
free-chat-model: gpt-3.5-turbo
14 changes: 14 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ type Config struct {
FontPath string `json:"font_path" yaml:"font_path"`
// 服务状态页面
ServiceStatusPage string `json:"service_status_page" yaml:"service_status_page"`

// 免费 Chat 请求 (仅限 IOS)
FreeChatEnabled bool `json:"free_chat_enabled" yaml:"free_chat_enabled"`
// 免费 Chat 每日限制(每 IP)
FreeChatDailyLimit int `json:"free_chat_daily_limit" yaml:"free_chat_daily_limit"`
// 免费 Chat 每日全局限制(不区分 IP)
FreeChatDailyGlobalLimit int `json:"free_chat_daily_global_limit" yaml:"free_chat_daily_global_limit"`
// 免费 Chat 模型
FreeChatModel string `json:"free_chat_model" yaml:"free_chat_model"`
}

func (conf *Config) SupportProxy() bool {
Expand Down Expand Up @@ -531,6 +540,11 @@ func Register(ins *app.App) {

FontPath: ctx.String("font-path"),
ServiceStatusPage: ctx.String("service-status-page"),

FreeChatEnabled: ctx.Bool("free-chat-enabled"),
FreeChatDailyLimit: ctx.Int("free-chat-daily-limit"),
FreeChatDailyGlobalLimit: ctx.Int("free-chat-daily-global-limit"),
FreeChatModel: ctx.String("free-chat-model"),
}
})
}
5 changes: 5 additions & 0 deletions config/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,9 @@ func initCmdFlags(ins *app.App) {

ins.AddStringFlag("font-path", "", "字体文件路径")
ins.AddStringFlag("service-status-page", "", "服务状态页面,留空则不启用服务状态页面")

ins.AddBoolFlag("free-chat-enabled", "是否启用免费聊天功能,启用后,未登录可以免费使用部分模型")
ins.AddIntFlag("free-chat-daily-limit", 5, "每日免费次数,基于客户端 IP 限制")
ins.AddIntFlag("free-chat-daily-global-limit", 1000, "每日全局免费次数,总的限制次数,不管是哪个 IP")
ins.AddStringFlag("free-chat-model", "gpt-3.5-turbo", "免费模型,所有的请求都会被替换为该模型")
}
26 changes: 26 additions & 0 deletions internal/coins/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ var coinTables = map[string]CoinTable{
"dall-e-2": 20,
},

"video": {
"default": 200,
"stability-image-to-video": 200,
},

"openai": {
// 1000 Token 计费
"gpt-3.5-turbo": 3, // valid $0.002/1K tokens -> ¥0.014/1K tokens
Expand Down Expand Up @@ -193,6 +198,27 @@ func GetUnifiedImageGenCoins(model string) int {
return int(coinTables["image"]["default"])
}

// GetImageGenCoinsExcept 获取除了指定价格的所有图片生成模型
func GetImageGenCoinsExcept(coins int64) map[string]int64 {
coinsTable := make(map[string]int64)
for model, price := range coinTables["image"] {
if price != coins {
coinsTable[model] = price
}
}

return coinsTable
}

// GetUnifiedVideoGenCoins 统一的视频生成计费
func GetUnifiedVideoGenCoins(model string) int {
if price, ok := coinTables["video"][model]; ok {
return int(price)
}

return int(coinTables["video"]["default"])
}

func GetTextToVoiceCoins(model string, wordCount int) int64 {
if price, ok := coinTables["speech"][model]; ok {
return int64(math.Ceil(float64(price) * float64(wordCount) / 1000.0))
Expand Down
3 changes: 2 additions & 1 deletion internal/queue/consumer/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ func (p Provider) Boot(resolver infra.Resolver) {
mux.HandleFunc(queue.TypeFromStonCompletion, queue.BuildFromStonCompletionHandler(fromstonClient, uploader, rep))
mux.HandleFunc(queue.TypeDashscopeImageCompletion, queue.BuildDashscopeImageCompletionHandler(dashscopeClient, uploader, rep, translater, openaiClient))
mux.HandleFunc(queue.TypeGetimgAICompletion, queue.BuildGetimgAICompletionHandler(getimgaiClient, translater, uploader, rep, openaiClient))
mux.HandleFunc(queue.TypeImageDownloader, queue.BuildImageDownloaderHandler(uploader, rep))
mux.HandleFunc(queue.TypeImageDownloader, queue.BuildImageDownloaderHandler(conf, uploader, rep))
mux.HandleFunc(queue.TypeImageUpscale, queue.BuildImageUpscaleHandler(deepaiClient, stabaiClient, uploader, rep))
mux.HandleFunc(queue.TypeImageColorization, queue.BuildImageColorizationHandler(deepaiClient, uploader, rep))
mux.HandleFunc(queue.TypeGroupChat, queue.BuildGroupChatHandler(conf, ct, rep, userSvc))
mux.HandleFunc(queue.TypeDalleCompletion, queue.BuildDalleCompletionHandler(dalleClient, uploader, rep))
mux.HandleFunc(queue.TypeArtisticTextCompletion, queue.BuildArtisticTextCompletionHandler(leptonClient, translater, uploader, rep, openaiClient))
mux.HandleFunc(queue.TypeImageToVideoCompletion, queue.BuildImageToVideoCompletionHandler(stabaiClient, rep))
})
}

Expand Down
Loading

0 comments on commit 2cb6d42

Please sign in to comment.