Skip to content

Commit

Permalink
Merge f8eadf5 into ffa8ad3
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko authored May 23, 2024
2 parents ffa8ad3 + f8eadf5 commit c90e305
Show file tree
Hide file tree
Showing 11 changed files with 743 additions and 15 deletions.
6 changes: 3 additions & 3 deletions applogic/chatglm.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ func truncateHistoryGlm(history []structs.Message, prompt string, promptstr stri
}
}

// 确保以user结尾,如果不是则尝试移除直到满足条件
if len(history) > 0 && history[len(history)-1].Role != "user" {
for len(history) > 0 && history[len(history)-1].Role != "user" {
// 第三步:确保以assistant结尾
if len(history) > 0 && history[len(history)-1].Role == "user" {
for len(history) > 0 && history[len(history)-1].Role != "assistant" {
history = history[:len(history)-1]
}
}
Expand Down
7 changes: 4 additions & 3 deletions applogic/chatgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ func truncateHistoryGpt(history []structs.Message, prompt string, promptstr stri
for _, msg := range history {
tokenCount += len(msg.Text)
}
fmt.Printf("测试:%v\n", history)

if tokenCount >= MAX_TOKENS {
// 第一步:从开始逐个移除消息,直到满足令牌数量限制
Expand Down Expand Up @@ -544,9 +545,9 @@ func truncateHistoryGpt(history []structs.Message, prompt string, promptstr stri
}
}

// 确保以user结尾,如果不是则尝试移除直到满足条件
if len(history) > 0 && history[len(history)-1].Role != "user" {
for len(history) > 0 && history[len(history)-1].Role != "user" {
// 第三步:确保以assistant结尾
if len(history) > 0 && history[len(history)-1].Role == "user" {
for len(history) > 0 && history[len(history)-1].Role != "assistant" {
history = history[:len(history)-1]
}
}
Expand Down
4 changes: 2 additions & 2 deletions applogic/gensokyo.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
urlParams.Add("prompt", promptstr)
}

// glm会根据userid参数来封禁用户
if config.GetApiType() == 5 || basePath == "/conversation_glm" {
// 元器和glm会根据userid参数来自动封禁用户
if config.GetApiType() == 5 || basePath == "/conversation_glm" || config.GetApiType() == 6 || basePath == "/conversation_yq" {
urlParams.Add("userid", strconv.FormatInt(message.UserID, 10))
}

Expand Down
6 changes: 3 additions & 3 deletions applogic/rwkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,9 @@ func truncateHistoryRwkv(history []structs.Message, prompt string, promptstr str
}
}

// 确保以user结尾,如果不是则尝试移除直到满足条件
if len(history) > 0 && history[len(history)-1].Role != "user" {
for len(history) > 0 && history[len(history)-1].Role != "user" {
// 第三步:确保以assistant结尾
if len(history) > 0 && history[len(history)-1].Role == "user" {
for len(history) > 0 && history[len(history)-1].Role != "assistant" {
history = history[:len(history)-1]
}
}
Expand Down
6 changes: 3 additions & 3 deletions applogic/tongyiqianwen.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,9 @@ func truncateHistoryTyqw(history []structs.Message, prompt string, promptstr str
}
}

// 确保以user结尾,如果不是则尝试移除直到满足条件
if len(history) > 0 && history[len(history)-1].Role != "user" {
for len(history) > 0 && history[len(history)-1].Role != "user" {
// 第三步:确保以assistant结尾
if len(history) > 0 && history[len(history)-1].Role == "user" {
for len(history) > 0 && history[len(history)-1].Role != "assistant" {
history = history[:len(history)-1]
}
}
Expand Down
Loading

0 comments on commit c90e305

Please sign in to comment.