Skip to content

Commit

Permalink
Beta138 (#137)
Browse files Browse the repository at this point in the history
* 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

* beta136

* beta137

* beta138
  • Loading branch information
Hoshinonyaruko authored Jun 6, 2024
1 parent 151d6f7 commit 4e2534a
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 195 deletions.
2 changes: 1 addition & 1 deletion applogic/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (app *App) GetAndSendEnv(msg string, promptstr string, message structs.Oneb
if message.RealMessageType == "group_private" || message.MessageType == "private" {
utils.SendPrivateMessageRaw(message.UserID, newResponse, selfid)
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, newResponse, selfid)
utils.SendGroupMessage(message.GroupID, message.UserID, newResponse, selfid, promptstr)
}
}

Expand Down
16 changes: 8 additions & 8 deletions applogic/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (app *App) ProcessExitChoicesQ(promptstr string, requestmsg *string, messag
}
}
if bestMatchCount > 0 {
app.HandleExit(bestText, message, selfid)
app.HandleExit(bestText, message, selfid, promptstr)
return
}
}
Expand All @@ -422,7 +422,7 @@ func (app *App) ProcessExitChoicesQ(promptstr string, requestmsg *string, messag
texts := strings.Split(addedTexts, "-")
if len(texts) > 0 {
selectedText := texts[rand.Intn(len(texts))]
app.HandleExit(selectedText, message, selfid)
app.HandleExit(selectedText, message, selfid, promptstr)
return
}
}
Expand All @@ -431,7 +431,7 @@ func (app *App) ProcessExitChoicesQ(promptstr string, requestmsg *string, messag
}

// HandleExit 处理用户退出逻辑,包括发送消息和重置用户状态。
func (app *App) HandleExit(exitText string, message *structs.OnebotGroupMessage, selfid string) {
func (app *App) HandleExit(exitText string, message *structs.OnebotGroupMessage, selfid string, promptstr string) {
userid := message.UserID
if config.GetGroupContext() && message.MessageType != "private" {
userid = message.GroupID
Expand All @@ -442,12 +442,12 @@ func (app *App) HandleExit(exitText string, message *structs.OnebotGroupMessage,
RestoreResponse := config.GetRandomRestoreResponses()
if message.RealMessageType == "group_private" || message.MessageType == "private" {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, RestoreResponse, selfid)
utils.SendPrivateMessage(message.UserID, RestoreResponse, selfid, promptstr)
} else {
utils.SendSSEPrivateRestoreMessage(message.UserID, RestoreResponse)
utils.SendSSEPrivateRestoreMessage(message.UserID, RestoreResponse, promptstr)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, RestoreResponse, selfid)
utils.SendGroupMessage(message.GroupID, message.UserID, RestoreResponse, selfid, promptstr)
}
app.deleteCustomRecord(userid)
}
Expand Down Expand Up @@ -508,7 +508,7 @@ func (app *App) ProcessExitChoicesA(promptstr string, response *string, message
}
}
if bestMatchCount > 0 {
app.HandleExit(bestText, message, selfid)
app.HandleExit(bestText, message, selfid, promptstr)
return
}
}
Expand All @@ -526,7 +526,7 @@ func (app *App) ProcessExitChoicesA(promptstr string, response *string, message
texts := strings.Split(addedTexts, "-")
if len(texts) > 0 {
selectedText := texts[rand.Intn(len(texts))]
app.HandleExit(selectedText, message, selfid)
app.HandleExit(selectedText, message, selfid, promptstr)
return
}
}
Expand Down
72 changes: 38 additions & 34 deletions applogic/gensokyo.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
}
}

