Skip to content

Commit

Permalink
Beta107 (#105)
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
  • Loading branch information
Hoshinonyaruko authored May 8, 2024
1 parent e3ae99f commit 3ffd466
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 30 deletions.
2 changes: 1 addition & 1 deletion applogic/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (app *App) getHistory(conversationID, parentMessageID string) ([]structs.Me
Role: msg.Role,
Text: msg.Text,
}
fmtf.Printf("加入:%v\n", historyEntry)
//fmtf.Printf("加入:%v\n", historyEntry)
history = append(history, historyEntry)
}
return history, nil
Expand Down
8 changes: 4 additions & 4 deletions applogic/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (app *App) ApplyPromptChoiceQ(promptstr string, requestmsg *string, message
// 获取系统历史,但不包括系统消息
systemHistory, err := prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmt.Printf("Error getting system history: %v\n", err)
fmt.Printf("Error getting system history ApplyPromptChoiceQ: %v\n", err)
return
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func (app *App) ApplyPromptChoiceQ(promptstr string, requestmsg *string, message
// 获取系统历史,但不包括系统消息
systemHistory, err := prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmt.Printf("Error getting system history: %v\n", err)
fmt.Printf("Error getting system history GetMessagesExcludingSystem: %v\n", err)
return
}

Expand Down Expand Up @@ -223,7 +223,7 @@ func (app *App) ApplyPromptCoverQ(promptstr string, requestmsg *string, message
// 获取系统历史,但不包括系统消息
systemHistory, err := prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmt.Printf("Error getting system history: %v\n", err)
fmt.Printf("Error getting system history GetMessagesExcludingSystem: %v\n", err)
return
}

Expand Down Expand Up @@ -593,7 +593,7 @@ func (app *App) ApplyPromptChoiceA(promptstr string, response string, message *s
// 获取系统历史,但不包括系统消息
systemHistory, err := prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmt.Printf("Error getting system history: %v\n", err)
fmt.Printf("Error getting system history GetMessagesExcludingSystem: %v\n", err)
return ""
}

Expand Down
68 changes: 59 additions & 9 deletions applogic/gensokyo.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,15 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {

// MARK: 提示词之间 整体切换Q 当用户没有存档时
app.ProcessPromptMarks(message.UserID, message.Message.(string), &promptstr)
// 初始状态就是 1
err = app.InsertCustomTableRecord(message.UserID, promptstr, 1)
var newstat int
if config.GetPromptMarksLength(promptstr) > 1000 {
newstat = config.GetPromptMarksLength(promptstr)
} else {
newstat = 1
}

// 初始状态就是 1 设置了1000以上长度的是固有场景,不可切换
err = app.InsertCustomTableRecord(message.UserID, promptstr, newstat)
if err != nil {
fmt.Printf("app.InsertCustomTableRecord 出错: %s\n", err)
}
Expand Down Expand Up @@ -566,7 +573,9 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
// 提取response字段
if response, ok = responseData["response"].(string); ok {
// 获取按照关键词补充的PromptChoiceA
EnhancedAContent = app.ApplyPromptChoiceA(promptstr, response, &message)
if config.GetEnhancedQA(promptstr) {
EnhancedAContent = app.ApplyPromptChoiceA(promptstr, response, &message)
}
// 如果accumulatedMessage是response的子串,则提取新的部分并发送
if exists && strings.HasPrefix(response, accumulatedMessage) {
newPart := response[len(accumulatedMessage):]
Expand All @@ -591,7 +600,21 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
utils.SendPrivateMessageSSE(message.UserID, messageSSE)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, newPart, selfid)
if !config.GetMdPromptKeyboardAtGroup() {
// 如果没有 EnhancedAContent
if EnhancedAContent == "" {
utils.SendGroupMessage(message.GroupID, message.UserID, newPart, selfid)
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, EnhancedAContent+response, selfid)
}
} else {
// 如果没有 EnhancedAContent
if EnhancedAContent == "" {
utils.SendGroupMessageMdPromptKeyboard(message.GroupID, message.UserID, response, selfid, newmsg, response, promptstr)
} else {
utils.SendGroupMessageMdPromptKeyboard(message.GroupID, message.UserID, EnhancedAContent+response, selfid, newmsg, response, promptstr)
}
}
}
} else {
//流的最后一次是完整结束的
Expand Down Expand Up @@ -626,12 +649,22 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
utils.SendPrivateMessageSSE(message.UserID, messageSSE)
}
} else {
// 如果没有 EnhancedAContent
if EnhancedAContent == "" {
utils.SendGroupMessage(message.GroupID, message.UserID, response, selfid)
if !config.GetMdPromptKeyboardAtGroup() {
// 如果没有 EnhancedAContent
if EnhancedAContent == "" {
utils.SendGroupMessage(message.GroupID, message.UserID, response, selfid)
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, EnhancedAContent+response, selfid)
}
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, EnhancedAContent+response, selfid)
// 如果没有 EnhancedAContent
if EnhancedAContent == "" {
utils.SendGroupMessageMdPromptKeyboard(message.GroupID, message.UserID, response, selfid, newmsg, response, promptstr)
} else {
utils.SendGroupMessageMdPromptKeyboard(message.GroupID, message.UserID, EnhancedAContent+response, selfid, newmsg, response, promptstr)
}
}

}
}
}
Expand Down Expand Up @@ -684,7 +717,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
if message.RealMessageType == "group_private" || message.MessageType == "private" {
if config.GetUsePrivateSSE() {

//发气泡和按钮
// 发气泡和按钮
var promptkeyboard []string
if !config.GetUseAIPromptkeyboard() {
promptkeyboard = config.GetPromptkeyboard()
Expand All @@ -698,6 +731,21 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
promptkeyboard[i] = acnode.CheckWordOUT(item)
}

// 添加第四个气泡
if config.GetNo4Promptkeyboard() {
RestoreResponses := config.GetRestoreCommand()
if len(RestoreResponses) > 0 {
selectedRestoreResponse := RestoreResponses[rand.Intn(len(RestoreResponses))]
if len(promptkeyboard) > 0 {
// 在promptkeyboard的末尾添加selectedRestoreResponse
promptkeyboard = append(promptkeyboard, selectedRestoreResponse)
} else {
// 如果promptkeyboard为空,我们也应当初始化它,并添加选中的恢复命令
promptkeyboard = []string{selectedRestoreResponse}
}
}
}

//最后一条了
messageSSE := structs.InterfaceBody{
Content: " ",
Expand Down Expand Up @@ -868,6 +916,8 @@ func handleWithdrawMessage(message structs.OnebotGroupMessage) {
id = message.UserID
case "group", "guild":
id = message.GroupID
case "interaction":
id = message.GroupID
default:
fmt.Println("Unsupported message type for withdrawal:", message.RealMessageType)
return
Expand Down
2 changes: 1 addition & 1 deletion applogic/rwkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (app *App) ChatHandlerRwkv(w http.ResponseWriter, r *http.Request) {
// 获取系统级预埋的系统自定义QA对
systemHistory, err := prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("Error getting system history: %v\n", err)
fmtf.Printf("Error getting system history: %v,promptstr[%v]\n", err, promptstr)
return
}

Expand Down
20 changes: 20 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1990,3 +1990,23 @@ func getEnvContentsInternal(options ...string) []string {

return envContents
}

// 群内md气泡
func GetMdPromptKeyboardAtGroup() bool {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return instance.Settings.MdPromptKeyboardAtGroup
}
return false
}

// 第四个气泡
func GetNo4Promptkeyboard() bool {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return instance.Settings.No4Promptkeyboard
}
return false
}
54 changes: 54 additions & 0 deletions structs/markdown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package structs

type RenderData struct {
Label string `json:"label"`
VisitedLabel string `json:"visited_label"`
Style int `json:"style"`
}

type Permission struct {
Type int `json:"type"`
SpecifyRoleIDs []string `json:"specify_role_ids"`
}

type Action struct {
Type int `json:"type"`
Permission Permission `json:"permission"`
ClickLimit int `json:"click_limit"`
UnsupportTips string `json:"unsupport_tips"`
Data string `json:"data"`
AtBotShowChannelList bool `json:"at_bot_show_channel_list"`
Enter bool `json:"enter"` //指令按钮可用,点击按钮后直接自动发送 data,默认 false。支持版本 8983
Reply bool `json:"reply"` //指令按钮可用,指令是否带引用回复本消息,默认 false。支持版本 8983
}

type Button struct {
ID string `json:"id"`
RenderData RenderData `json:"render_data"`
Action Action `json:"action"`
}

type Row struct {
Buttons []Button `json:"buttons"`
}

type KeyboardContent struct {
Rows []Row `json:"rows"`
}

type Keyboard struct {
Content KeyboardContent `json:"content"`
}

type Markdown struct {
Content string `json:"content"`
}

type PromptKeyboardMarkdown struct {
Markdown Markdown `json:"markdown"`
Keyboard Keyboard `json:"keyboard"`
Content string `json:"content"`
MsgID string `json:"msg_id"`
Timestamp string `json:"timestamp"`
MsgType int `json:"msg_type"`
}
32 changes: 17 additions & 15 deletions structs/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,22 @@ type WXFunctionCall struct {
}

type Settings struct {
AllApi bool `yaml:"allApi"`
SecretId string `yaml:"secretId"`
SecretKey string `yaml:"secretKey"`
Region string `yaml:"region"`
UseSse bool `yaml:"useSse"`
Port int `yaml:"port"`
SelfPath string `yaml:"selfPath"`
HttpPath string `yaml:"path"`
Lotus string `yaml:"lotus"`
PathToken string `yaml:"pathToken"`
SystemPrompt []string `yaml:"systemPrompt"`
IPWhiteList []string `yaml:"iPWhiteList"`
ApiType int `yaml:"apiType"`
Proxy string `yaml:"proxy"`
UrlSendPics bool `yaml:"urlSendPics"` //自己构造图床加速图片发送
AllApi bool `yaml:"allApi"`
SecretId string `yaml:"secretId"`
SecretKey string `yaml:"secretKey"`
Region string `yaml:"region"`
UseSse bool `yaml:"useSse"`
Port int `yaml:"port"`
SelfPath string `yaml:"selfPath"`
HttpPath string `yaml:"path"`
Lotus string `yaml:"lotus"`
PathToken string `yaml:"pathToken"`
SystemPrompt []string `yaml:"systemPrompt"`
IPWhiteList []string `yaml:"iPWhiteList"`
ApiType int `yaml:"apiType"`
Proxy string `yaml:"proxy"`
UrlSendPics bool `yaml:"urlSendPics"` // 自己构造图床加速图片发送
MdPromptKeyboardAtGroup bool `yaml:"mdPromptKeyboardAtGroup"` // 群内使用md能力模拟PromptKeyboard

HunyuanType int `yaml:"hunyuanType"`
MaxTokensHunyuan int `yaml:"maxTokensHunyuan"`
Expand Down Expand Up @@ -265,6 +266,7 @@ type Settings struct {
RestoreResponses []string `yaml:"restoreResponses"`
UsePrivateSSE bool `yaml:"usePrivateSSE"`
Promptkeyboard []string `yaml:"promptkeyboard"`
No4Promptkeyboard bool `yaml:"no4Promptkeyboard"`
Savelogs bool `yaml:"savelogs"`
AntiPromptLimit float64 `yaml:"antiPromptLimit"`

Expand Down
Loading

0 comments on commit 3ffd466

Please sign in to comment.