From f4044cde7e0de197b233367497105c609b692cec Mon Sep 17 00:00:00 2001 From: Eugen Eisler Date: Fri, 20 Sep 2024 13:16:49 +0200 Subject: [PATCH] feat: #979 add support for configurable base url for Anthropic --- vendors/anthropic/anthropic.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/vendors/anthropic/anthropic.go b/vendors/anthropic/anthropic.go index 18461cc03..a084b988f 100644 --- a/vendors/anthropic/anthropic.go +++ b/vendors/anthropic/anthropic.go @@ -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{} @@ -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 @@ -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 @@ -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 }