From c96895e35bdd44c066ed35fde56d34cb21a2cd4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=A1=E4=B8=B9=E5=87=A4=E5=87=B0?= <87239270+sunrise0o0@users.noreply.github.com> Date: Sat, 8 Feb 2025 00:07:55 +0800 Subject: [PATCH 1/3] docs: add related project CherryStudio (#2059) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update README.md 增加相关项目CherryStudio * Update README.en.md * Update README.ja.md --- README.en.md | 1 + README.ja.md | 4 ++-- README.md | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.en.md b/README.en.md index 2741062e..61864241 100644 --- a/README.en.md +++ b/README.en.md @@ -315,6 +315,7 @@ If the channel ID is not provided, load balancing will be used to distribute the * [FastGPT](https://github.com/labring/FastGPT): Knowledge question answering system based on the LLM * [VChart](https://github.com/VisActor/VChart): More than just a cross-platform charting library, but also an expressive data storyteller. * [VMind](https://github.com/VisActor/VMind): Not just automatic, but also fantastic. Open-source solution for intelligent visualization. +* * [CherryStudio](https://github.com/CherryHQ/cherry-studio): A cross-platform AI client that integrates multiple service providers and supports local knowledge base management. ## Note This project is an open-source project. Please use it in compliance with OpenAI's [Terms of Use](https://openai.com/policies/terms-of-use) and **applicable laws and regulations**. It must not be used for illegal purposes. diff --git a/README.ja.md b/README.ja.md index 4642df7d..38080468 100644 --- a/README.ja.md +++ b/README.ja.md @@ -287,8 +287,8 @@ graph LR + インターフェイスアドレスと API Key が正しいか再確認してください。 ## 関連プロジェクト -[FastGPT](https://github.com/labring/FastGPT): LLM に基づく知識質問応答システム - +* [FastGPT](https://github.com/labring/FastGPT): LLM に基づく知識質問応答システム +* [CherryStudio](https://github.com/CherryHQ/cherry-studio): マルチプラットフォーム対応のAIクライアント。複数のサービスプロバイダーを統合管理し、ローカル知識ベースをサポートします。 ## 注 本プロジェクトはオープンソースプロジェクトです。OpenAI の[利用規約](https://openai.com/policies/terms-of-use)および**適用される法令**を遵守してご利用ください。違法な目的での利用はご遠慮ください。 diff --git a/README.md b/README.md index a00f07d5..2a3d3453 100644 --- a/README.md +++ b/README.md @@ -469,6 +469,7 @@ https://openai.justsong.cn * [ChatGPT Next Web](https://github.com/Yidadaa/ChatGPT-Next-Web): 一键拥有你自己的跨平台 ChatGPT 应用 * [VChart](https://github.com/VisActor/VChart): 不只是开箱即用的多端图表库,更是生动灵活的数据故事讲述者。 * [VMind](https://github.com/VisActor/VMind): 不仅自动,还很智能。开源智能可视化解决方案。 +* [CherryStudio](https://github.com/CherryHQ/cherry-studio): 全平台支持的AI客户端, 多服务商集成管理、本地知识库支持。 ## 注意 From 07808122a64995f3a483093bf90071fe070bcc71 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 9 Feb 2025 10:57:22 +0800 Subject: [PATCH 2/3] fix: fix Debugf not using DebugEnabled (close #2068) --- common/logger/logger.go | 3 +++ relay/model/message.go | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common/logger/logger.go b/common/logger/logger.go index b5348033..724bc029 100644 --- a/common/logger/logger.go +++ b/common/logger/logger.go @@ -93,6 +93,9 @@ func Error(ctx context.Context, msg string) { } func Debugf(ctx context.Context, format string, a ...any) { + if !config.DebugEnabled { + return + } logHelper(ctx, loggerDEBUG, fmt.Sprintf(format, a...)) } diff --git a/relay/model/message.go b/relay/model/message.go index b908f989..5ff7b7ae 100644 --- a/relay/model/message.go +++ b/relay/model/message.go @@ -1,11 +1,12 @@ package model type Message struct { - Role string `json:"role,omitempty"` - Content any `json:"content,omitempty"` - Name *string `json:"name,omitempty"` - ToolCalls []Tool `json:"tool_calls,omitempty"` - ToolCallId string `json:"tool_call_id,omitempty"` + Role string `json:"role,omitempty"` + Content any `json:"content,omitempty"` + ReasoningContent any `json:"reasoning_content,omitempty"` + Name *string `json:"name,omitempty"` + ToolCalls []Tool `json:"tool_calls,omitempty"` + ToolCallId string `json:"tool_call_id,omitempty"` } func (m Message) IsStringContent() bool { From 3e3b8230ac138cc3279ccc65fd32b8121a66880f Mon Sep 17 00:00:00 2001 From: longkeyy Date: Sun, 9 Feb 2025 11:02:45 +0800 Subject: [PATCH 3/3] fix: add read/write locks for ModelRatio and GroupRatio to prevent concurrent map read/write issues (#2067) --- relay/billing/ratio/group.go | 6 ++++++ relay/billing/ratio/model.go | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/relay/billing/ratio/group.go b/relay/billing/ratio/group.go index 8e9c5b73..b7f62e6e 100644 --- a/relay/billing/ratio/group.go +++ b/relay/billing/ratio/group.go @@ -3,8 +3,10 @@ package ratio import ( "encoding/json" "github.com/songquanpeng/one-api/common/logger" + "sync" ) +var groupRatioLock sync.RWMutex var GroupRatio = map[string]float64{ "default": 1, "vip": 1, @@ -20,11 +22,15 @@ func GroupRatio2JSONString() string { } func UpdateGroupRatioByJSONString(jsonStr string) error { + groupRatioLock.Lock() + defer groupRatioLock.Unlock() GroupRatio = make(map[string]float64) return json.Unmarshal([]byte(jsonStr), &GroupRatio) } func GetGroupRatio(name string) float64 { + groupRatioLock.RLock() + defer groupRatioLock.RUnlock() ratio, ok := GroupRatio[name] if !ok { logger.SysError("group ratio not found: " + name) diff --git a/relay/billing/ratio/model.go b/relay/billing/ratio/model.go index d4deff8b..a0d57e26 100644 --- a/relay/billing/ratio/model.go +++ b/relay/billing/ratio/model.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "strings" + "sync" "github.com/songquanpeng/one-api/common/logger" ) @@ -15,6 +16,8 @@ const ( RMB = USD / USD2RMB ) +var modelRatioLock sync.RWMutex + // ModelRatio // https://platform.openai.com/docs/models/model-endpoint-compatibility // https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Blfmc9dlf @@ -88,11 +91,11 @@ var ModelRatio = map[string]float64{ "claude-2.1": 8.0 / 1000 * USD, "claude-3-haiku-20240307": 0.25 / 1000 * USD, "claude-3-5-haiku-20241022": 1.0 / 1000 * USD, - "claude-3-5-haiku-latest": 1.0 / 1000 * USD, + "claude-3-5-haiku-latest": 1.0 / 1000 * USD, "claude-3-sonnet-20240229": 3.0 / 1000 * USD, "claude-3-5-sonnet-20240620": 3.0 / 1000 * USD, "claude-3-5-sonnet-20241022": 3.0 / 1000 * USD, - "claude-3-5-sonnet-latest" : 3.0 / 1000 * USD, + "claude-3-5-sonnet-latest": 3.0 / 1000 * USD, "claude-3-opus-20240229": 15.0 / 1000 * USD, // https://cloud.baidu.com/doc/WENXINWORKSHOP/s/hlrk4akp7 "ERNIE-4.0-8K": 0.120 * RMB, @@ -417,11 +420,15 @@ func ModelRatio2JSONString() string { } func UpdateModelRatioByJSONString(jsonStr string) error { + modelRatioLock.Lock() + defer modelRatioLock.Unlock() ModelRatio = make(map[string]float64) return json.Unmarshal([]byte(jsonStr), &ModelRatio) } func GetModelRatio(name string, channelType int) float64 { + modelRatioLock.RLock() + defer modelRatioLock.RUnlock() if strings.HasPrefix(name, "qwen-") && strings.HasSuffix(name, "-internet") { name = strings.TrimSuffix(name, "-internet") }