Skip to content

Commit

Permalink
feat: #979 add support for configurable base url for Anthropic
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeis committed Sep 20, 2024
1 parent a31af9f commit f4044cd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions vendors/anthropic/anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/liushuangls/go-anthropic/v2"
)

const baseUrl = "https://api.anthropic.com/v1"

func NewClient() (ret *Client) {
vendorName := "Anthropic"
ret = &Client{}
Expand All @@ -20,6 +22,8 @@ func NewClient() (ret *Client) {
ConfigureCustom: ret.configure,
}

ret.ApiBaseURL = ret.AddSetupQuestion("API Base URL", false)
ret.ApiBaseURL.Value = baseUrl
ret.ApiKey = ret.Configurable.AddSetupQuestion("API key", true)

// we could provide a setup question for the following settings
Expand All @@ -36,7 +40,8 @@ func NewClient() (ret *Client) {

type Client struct {
*common.Configurable
ApiKey *common.SetupQuestion
ApiBaseURL *common.SetupQuestion
ApiKey *common.SetupQuestion

maxTokens int
defaultRequiredUserMessage string
Expand All @@ -46,7 +51,11 @@ type Client struct {
}

func (an *Client) configure() (err error) {
an.client = anthropic.NewClient(an.ApiKey.Value)
if an.ApiBaseURL.Value != "" {
an.client = anthropic.NewClient(an.ApiKey.Value, anthropic.WithBaseURL(an.ApiBaseURL.Value))
} else {
an.client = anthropic.NewClient(an.ApiKey.Value)
}
return
}

Expand Down

0 comments on commit f4044cd

Please sign in to comment.