if utils.BlacklistIntercept(message, selfid) {
if utils.BlacklistIntercept(message, selfid, promptstr) {
fmtf.Printf("userid:[%v]groupid:[%v]这位用户或群在黑名单中,被拦截", message.UserID, message.GroupID)
return
}
Expand All @@ -355,12 +355,12 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
RestoreResponse := config.GetRandomRestoreResponses()
if message.RealMessageType == "group_private" || message.MessageType == "private" {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, RestoreResponse, selfid)
utils.SendPrivateMessage(message.UserID, RestoreResponse, selfid, promptstr)
} else {
utils.SendSSEPrivateRestoreMessage(message.UserID, RestoreResponse)
utils.SendSSEPrivateRestoreMessage(message.UserID, RestoreResponse, promptstr)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, RestoreResponse, selfid)
utils.SendGroupMessage(message.GroupID, message.UserID, RestoreResponse, selfid, promptstr)
}
// 处理故事情节的重置
if config.GetGroupContext() && message.MessageType != "private" {
Expand Down Expand Up @@ -402,7 +402,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {

// 进行字数拦截
if config.GetQuestionMaxLenth() != 0 {
if utils.LengthIntercept(newmsg, message, selfid) {
if utils.LengthIntercept(newmsg, message, selfid, promptstr) {
fmtf.Printf("字数过长,可在questionMaxLenth配置项修改,Q: %v", newmsg)
// 发送响应
w.WriteHeader(http.StatusOK)
Expand All @@ -413,7 +413,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {

// 进行语言判断拦截 skipLangCheck为false时
if len(config.GetAllowedLanguages()) > 0 && !skipLangCheck {
if utils.LanguageIntercept(newmsg, message, selfid) {
if utils.LanguageIntercept(newmsg, message, selfid, promptstr) {
fmtf.Printf("不安全!不支持的语言,可在config.yml设置允许的语言,allowedLanguages配置项,Q: %v", newmsg)
// 发送响应
w.WriteHeader(http.StatusOK)
Expand All @@ -440,7 +440,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {

// 向量安全词部分,机器人向量安全屏障
if config.GetVectorSensitiveFilter() {
ret, retstr, err := app.InterceptSensitiveContent(vector, message, selfid)
ret, retstr, err := app.InterceptSensitiveContent(vector, message, selfid, promptstr)
if err != nil {
fmtf.Printf("Error in InterceptSensitiveContent: %v", err)
// 发送响应
Expand Down Expand Up @@ -490,12 +490,12 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
// 发送响应消息
if message.RealMessageType == "group_private" || message.MessageType == "private" {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, responseText, selfid)
utils.SendPrivateMessage(message.UserID, responseText, selfid, promptstr)
} else {
utils.SendSSEPrivateMessage(message.UserID, responseText)
utils.SendSSEPrivateMessage(message.UserID, responseText, promptstr)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, responseText, selfid)
utils.SendGroupMessage(message.GroupID, message.UserID, responseText, selfid, promptstr)
}
// 发送响应
w.WriteHeader(http.StatusOK)
Expand Down Expand Up @@ -535,12 +535,12 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
if saveresponse != "" {
if message.RealMessageType == "group_private" || message.MessageType == "private" {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, saveresponse, selfid)
utils.SendPrivateMessage(message.UserID, saveresponse, selfid, promptstr)
} else {
utils.SendSSEPrivateSafeMessage(message.UserID, saveresponse)
utils.SendSSEPrivateSafeMessage(message.UserID, saveresponse, promptstr)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, saveresponse, selfid)
utils.SendGroupMessage(message.GroupID, message.UserID, saveresponse, selfid, promptstr)
}
}
// 发送响应
Expand Down Expand Up @@ -575,7 +575,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {

// 处理保存记忆
if ismemoryCommand {
app.handleSaveMemory(message, conversationID, parentMessageID) // 适配群
app.handleSaveMemory(message, conversationID, parentMessageID, promptstr) // 适配群
return
}

Expand All @@ -597,13 +597,13 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {

// 处理记忆列表
if ismemoryLoadCommand {
app.handleMemoryList(message) // 适配群
app.handleMemoryList(message, promptstr) // 适配群
return
}

// 新增处理载入记忆的逻辑
if isPrefixedMemoryLoadCommand {
app.handleLoadMemory(message, checkResetCommand) // 适配群
app.handleLoadMemory(message, checkResetCommand, promptstr) // 适配群
return
}

Expand All @@ -621,7 +621,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {

// 处理新对话
if isnewConversationCommand {
app.handleNewConversation(message, conversationID, parentMessageID) // 适配群
app.handleNewConversation(message, conversationID, parentMessageID, promptstr) // 适配群
return
}

Expand Down Expand Up @@ -686,6 +686,10 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
PromptMarksLength := config.GetPromptMarksLength(promptstr)
app.GetAndSendEnv(requestmsg, promptstr, message, selfid, CustomRecord.PromptStrStat, PromptMarksLength)
}

// 按提示词区分的细化替换 这里主要不是为了安全和敏感词,而是细化效果,也就没有使用acnode提高效率
requestmsg = utils.ReplaceTextIn(requestmsg, promptstr)

if config.GetGroupContext() && message.MessageType != "private" {
fmtf.Printf("实际请求conversation端点内容:[%v]%v\n", message.GroupID, requestmsg)
} else {
Expand Down Expand Up @@ -817,7 +821,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
// 判断消息类型,如果是私人消息或私有群消息,发送私人消息;否则,根据配置决定是否发送群消息
if userinfo.RealMessageType == "group_private" || userinfo.MessageType == "private" {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(userinfo.UserID, newPart, selfid)
utils.SendPrivateMessage(userinfo.UserID, newPart, selfid, promptstr)
} else {
//判断是否最后一条
var state int
Expand All @@ -830,16 +834,16 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
Content: newPart,
State: state,
}
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE)
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr)
}
} else {
// 这里发送的是newPart api最后补充的部分
if !config.GetMdPromptKeyboardAtGroup() {
// 如果没有 EnhancedAContent
if EnhancedAContent == "" {
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, newPart, selfid)
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, newPart, selfid, promptstr)
} else {
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, newPart+EnhancedAContent, selfid)
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, newPart+EnhancedAContent, selfid, promptstr)
}
} else {
// 如果没有 EnhancedAContent
Expand All @@ -864,9 +868,9 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
if !config.GetUsePrivateSSE() {
// 如果没有 EnhancedAContent
if EnhancedAContent == "" {
utils.SendPrivateMessage(userinfo.UserID, response, selfid)
utils.SendPrivateMessage(userinfo.UserID, response, selfid, promptstr)
} else {
utils.SendPrivateMessage(userinfo.UserID, response+EnhancedAContent, selfid)
utils.SendPrivateMessage(userinfo.UserID, response+EnhancedAContent, selfid, promptstr)
}
} else {
//判断是否最后一条
Expand All @@ -880,15 +884,15 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
Content: response,
State: state,
}
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE)
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr)
}
} else {
if !config.GetMdPromptKeyboardAtGroup() {
// 如果没有 EnhancedAContent
if EnhancedAContent == "" {
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, response, selfid)
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, response, selfid, promptstr)
} else {
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, response+EnhancedAContent, selfid)
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, response+EnhancedAContent, selfid, promptstr)
}
} else {
// 如果没有 EnhancedAContent
Expand Down Expand Up @@ -936,7 +940,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
Content: EnhancedAContent,
State: 11,
}
utils.SendPrivateMessageSSE(message.UserID, messageSSE)
utils.SendPrivateMessageSSE(message.UserID, messageSSE, promptstr)
}
}
}
Expand Down Expand Up @@ -1015,7 +1019,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
State: 20,
PromptKeyboard: promptkeyboard,
}
utils.SendPrivateMessageSSE(message.UserID, messageSSE)
utils.SendPrivateMessageSSE(message.UserID, messageSSE, promptstr)
ResetIndex(newmsg)
}
}
Expand All @@ -1041,9 +1045,9 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
if response, ok = responseData["response"].(string); ok && response != "" {
// 判断消息类型,如果是私人消息或私有群消息,发送私人消息;否则,根据配置决定是否发送群消息
if message.RealMessageType == "group_private" || message.MessageType == "private" {
utils.SendPrivateMessage(message.UserID, response, selfid)
utils.SendPrivateMessage(message.UserID, response, selfid, promptstr)
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, response, selfid)
utils.SendGroupMessage(message.GroupID, message.UserID, response, selfid, promptstr)
}
}

Expand Down Expand Up @@ -1157,7 +1161,7 @@ func processMessage(response string, conversationid string, newmesssage string,
// 判断消息类型,如果是私人消息或私有群消息,发送私人消息;否则,根据配置决定是否发送群消息
if userinfo.RealMessageType == "group_private" || userinfo.MessageType == "private" {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(userinfo.UserID, accumulatedMessage, selfid)
utils.SendPrivateMessage(userinfo.UserID, accumulatedMessage, selfid, promptstr)
} else {
if IncrementIndex(newmesssage) == 1 {
//第一条信息
Expand All @@ -1170,18 +1174,18 @@ func processMessage(response string, conversationid string, newmesssage string,
ActionButton: 10,
CallbackData: uerid,
}
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE)
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr)
} else {
//SSE的前半部分
messageSSE := structs.InterfaceBody{
Content: accumulatedMessage,
State: 1,
}
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE)
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr)
}
}
} else {
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, accumulatedMessage, selfid)
utils.SendGroupMessage(userinfo.GroupID, userinfo.UserID, accumulatedMessage, selfid, promptstr)
}

ClearMessage(conversationid)
Expand Down
Loading

0 comments on commit 4e2534a

Please sign in to comment.