fix anthropic
This commit is contained in:
parent
dfb768d966
commit
6e2b5a33c0
24
anthropic.go
24
anthropic.go
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
anth "github.com/liushuangls/go-anthropic/v2"
|
||||
@ -25,6 +26,13 @@ func (a anthropic) ModelVersion(modelVersion string) (ChatCompletion, error) {
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func deferClose(c io.Closer) {
|
||||
err := c.Close()
|
||||
if err != nil {
|
||||
slog.Error("error closing", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
res := anth.MessagesRequest{
|
||||
Model: anth.Model(a.model),
|
||||
@ -85,7 +93,7 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
continue
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
defer deferClose(resp.Body)
|
||||
|
||||
img.ContentType = resp.Header.Get("Content-Type")
|
||||
|
||||
@ -121,12 +129,14 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
}
|
||||
}
|
||||
|
||||
for _, tool := range req.Toolbox.funcs {
|
||||
res.Tools = append(res.Tools, anth.ToolDefinition{
|
||||
Name: tool.Name,
|
||||
Description: tool.Description,
|
||||
InputSchema: tool.Parameters,
|
||||
})
|
||||
if req.Toolbox != nil {
|
||||
for _, tool := range req.Toolbox.funcs {
|
||||
res.Tools = append(res.Tools, anth.ToolDefinition{
|
||||
Name: tool.Name,
|
||||
Description: tool.Description,
|
||||
InputSchema: tool.Parameters,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
res.Messages = msgs
|
||||
|
Loading…
x
Reference in New Issue
Block a user