Skip to content

Commit

Permalink
Beta135 (#134)
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
  • Loading branch information
Hoshinonyaruko authored Jun 3, 2024
1 parent 6c89588 commit 89745a2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
38 changes: 30 additions & 8 deletions applogic/gensokyo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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() {

Expand Down Expand Up @@ -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)
}
}

}
}

Expand Down
10 changes: 10 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions structs/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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接入
Expand Down
6 changes: 3 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 89745a2

Please sign in to comment.