Skip to content

Commit

Permalink
Beta155 (#154)
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

* beta139

* beta140

* beta141

* beta142

* beta143

* beta144

* beta145

* beta146

* beta148

* beta149

* beta150

* beta151

* beta151

* beta152

* beta154

* beta155
  • Loading branch information
Hoshinonyaruko authored Jun 20, 2024
1 parent 8b3aa09 commit eece40b
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 41 deletions.
2 changes: 1 addition & 1 deletion applogic/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (app *App) HandleExit(exitText string, message *structs.OnebotGroupMessage,
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, RestoreResponse, selfid, promptstr)
} else {
utils.SendSSEPrivateRestoreMessage(message.UserID, RestoreResponse, promptstr)
utils.SendSSEPrivateRestoreMessage(message.UserID, RestoreResponse, promptstr, selfid)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, RestoreResponse, selfid, promptstr)
Expand Down
31 changes: 20 additions & 11 deletions applogic/gensokyo.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, RestoreResponse, selfid, promptstr)
} else {
utils.SendSSEPrivateRestoreMessage(message.UserID, RestoreResponse, promptstr)
utils.SendSSEPrivateRestoreMessage(message.UserID, RestoreResponse, promptstr, selfid)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, RestoreResponse, selfid, promptstr)
Expand Down Expand Up @@ -490,7 +490,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, responseText, selfid, promptstr)
} else {
utils.SendSSEPrivateMessage(message.UserID, responseText, promptstr)
utils.SendSSEPrivateMessage(message.UserID, responseText, promptstr, selfid)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, responseText, selfid, promptstr)
Expand Down Expand Up @@ -535,7 +535,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, saveresponse, selfid, promptstr)
} else {
utils.SendSSEPrivateSafeMessage(message.UserID, saveresponse, promptstr)
utils.SendSSEPrivateSafeMessage(message.UserID, saveresponse, promptstr, selfid)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, saveresponse, selfid, promptstr)
Expand Down Expand Up @@ -727,6 +727,15 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {

// 初始化URL,根据api参数动态调整路径
basePath := "/conversation"

//MARK:能定义每个yml自己要调用的conversation端点
newPath := config.GetConversationPath(promptstr)
// 允许覆盖请求不同的conversation
if newPath != "/conversation" && newPath != "" {
fmtf.Printf("覆盖api参数: %s\n", newPath)
basePath = newPath // 动态替换conversation部分为ConversationPath,这个配置是包含了/的
}

if api != "" {
fmtf.Printf("收到api参数: %s\n", api)
basePath = "/" + api // 动态替换conversation部分为api参数值
Expand Down Expand Up @@ -839,15 +848,15 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
//判断是否最后一条
var state int
if EnhancedAContent == "" {
state = 11
state = 11 //结束
} else {
state = 1
state = 1 //继续
}
messageSSE := structs.InterfaceBody{
Content: newPart,
State: state,
}
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr)
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr, selfid)
}
} else {
// 这里发送的是newPart api最后补充的部分
Expand Down Expand Up @@ -897,7 +906,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
Content: response,
State: state,
}
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr)
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr, selfid)
}
} else {
if !config.GetMdPromptKeyboardAtGroup() {
Expand Down Expand Up @@ -953,7 +962,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
Content: EnhancedAContent,
State: 11,
}
utils.SendPrivateMessageSSE(message.UserID, messageSSE, promptstr)
utils.SendPrivateMessageSSE(message.UserID, messageSSE, promptstr, selfid)
}
}
}
Expand Down Expand Up @@ -1032,7 +1041,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
State: 20,
PromptKeyboard: promptkeyboard,
}
utils.SendPrivateMessageSSE(message.UserID, messageSSE, promptstr)
utils.SendPrivateMessageSSE(message.UserID, messageSSE, promptstr, selfid)
ResetIndex(newmsg)
}
}
Expand Down Expand Up @@ -1187,14 +1196,14 @@ func processMessage(response string, conversationid string, newmesssage string,
ActionButton: 10,
CallbackData: uerid,
}
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr)
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr, selfid)
} else {
//SSE的前半部分
messageSSE := structs.InterfaceBody{
Content: accumulatedMessage,
State: 1,
}
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr)
utils.SendPrivateMessageSSE(userinfo.UserID, messageSSE, promptstr, selfid)
}
}
} else {
Expand Down
9 changes: 6 additions & 3 deletions applogic/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ func (app *App) handleLoadMemory(msg structs.OnebotGroupMessage, checkResetComma
// 移除空格得到匹配词
matchTerm := strings.TrimSpace(checkResetCommand)

// 判断处理过的字符串是否以"+"开头 移除+号
matchTerm = strings.TrimPrefix(matchTerm, "+")

// 获取用户记忆
memories, err := app.GetUserMemories(userid)
if err != nil {
Expand Down Expand Up @@ -244,7 +247,7 @@ func (app *App) sendMemoryResponseWithkeyBoard(msg structs.OnebotGroupMessage, r
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(msg.UserID, response, strSelfID, promptstr)
} else {
utils.SendSSEPrivateMessageWithKeyboard(msg.UserID, response, keyboard, promptstr)
utils.SendSSEPrivateMessageWithKeyboard(msg.UserID, response, keyboard, promptstr, strSelfID)
}
} else {
utils.SendGroupMessage(msg.GroupID, msg.UserID, response, strSelfID, promptstr)
Expand All @@ -257,7 +260,7 @@ func (app *App) sendMemoryResponse(msg structs.OnebotGroupMessage, response stri
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(msg.UserID, response, strSelfID, promptstr)
} else {
utils.SendSSEPrivateMessage(msg.UserID, response, promptstr)
utils.SendSSEPrivateMessage(msg.UserID, response, promptstr, strSelfID)
}
} else {
utils.SendGroupMessage(msg.GroupID, msg.UserID, response, strSelfID, promptstr)
Expand All @@ -274,7 +277,7 @@ func (app *App) sendMemoryResponseByline(msg structs.OnebotGroupMessage, respons
if len(keyboard) >= 3 {
keyboard = keyboard[:3]
}
utils.SendSSEPrivateMessageByLine(msg.UserID, response, keyboard, promptstr)
utils.SendSSEPrivateMessageByLine(msg.UserID, response, keyboard, promptstr, strSelfID)
}
} else {
if config.GetMemoryListMD() == 0 {
Expand Down
2 changes: 1 addition & 1 deletion applogic/vectorsensitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (app *App) InterceptSensitiveContent(vector []float64, message structs.Oneb
if !config.GetUsePrivateSSE() {
utils.SendPrivateMessage(message.UserID, saveresponse, selfid, promptstr)
} else {
utils.SendSSEPrivateSafeMessage(message.UserID, saveresponse, promptstr)
utils.SendSSEPrivateSafeMessage(message.UserID, saveresponse, promptstr, selfid)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, saveresponse, selfid, promptstr)
Expand Down
44 changes: 44 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3386,3 +3386,47 @@ func getSpecialNameToQInternal(options ...string) []structs.ReplacementNamePair

return confs
}

// GetConversationPath 获取ConversationPath,可接受basename作为参数
func GetConversationPath(options ...string) string {
mu.Lock()
defer mu.Unlock()
return getConversationPathInternal(options...)
}

// getTyqwApiPathInternal 内部逻辑执行函数,不处理锁,可以安全地递归调用
func getConversationPathInternal(options ...string) string {
// 检查是否有参数传递进来,以及是否为空字符串
if len(options) == 0 || options[0] == "" {
if instance != nil {
ConversationPath := instance.Settings.ConversationPath
if ConversationPath != "" {
return ConversationPath
} else {
return "/conversation" // 默认值 /conversation
}
}
// instance未加载
return "/conversation" // 默认值 /conversation
}

// 使用传入的 basename
basename := options[0]
ConversationPathInterface, err := prompt.GetSettingFromFilename(basename, "ConversationPath")
if err != nil {
log.Println("Error retrieving ConversationPath:", err)
return getConversationPathInternal() // 递归调用内部函数,不传递任何参数
}

ConversationPath, ok := ConversationPathInterface.(string)
if !ok { // 检查类型断言是否失败
log.Println("Type assertion failed for ConversationPath, fetching default")
return getConversationPathInternal() // 递归调用内部函数,不传递任何参数
}

if ConversationPath == "" {
return getConversationPathInternal()
}

return ConversationPath
}
1 change: 1 addition & 0 deletions structs/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ type Settings struct {
SelfPath string `yaml:"selfPath"`
HttpPath string `yaml:"path"`
HttpPaths []string `yaml:"paths"`
ConversationPath string `yaml:"conversationPath"`
Lotus string `yaml:"lotus"`
PathToken string `yaml:"pathToken"`
SystemPrompt []string `yaml:"systemPrompt"`
Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ settings:
selfPath : "" #本程序监听地址,不包含http头,请放通port到公网,仅发图场景需要填写,可以是域名,暂不支持https.
path : "http://123.123.123.123:11111" #调用gensokyo api的地址,填入 gensokyo 的 正向http地址 http_address: "0.0.0.0:46231" 对应填入 "http://127.0.0.1:46231"
paths : [] #当要连接多个onebotv11的http正向地址时,多个地址填入这里.
conversationPath : "/conversation" #所请求的conversation端口,在当前配置下不需要修改,在prompts文件夹中的promptstr=xxx xxx.yml中,可选用conversation_xxx n种不同的api(main.go 172行查看) 需打开allApi=true
lotus : "" #当填写另一个gensokyo-llm的http地址时,将请求另一个的conversation端点,实现多个llm不需要多次配置,简化配置,单独使用请忽略留空.例:http://192.168.0.1:12345(包含http头和端口)
pathToken : "" #gensokyo正向http-api的access_token(是onebotv11标准的)
apiType : 0 #0=混元 1=文心(文心平台包含了N种模型...) 2=gpt 3=rwkv 4=通义千问 5=智谱AI 6=腾讯元器
Expand Down
4 changes: 2 additions & 2 deletions utils/blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func BlacklistIntercept(message structs.OnebotGroupMessage, selfid string, promp
if !config.GetUsePrivateSSE() {
SendPrivateMessage(message.UserID, responseMessage, selfid, promptstr)
} else {
SendSSEPrivateMessage(message.UserID, responseMessage, promptstr)
SendSSEPrivateMessage(message.UserID, responseMessage, promptstr, selfid)
}
} else {
SendGroupMessage(message.GroupID, message.UserID, responseMessage, selfid, promptstr)
Expand All @@ -124,7 +124,7 @@ func BlacklistIntercept(message structs.OnebotGroupMessage, selfid string, promp
if !config.GetUsePrivateSSE() {
SendPrivateMessage(message.UserID, responseMessage, selfid, promptstr)
} else {
SendSSEPrivateMessage(message.UserID, responseMessage, promptstr)
SendSSEPrivateMessage(message.UserID, responseMessage, promptstr, selfid)
}
} else {
SendGroupMessage(message.GroupID, message.UserID, responseMessage, selfid, promptstr)
Expand Down
Loading

0 comments on commit eece40b

Please sign in to comment.