Skip to content

Commit

Permalink
fix(you): 删除url中传chats
Browse files Browse the repository at this point in the history
  • Loading branch information
bincooo committed Jul 2, 2024
1 parent b2fb88d commit 60fb6ad
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/bincooo/coze-api v1.0.2-0.20240620163352-ad627f0dffd2
github.com/bincooo/edge-api v1.0.4-0.20240630075039-f55db93af0ab
github.com/bincooo/emit.io v0.0.0-20240701124043-eed97f47e57e
github.com/bincooo/you.com v0.0.0-20240630230515-3db4983fc758
github.com/bincooo/you.com v0.0.0-20240702083541-d8365be42ce9
github.com/dlclark/regexp2 v1.7.0
github.com/eko/gocache/lib/v4 v4.1.6
github.com/eko/gocache/store/go_cache/v4 v4.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/bincooo/edge-api v1.0.4-0.20240630075039-f55db93af0ab h1:X10eWl5imQOM
github.com/bincooo/edge-api v1.0.4-0.20240630075039-f55db93af0ab/go.mod h1:cSJi20GKnl0PCe4UIzxJ8xHZkQy9xGOF7tR/T7aE/9U=
github.com/bincooo/emit.io v0.0.0-20240701124043-eed97f47e57e h1:kJkmi17AvytYm5re5ruyz90vzAvEG4zZY/eeo2MbumY=
github.com/bincooo/emit.io v0.0.0-20240701124043-eed97f47e57e/go.mod h1:TM7ofgLvBROkDM6SWaLduIMYWNiTOvYtRbQy0u4X5SY=
github.com/bincooo/you.com v0.0.0-20240630230515-3db4983fc758 h1:n/cFI9dQGIbnTqlU3ixYiP3Wv49cyED6/l6R8NjnNQM=
github.com/bincooo/you.com v0.0.0-20240630230515-3db4983fc758/go.mod h1:SOuP1CRtNiOr+gYyYsZ/K7pj/Wc6Ko5lT3rFn07yLng=
github.com/bincooo/you.com v0.0.0-20240702083541-d8365be42ce9 h1:MtwqXOos/z1B3z8nkwbOaDjXtsPaM9vrevJfN1rJAtM=
github.com/bincooo/you.com v0.0.0-20240702083541-d8365be42ce9/go.mod h1:SOuP1CRtNiOr+gYyYsZ/K7pj/Wc6Ko5lT3rFn07yLng=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
Expand Down
16 changes: 10 additions & 6 deletions internal/plugin/llm/you/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,16 @@ func (API) Completion(ctx *gin.Context) {
)

completion.Model = completion.Model[4:]
pMessages, currMessage, tokens, err := mergeMessages(ctx, completion)
chats, message, tokens, err := mergeMessages(ctx, completion)
if err != nil {
logger.Error(err)
response.Error(ctx, -1, err)
return
}

if echo {
is32 := tokens < 12000
pM, _ := you.MergeMessages(pMessages, !is32)
response.Echo(ctx, completion.Model, fmt.Sprintf("PREVIOUS MESSAGES:\n%s\n\n\n------\nCURR QUESTION:\n%s", pM, currMessage), completion.Stream)
pM, _ := you.MergeMessages(chats, true)
response.Echo(ctx, completion.Model, fmt.Sprintf("--------FILE MESSAGE--------:\n%s\n\n\n--------CURR QUESTION--------:\n%s", pM, message), completion.Stream)
return
}

Expand Down Expand Up @@ -198,9 +197,14 @@ label:
var cancel chan error
cancel, matchers = joinMatchers(ctx, matchers)
ctx.Set(ginTokens, tokens)
is32 := tokens < 12000

ch, err := chat.Reply(common.GetGinContext(ctx), pMessages, currMessage, !is32)
messages, err := you.MergeMessages(chats, true)
if err != nil {
response.Error(ctx, -1, err)
return
}

ch, err := chat.Reply(common.GetGinContext(ctx), nil, messages, message)
if err != nil {
logger.Error(err)
var se emit.Error
Expand Down
22 changes: 11 additions & 11 deletions internal/plugin/llm/you/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func mergeMessages(ctx *gin.Context, completion pkg.ChatCompletion) (pMessages [
tokens += common.CalcTokens(message.GetString("content"))
}

is32 := tokens < 12000
//is32 := tokens < 12000
// 合并历史对话
iterator := func(opts struct {
Previous string
Expand Down Expand Up @@ -201,16 +201,16 @@ func mergeMessages(ctx *gin.Context, completion pkg.ChatCompletion) (pMessages [

// 获取最后一条用户消息
okey := ""
if is32 {
okey = "ok ~"
messageL := len(newMessages)
message := newMessages[messageL-1]
if message["role"] == "user" {
newMessages = newMessages[:messageL-1]
text = strings.TrimSpace(message["content"])
messageL -= 1
}
}
//if is32 {
// okey = "ok ~"
// messageL := len(newMessages)
// message := newMessages[messageL-1]
// if message["role"] == "user" {
// newMessages = newMessages[:messageL-1]
// text = strings.TrimSpace(message["content"])
// messageL -= 1
// }
//}

// 理论上合并后的上下文不存在相邻的相同消息
pos := 0
Expand Down
4 changes: 1 addition & 3 deletions internal/plugin/llm/you/toolcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ func completeToolCalls(ctx *gin.Context, cookie, proxies string, completion pkg.
}

chat.CloudFlare(clearance, userAgent, lang)
chatResponse, err := chat.Reply(common.GetGinContext(ctx), []you.Message{
{"", message},
}, "Please review the attached prompt", true)
chatResponse, err := chat.Reply(common.GetGinContext(ctx), nil, message, "Please review the attached prompt")
if err != nil {
if strings.Contains(err.Error(), "ZERO QUOTA") {
code = 429
Expand Down

0 comments on commit 60fb6ad

Please sign in to comment.