Skip to content

Commit 4c58221

Browse files
feat: anthropic integration added in http transport
1 parent 0709d38 commit 4c58221

File tree

7 files changed

+507
-15
lines changed

7 files changed

+507
-15
lines changed

core/providers/anthropic.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ func prepareAnthropicChatRequest(messages []schemas.BifrostMessage, params *sche
489489
if params != nil && params.ToolChoice != nil {
490490
switch toolChoice := params.ToolChoice.Type; toolChoice {
491491
case schemas.ToolChoiceTypeFunction:
492+
fallthrough
493+
case "tool":
492494
preparedParams["tool_choice"] = map[string]interface{}{
493495
"type": "tool",
494496
"name": params.ToolChoice.Function.Name,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package anthropic
2+
3+
import (
4+
bifrost "github.com/maximhq/bifrost/core"
5+
"github.com/maximhq/bifrost/core/schemas"
6+
"github.com/maximhq/bifrost/transports/bifrost-http/integrations"
7+
)
8+
9+
// AnthropicRouter holds route registrations for Anthropic endpoints.
10+
// It supports standard chat completions and image-enabled vision capabilities.
11+
type AnthropicRouter struct {
12+
*integrations.GenericRouter
13+
}
14+
15+
// NewAnthropicRouter creates a new AnthropicRouter with the given bifrost client.
16+
func NewAnthropicRouter(client *bifrost.Bifrost) *AnthropicRouter {
17+
routes := []integrations.RouteConfig{
18+
{
19+
Path: "/anthropic/v1/messages",
20+
Method: "POST",
21+
GetRequestTypeInstance: func() interface{} {
22+
return &AnthropicMessageRequest{}
23+
},
24+
RequestConverter: func(req interface{}) *schemas.BifrostRequest {
25+
if anthropicReq, ok := req.(*AnthropicMessageRequest); ok {
26+
return anthropicReq.ConvertToBifrostRequest()
27+
}
28+
return nil
29+
},
30+
ResponseFunc: func(resp *schemas.BifrostResponse) interface{} {
31+
return DeriveAnthropicFromBifrostResponse(resp)
32+
},
33+
},
34+
}
35+
36+
return &AnthropicRouter{
37+
GenericRouter: integrations.NewGenericRouter(client, routes),
38+
}
39+
}

0 commit comments

Comments
 (0)