Skip to content

Commit

Permalink
fix: 画图参数获取错误
Browse files Browse the repository at this point in the history
  • Loading branch information
bincooo committed May 18, 2024
1 parent e470005 commit 6669f24
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<p align="center">
<h2 align="center">Adapter for ChatGPT</h2>
<p align="center">
一款将免费服务整合到一起的ChatGPT接口服务!
<br/>
一款将免费服务整合到一起的ChatGPT接口服务!<br />
*添加实验性toolCall能力*
</p>
</p>

Expand Down Expand Up @@ -99,6 +99,19 @@ curl -i -X POST \
'http://127.0.0.1:8080/v1/chat/completions'
```

<datails>
<summary> * 效果预览 1 * </summary>
<p>
<img width="451" alt="Screenshot 2024-05-19 at 01 53 05" src="https://github.com/bincooo/chatgpt-adapter/assets/36452456/e055af22-38c4-4a05-bc1b-9f5e9e89beeb">
</p>
</datails>

<datails>
<summary> * 效果预览 2 * </summary>
<p>
<img width="451" alt="Screenshot 2024-05-19 at 01 54 26" src="https://github.com/bincooo/chatgpt-adapter/assets/36452456/a41a15c2-5d81-4029-ad43-72ac7e92e93c">
</p>
</datails>

#### Authorization 获取

Expand Down
2 changes: 1 addition & 1 deletion internal/gin.handler/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func generations(ctx *gin.Context) {
return
}

ctx.Set(vars.GinCompletion, generation)
ctx.Set(vars.GinGeneration, generation)
logrus.Infof("generate images text[ %s ]: %s", generation.Model, generation.Prompt)
if !GlobalExtension.Match(ctx, generation.Model) {
middle.ErrResponse(ctx, -1, fmt.Sprintf("model '%s' is not not yet supported", generation.Model))
Expand Down
2 changes: 1 addition & 1 deletion internal/middle/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (adapter ExtensionAdapter) Completion(ctx *gin.Context) {
}

func (adapter ExtensionAdapter) Generation(ctx *gin.Context) {
completion := common.GetGinCompletion(ctx)
completion := common.GetGinGeneration(ctx)
for _, extension := range adapter.Extensions {
if extension.Match(ctx, completion.Model) {
extension.Generation(ctx)
Expand Down
4 changes: 2 additions & 2 deletions internal/middle/lmsys/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ label:
func mergeMessages(messages []pkg.Keyv[interface{}]) (newMessages string) {
condition := func(expr string) string {
switch expr {
case "system", "user", "function", "assistant":
case "system", "user", "tool", "function", "assistant":
return expr
default:
return ""
Expand All @@ -108,7 +108,7 @@ func mergeMessages(messages []pkg.Keyv[interface{}]) (newMessages string) {
role := message["role"]
if condition(role) == condition(next) {
// cache buffer
if role == "function" {
if role == "function" || role == "tool" {
buffer.WriteString(fmt.Sprintf("这是系统内置tools工具的返回结果: (%s)\n\n##\n%s\n##", message["name"], message["content"]))
return nil
}
Expand Down
5 changes: 0 additions & 5 deletions internal/middle/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import (
var (
stop = "stop"
toolCalls = "tool_calls"
delta = &struct {
Role string `json:"role"`
Content string `json:"content"`
ToolCalls []pkg.Keyv[interface{}] `json:"tool_calls"`
}{}
)

func MessageValidator(ctx *gin.Context) bool {
Expand Down
15 changes: 15 additions & 0 deletions internal/middle/toolcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,20 @@ func parseToToolCall(ctx *gin.Context, content string, req pkg.ChatCompletion) b
}

func ToolCallCancel(str string) bool {
if strings.HasPrefix(str, "<|tool|>") {
return true
}
if strings.HasPrefix(str, "<|assistant|>") {
return true
}
if strings.HasPrefix(str, "<|user|>") {
return true
}
if strings.HasPrefix(str, "<|system|>") {
return true
}
if strings.HasPrefix(str, "<|end|>") {
return true
}
return len(str) > 1 && !strings.HasPrefix(str, "1:")
}

0 comments on commit 6669f24

Please sign in to comment.