From fa4cf7bd66b104d2a0ca6f2d135f757b5710f396 Mon Sep 17 00:00:00 2001 From: river Date: Sun, 19 Nov 2023 10:59:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9ai=E5=8F=91?= =?UTF-8?q?=E6=95=A3=E6=89=BF=E6=8B=85=E7=9A=84=E6=96=87=E6=A1=88=E5=92=8C?= =?UTF-8?q?temperature=E5=AF=B9=E5=BA=94=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://platform.openai.com/docs/api-reference/chat/create --- code/config.example.yaml | 3 ++- code/handlers/card_ai_mode_action.go | 2 +- code/handlers/event_common_action.go | 4 ++-- code/handlers/event_msg_action.go | 6 ++++-- code/handlers/msg.go | 6 +++--- code/logger/logger.go | 2 +- code/services/openai/gpt3.go | 22 +++++++++++----------- 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/code/config.example.yaml b/code/config.example.yaml index 93d41139..d93a1abe 100644 --- a/code/config.example.yaml +++ b/code/config.example.yaml @@ -9,7 +9,8 @@ BOT_NAME: chatGpt # openAI key 支持负载均衡 可以填写多个key 用逗号分隔 OPENAI_KEY: sk-xxx,sk-xxx,sk-xxx # openAI model 指定模型,默认为 gpt-3.5-turbo -# 可选参数有:"gpt-4-0314", "gpt-4", "gpt-3.5-turbo-0301","gpt-3.5-turbo-16k", "gpt-3.5-turbo",如果使用gpt-4,请确认自己是否有接口调用白名单 +# 可选参数有:"gpt-4-1106-preview", "gpt-4-32K","gpt-4","gpt-3.5-turbo-16k", "gpt-3.5-turbo","gpt-3.5-turbo-16k","gpt-3.5-turbo-1106" 等 +# 如果使用gpt-4,请确认自己是否有接口调用白名单 OPENAI_MODEL: gpt-3.5-turbo # openAI 最大token数 默认为2000 OPENAI_MAX_TOKENS: 2000 diff --git a/code/handlers/card_ai_mode_action.go b/code/handlers/card_ai_mode_action.go index f544b3cc..f7f05b82 100644 --- a/code/handlers/card_ai_mode_action.go +++ b/code/handlers/card_ai_mode_action.go @@ -31,7 +31,7 @@ func CommonProcessAIMode(msg CardMsg, cardAction *larkcard.CardAction, cache services.SessionServiceCacheInterface) (interface{}, error, bool) { option := cardAction.Action.Option - replyMsg(context.Background(), "已选择AI模式:"+option, + replyMsg(context.Background(), "已选择发散模式:"+option, &msg.MsgId) cache.SetAIMode(msg.SessionId, openai.AIModeMap[option]) return nil, nil, true diff --git a/code/handlers/event_common_action.go b/code/handlers/event_common_action.go index d6827b52..5139060d 100644 --- a/code/handlers/event_common_action.go +++ b/code/handlers/event_common_action.go @@ -155,12 +155,12 @@ func (*RoleListAction) Execute(a *ActionInfo) bool { return true } -type AIModeAction struct { /*AI模式*/ +type AIModeAction struct { /*发散模式*/ } func (*AIModeAction) Execute(a *ActionInfo) bool { if _, foundMode := utils.EitherCutPrefix(a.info.qParsed, - "/ai_mode", "AI模式"); foundMode { + "/ai_mode", "发散模式"); foundMode { SendAIModeListsCard(*a.ctx, a.info.sessionId, a.info.msgId, openai.AIModeStrs) return false } diff --git a/code/handlers/event_msg_action.go b/code/handlers/event_msg_action.go index 6625a375..da7e5b4b 100644 --- a/code/handlers/event_msg_action.go +++ b/code/handlers/event_msg_action.go @@ -37,10 +37,10 @@ func (*MessageAction) Execute(a *ActionInfo) bool { Role: "user", Content: a.info.qParsed, }) - //fmt.Println("msg", msg) - //logger.Debug("msg", msg) // get ai mode as temperature aiMode := a.handler.sessionCache.GetAIMode(*a.info.sessionId) + fmt.Println("msg: ", msg) + fmt.Println("aiMode: ", aiMode) completions, err := a.handler.gpt.Completions(msg, aiMode) if err != nil { replyMsg(*a.ctx, fmt.Sprintf( @@ -132,6 +132,8 @@ func (m *StreamMessageAction) Execute(a *ActionInfo) bool { //log.Printf("UserId: %s , Request: %s", a.info.userId, msg) aiMode := a.handler.sessionCache.GetAIMode(*a.info.sessionId) + //fmt.Println("msg: ", msg) + //fmt.Println("aiMode: ", aiMode) if err := a.handler.gpt.StreamChat(*a.ctx, msg, aiMode, chatResponseStream); err != nil { err := updateFinalCard(*a.ctx, "聊天失败", cardId, ifNewTopic) diff --git a/code/handlers/msg.go b/code/handlers/msg.go index 6c486f3e..1b359864 100644 --- a/code/handlers/msg.go +++ b/code/handlers/msg.go @@ -29,7 +29,7 @@ var ( PicVarMoreKind = CardKind("pic_var_more") // 变量图片 RoleTagsChooseKind = CardKind("role_tags_choose") // 内置角色所属标签选择 RoleChooseKind = CardKind("role_choose") // 内置角色选择 - AIModeChooseKind = CardKind("ai_mode_choose") // AI模式选择 + AIModeChooseKind = CardKind("ai_mode_choose") // 发散模式选择 ) var ( @@ -712,7 +712,7 @@ func sendHelpCard(ctx context.Context, "sessionId": *sessionId, }, larkcard.MessageCardButtonTypeDanger)), withSplitLine(), - withMainMd("🤖 **AI模式选择** \n"+" 文本回复 *AI模式* 或 */ai_mode*"), + withMainMd("🤖 **发散模式选择** \n"+" 文本回复 *发散模式* 或 */ai_mode*"), withSplitLine(), withMainMd("🛖 **内置角色列表** \n"+" 文本回复 *角色列表* 或 */roles*"), withSplitLine(), @@ -810,7 +810,7 @@ func SendRoleListCard(ctx context.Context, func SendAIModeListsCard(ctx context.Context, sessionId *string, msgId *string, aiModeStrs []string) { newCard, _ := newSendCard( - withHeader("🤖 AI模式选择", larkcard.TemplateIndigo), + withHeader("🤖 发散模式选择", larkcard.TemplateIndigo), withAIModeBtn(sessionId, aiModeStrs), withNote("提醒:选择内置模式,让AI更好的理解您的需求。")) replyCard(ctx, msgId, newCard) diff --git a/code/logger/logger.go b/code/logger/logger.go index 75442471..784618c6 100644 --- a/code/logger/logger.go +++ b/code/logger/logger.go @@ -24,7 +24,7 @@ func init() { //WarnLevel //InfoLevel //DebugLevel - logger.Level = logrus.InfoLevel + logger.Level = logrus.ErrorLevel } diff --git a/code/services/openai/gpt3.go b/code/services/openai/gpt3.go index 87425bbb..0ecc7397 100644 --- a/code/services/openai/gpt3.go +++ b/code/services/openai/gpt3.go @@ -12,23 +12,23 @@ type AIMode float64 const ( Fresh AIMode = 0.1 - Warmth AIMode = 0.4 - Balance AIMode = 0.7 - Creativity AIMode = 1.0 + Warmth AIMode = 0.7 + Balance AIMode = 1.2 + Creativity AIMode = 1.7 ) var AIModeMap = map[string]AIMode{ - "清新": Fresh, - "温暖": Warmth, - "平衡": Balance, - "创意": Creativity, + "严谨": Fresh, + "简洁": Warmth, + "标准": Balance, + "发散": Creativity, } var AIModeStrs = []string{ - "清新", - "温暖", - "平衡", - "创意", + "严谨", + "简洁", + "标准", + "发散", } type Messages struct { From ed79cfc174a4d758bf338066d4ca8d08b53e9e31 Mon Sep 17 00:00:00 2001 From: river Date: Sun, 19 Nov 2023 11:03:36 +0800 Subject: [PATCH 2/2] chore: update log level --- code/logger/logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/logger/logger.go b/code/logger/logger.go index 784618c6..75442471 100644 --- a/code/logger/logger.go +++ b/code/logger/logger.go @@ -24,7 +24,7 @@ func init() { //WarnLevel //InfoLevel //DebugLevel - logger.Level = logrus.ErrorLevel + logger.Level = logrus.InfoLevel }