Skip to content

Commit

Permalink
Merge 48c8496 into 6ad461d
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko authored Apr 20, 2024
2 parents 6ad461d + 48c8496 commit 2a50ea3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 8 additions & 2 deletions applogic/chatgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,15 @@ func (app *App) ChatHandlerChatgpt(w http.ResponseWriter, r *http.Request) {

newContent := ""
for _, choice := range eventData.Choices {
// 如果新内容以旧内容开头
if strings.HasPrefix(choice.Delta.Content, lastResponseText) {
// 如果新内容以旧内容开头,剔除旧内容部分,只保留新增的部分
newContent += choice.Delta.Content[len(lastResponseText):]
// 特殊情况:当新内容和旧内容完全相同时,处理逻辑应当与新内容不以旧内容开头时相同
if choice.Delta.Content == lastResponseText {
newContent += choice.Delta.Content
} else {
// 剔除旧内容部分,只保留新增的部分
newContent += choice.Delta.Content[len(lastResponseText):]
}
} else {
// 如果新内容不以旧内容开头,可能是并发情况下的新消息,直接使用新内容
newContent += choice.Delta.Content
Expand Down
10 changes: 8 additions & 2 deletions applogic/rwkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,15 @@ func (app *App) ChatHandlerRwkv(w http.ResponseWriter, r *http.Request) {

newContent := ""
for _, choice := range eventData.Choices {
// 如果新内容以旧内容开头
if strings.HasPrefix(choice.Delta.Content, lastResponseText) {
// 如果新内容以旧内容开头,剔除旧内容部分,只保留新增的部分
newContent += choice.Delta.Content[len(lastResponseText):]
// 特殊情况:当新内容和旧内容完全相同时,处理逻辑应当与新内容不以旧内容开头时相同
if choice.Delta.Content == lastResponseText {
newContent += choice.Delta.Content
} else {
// 剔除旧内容部分,只保留新增的部分
newContent += choice.Delta.Content[len(lastResponseText):]
}
} else {
// 如果新内容不以旧内容开头,可能是并发情况下的新消息,直接使用新内容
newContent += choice.Delta.Content
Expand Down
6 changes: 6 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ func SendGroupMessage(groupID int64, userID int64, message string, selfid string
message = acnode.CheckWordOUT(message)
}

// 去除末尾的换行符 不去除会导致不好看
message = removeTrailingCRLFs(message)

// 构造请求体
requestBody, err := json.Marshal(map[string]interface{}{
"group_id": groupID,
Expand Down Expand Up @@ -272,6 +275,9 @@ func SendPrivateMessage(UserID int64, message string, selfid string) error {
message = acnode.CheckWordOUT(message)
}

// 去除末尾的换行符 不去除会导致不好看
message = removeTrailingCRLFs(message)

// 构造请求体
requestBody, err := json.Marshal(map[string]interface{}{
"user_id": UserID,
Expand Down

0 comments on commit 2a50ea3

Please sign in to comment.