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