Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
f4e9082ce4 |
17
anthropic.go
17
anthropic.go
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
anth "github.com/liushuangls/go-anthropic/v2"
|
||||
@ -26,13 +25,6 @@ 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),
|
||||
@ -71,11 +63,6 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
}
|
||||
|
||||
for _, img := range msg.Images {
|
||||
// anthropic doesn't allow the assistant to send images, so we need to say it's from the user
|
||||
if m.Role == anth.RoleAssistant {
|
||||
m.Role = anth.RoleUser
|
||||
}
|
||||
|
||||
if img.Base64 != "" {
|
||||
m.Content = append(m.Content, anth.NewImageMessageContent(
|
||||
anth.NewMessageContentSource(
|
||||
@ -98,7 +85,7 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
continue
|
||||
}
|
||||
|
||||
defer deferClose(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
|
||||
img.ContentType = resp.Header.Get("Content-Type")
|
||||
|
||||
@ -134,7 +121,6 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
}
|
||||
}
|
||||
|
||||
if req.Toolbox != nil {
|
||||
for _, tool := range req.Toolbox.funcs {
|
||||
res.Tools = append(res.Tools, anth.ToolDefinition{
|
||||
Name: tool.Name,
|
||||
@ -142,7 +128,6 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
|
||||
InputSchema: tool.Parameters,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
res.Messages = msgs
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.23.1
|
||||
require (
|
||||
github.com/google/generative-ai-go v0.19.0
|
||||
github.com/liushuangls/go-anthropic/v2 v2.13.0
|
||||
github.com/sashabaranov/go-openai v1.36.1
|
||||
github.com/sashabaranov/go-openai v1.36.0
|
||||
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
|
||||
google.golang.org/api v0.214.0
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -39,8 +39,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sashabaranov/go-openai v1.36.0 h1:fcSrn8uGuorzPWCBp8L0aCR95Zjb/Dd+ZSML0YZy9EI=
|
||||
github.com/sashabaranov/go-openai v1.36.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
||||
github.com/sashabaranov/go-openai v1.36.1 h1:EVfRXwIlW2rUzpx6vR+aeIKCK/xylSrVYAx1TMTSX3g=
|
||||
github.com/sashabaranov/go-openai v1.36.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
|
@ -3,9 +3,8 @@ package go_llm
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
oai "github.com/sashabaranov/go-openai"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type openaiImpl struct {
|
||||
@ -58,7 +57,6 @@ func (o openaiImpl) requestToOpenAIRequest(request Request) oai.ChatCompletionRe
|
||||
res.Messages = append(res.Messages, m)
|
||||
}
|
||||
|
||||
if request.Toolbox != nil {
|
||||
for _, tool := range request.Toolbox.funcs {
|
||||
res.Tools = append(res.Tools, oai.Tool{
|
||||
Type: "function",
|
||||
@ -72,7 +70,6 @@ func (o openaiImpl) requestToOpenAIRequest(request Request) oai.ChatCompletionRe
|
||||
|
||||
fmt.Println("tool:", tool.Name, tool.Description, tool.Strict, tool.Parameters.Definition())
|
||||
}
|
||||
}
|
||||
|
||||
if request.Temperature != nil {
|
||||
res.Temperature = *request.Temperature
|
||||
|
Loading…
x
Reference in New Issue
Block a user