Skip to content

Commit

Permalink
fix(v1): 默认toolCall时返回EMPTY RESPONSE错误
Browse files Browse the repository at this point in the history
  • Loading branch information
bincooo committed Sep 11, 2024
1 parent bb25496 commit 36d0336
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ custom-llm:
- base-url: http://127.0.0.1:8080/v1
prefix: custom
use-proxies: false
tc: false

# toolCall 默认配置化; 在 flags 关闭时也可用
toolCall:
Expand Down
4 changes: 3 additions & 1 deletion internal/plugin/llm/v1/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
key = "__custom-url__"
upKey = "__custom-proxies__"
modKey = "__custom-model__"
tcKey = "__custom-toolCall__"
)

type API struct {
Expand Down Expand Up @@ -47,6 +48,7 @@ func (API) Match(ctx *gin.Context, model string) bool {
ctx.Set(key, it["base-url"])
ctx.Set(upKey, it["use-proxies"] == "true")
ctx.Set(modKey, model[len(prefix)+1:])
ctx.Set(tcKey, it["tc"] == "true")
return true
}
}
Expand All @@ -73,7 +75,7 @@ func (API) Completion(ctx *gin.Context) {
)

completion.Model = completion.Model[7:]
if plugin.NeedToToolCall(ctx) {
if ctx.GetBool(tcKey) && plugin.NeedToToolCall(ctx) {
if completeToolCalls(ctx, proxies, completion) {
return
}
Expand Down
8 changes: 4 additions & 4 deletions internal/plugin/llm/v1/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ func waitResponse(ctx *gin.Context, matchers []common.Matcher, r *http.Response,
content += raw
}

if content == "" && response.NotSSEHeader(ctx) {
return
}

if toolCall != nil {
args, _ := json.Marshal(toolCall["args"])
if !sse {
Expand All @@ -201,6 +197,10 @@ func waitResponse(ctx *gin.Context, matchers []common.Matcher, r *http.Response,
return
}

if content == "" && response.NotSSEHeader(ctx) {
return
}

if !sse {
response.Response(ctx, Model, content)
} else {
Expand Down

0 comments on commit 36d0336

Please sign in to comment.