feat: #979 add support for configurable base url for Anthropic

This commit is contained in:
Eugen Eisler 2024-09-20 13:16:49 +02:00
parent a31af9fa80
commit f4044cde7e

View File

@ -10,6 +10,8 @@ import (
"github.com/liushuangls/go-anthropic/v2" "github.com/liushuangls/go-anthropic/v2"
) )
const baseUrl = "https://api.anthropic.com/v1"
func NewClient() (ret *Client) { func NewClient() (ret *Client) {
vendorName := "Anthropic" vendorName := "Anthropic"
ret = &Client{} ret = &Client{}
@ -20,6 +22,8 @@ func NewClient() (ret *Client) {
ConfigureCustom: ret.configure, ConfigureCustom: ret.configure,
} }
ret.ApiBaseURL = ret.AddSetupQuestion("API Base URL", false)
ret.ApiBaseURL.Value = baseUrl
ret.ApiKey = ret.Configurable.AddSetupQuestion("API key", true) ret.ApiKey = ret.Configurable.AddSetupQuestion("API key", true)
// we could provide a setup question for the following settings // we could provide a setup question for the following settings
@ -36,7 +40,8 @@ func NewClient() (ret *Client) {
type Client struct { type Client struct {
*common.Configurable *common.Configurable
ApiKey *common.SetupQuestion ApiBaseURL *common.SetupQuestion
ApiKey *common.SetupQuestion
maxTokens int maxTokens int
defaultRequiredUserMessage string defaultRequiredUserMessage string
@ -46,7 +51,11 @@ type Client struct {
} }
func (an *Client) configure() (err error) { 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 return
} }