From 89745a25c56d2d3485dcd535ba2e6a781ea78db0 Mon Sep 17 00:00:00 2001 From: SanaeFox <36219542+Hoshinonyaruko@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:18:36 +0800 Subject: [PATCH] Beta135 (#134) * beta1 * beta2 * beta3 * beta4 * beta5 * beta6 * beta7 * beta8 * beta9 * beta10 * beta11 * beta12 * beta13 * beta14 * beta15 * beta16 * beta16 * beta19 * beta20 * beta21 * beta22 * beta23 * beta24 * beta25 * beta27 * beta28 * beta29 * beta30 * beta31 * beta33 * beta34 * beta35 * beta36 * beta37 * beta38 * beta39 * beta40 * beta41 * beta42 * beta43 * beta44 * beta45 * beta45 * beta46 * beat48 * beta49 * beta50 * beta51 * beta52 * beta53 * beta54 * beta55 * beta57 * beta58 * beta59 * beta61 * beta62 * beta63 * beta63 * beta64 * beta65 * beta66 * beta67 * beta70 * beta71 * beta72 * beta72 * beta74 * beta75 * beta76 * beta77 * beta78 * beta79 * beta80 * beta81 * beta82 * beta83 * beta85 * beta86 * beta87 * beta88 * beta89 * beta90 * beta91 * beta92 * beta93 * beta94 * beta94 * beta96 * beta97 * beta98 * beta99 * beta100 * beta101 * beta102 * beta104 * beta105 * beta106 * beta107 * beta108 * beta109 * beta110 * beta111 * beta112 * beta113 * beta115 * beta116 * beta117 * beta118 * beta119 * beta120 * beta121 * beta122 * beta123 * beta124 * beta125 * beta126 * beta127 * beta128 * beta129 * beta130 * beta131 * beta132 * beta1333 * beta134 * beta135 --- applogic/gensokyo.go | 38 +++++++++++++++++++++++++++++-------- config/config.go | 10 ++++++++++ structs/struct.go | 1 + template/config_template.go | 1 + utils/utils.go | 6 +++--- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/applogic/gensokyo.go b/applogic/gensokyo.go index 4db4ac4..a92b76e 100644 --- a/applogic/gensokyo.go +++ b/applogic/gensokyo.go @@ -492,8 +492,14 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) { } } - // 请求conversation api 增加当前用户上下文 - conversationID, parentMessageID, err := app.handleUserContext(message.UserID) + var conversationID, parentMessageID string + // 请求conversation api 增加当前群/用户上下文 + if config.GetGroupContext() && message.MessageType != "private" { + conversationID, parentMessageID, err = app.handleUserContext(message.GroupID) + } else { + conversationID, parentMessageID, err = app.handleUserContext(message.UserID) + } + // 使用map映射conversationID和uid gid的关系 StoreUserInfo(conversationID, message.UserID, message.GroupID, message.RealMessageType, message.MessageType) @@ -863,10 +869,18 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) { // 在SSE流结束后更新用户上下文 在这里调用gensokyo流式接口的最后一步 插推荐气泡 if lastMessageID != "" { fmtf.Printf("lastMessageID: %s\n", lastMessageID) - err := app.updateUserContext(message.UserID, lastMessageID) - if err != nil { - fmtf.Printf("Error updating user context: %v\n", err) + if config.GetGroupContext() && message.MessageType != "private" { + err := app.updateUserContext(message.GroupID, lastMessageID) + if err != nil { + fmtf.Printf("Error updating user context: %v\n", err) + } + } else { + err := app.updateUserContext(message.UserID, lastMessageID) + if err != nil { + fmtf.Printf("Error updating user context: %v\n", err) + } } + if message.RealMessageType == "group_private" || message.MessageType == "private" { if config.GetUsePrivateSSE() { @@ -960,10 +974,18 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) { // 更新用户上下文 if messageId, ok := responseData["messageId"].(string); ok { - err := app.updateUserContext(message.UserID, messageId) - if err != nil { - fmtf.Printf("Error updating user context: %v\n", err) + if config.GetGroupContext() && message.MessageType != "private" { + err := app.updateUserContext(message.GroupID, messageId) + if err != nil { + fmtf.Printf("Error updating user context: %v\n", err) + } + } else { + err := app.updateUserContext(message.UserID, messageId) + if err != nil { + fmtf.Printf("Error updating user context: %v\n", err) + } } + } } diff --git a/config/config.go b/config/config.go index 173c44c..1b9fff1 100644 --- a/config/config.go +++ b/config/config.go @@ -1122,6 +1122,16 @@ func GetNoContext() bool { return false } +// 获取GroupContext +func GetGroupContext() bool { + mu.Lock() + defer mu.Unlock() + if instance != nil { + return instance.Settings.GroupContext + } + return false +} + // 获取WithdrawCommand func GetWithdrawCommand() []string { mu.Lock() diff --git a/structs/struct.go b/structs/struct.go index e90d480..9fe5828 100644 --- a/structs/struct.go +++ b/structs/struct.go @@ -264,6 +264,7 @@ type Settings struct { UrlSendPics bool `yaml:"urlSendPics"` // 自己构造图床加速图片发送 MdPromptKeyboardAtGroup bool `yaml:"mdPromptKeyboardAtGroup"` // 群内使用md能力模拟PromptKeyboard GroupHintWords []string `yaml:"groupHintWords"` + GroupContext bool `yaml:"groupContext"` HunyuanType int `yaml:"hunyuanType"` MaxTokensHunyuan int `yaml:"maxTokensHunyuan"` diff --git a/template/config_template.go b/template/config_template.go index 051c26d..a8739a3 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -49,6 +49,7 @@ settings: hideExtraLogs : false #忽略流信息的log,提高性能 urlSendPics : false #自己构造图床加速图片发送.需配置公网ip+放通port+设置正确的selfPath groupHintWords : [] #当机器人位于群内时,需满足包含groupHintWords数组任意内容如[CQ:at,qq=2] 机器人的名字 等 + groupContext : false #群上下文 在智能体在群内时,以群为单位处理上下文. #Ws服务器配置 wsServerToken : "" #ws密钥 可以由onebotv11反向ws接入 diff --git a/utils/utils.go b/utils/utils.go index 981b1e4..85a59b9 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -981,11 +981,11 @@ func SendSSEPrivateMessage(userID int64, content string) { } if state == 20 { // 对最后一部分特殊处理 - RestoreResponses := config.GetRestoreCommand() + MemoryLoadCommand := config.GetMemoryLoadCommand() promptKeyboard := config.GetPromptkeyboard() - if len(RestoreResponses) > 0 { - selectedRestoreResponse := RestoreResponses[rand.Intn(len(RestoreResponses))] + if len(MemoryLoadCommand) > 0 { + selectedRestoreResponse := MemoryLoadCommand[rand.Intn(len(MemoryLoadCommand))] if len(promptKeyboard) > 0 { promptKeyboard[0] = selectedRestoreResponse }