added anthropic tool support i think

This commit is contained in:
2025-04-12 03:41:48 -04:00
parent 3093b988f8
commit 916f07be18
7 changed files with 79 additions and 27 deletions

View File

@@ -123,7 +123,6 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
// if this has the same role as the previous message, we can append it to the previous message
// as anthropic expects alternating assistant and user roles
if len(msgs) > 0 && msgs[len(msgs)-1].Role == role {
m2 := &msgs[len(msgs)-1]
@@ -134,16 +133,13 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
}
}
/*
for _, tool := range req.Toolbox.functions {
res.Tools = append(res.Tools, anth.ToolDefinition{
Name: tool.Name,
Description: tool.Description,
InputSchema: tool.Parameters.OpenAIParameters(),
})
}
*/
for _, tool := range req.Toolbox.functions {
res.Tools = append(res.Tools, anth.ToolDefinition{
Name: tool.Name,
Description: tool.Description,
InputSchema: tool.Parameters.AnthropicInputSchema(),
})
}
res.Messages = msgs
@@ -158,15 +154,13 @@ func (a anthropic) requestToAnthropicRequest(req Request) anth.MessagesRequest {
}
func (a anthropic) responseToLLMResponse(in anth.MessagesResponse) Response {
res := Response{}
choice := ResponseChoice{}
for _, msg := range in.Content {
choice := ResponseChoice{}
switch msg.Type {
case anth.MessagesContentTypeText:
if msg.Text != nil {
choice.Content = *msg.Text
choice.Content += *msg.Text
}
case anth.MessagesContentTypeToolUse:
@@ -185,13 +179,13 @@ func (a anthropic) responseToLLMResponse(in anth.MessagesResponse) Response {
}
}
}
res.Choices = append(res.Choices, choice)
}
log.Println("anthropic response to llm response", res)
log.Println("anthropic response to llm response", choice)
return res
return Response{
Choices: []ResponseChoice{choice},
}
}
func (a anthropic) ChatComplete(ctx context.Context, req Request) (Response, error) {