feat: Base URL Setup for OpenAPI-Compatible and Proxy Providers. Adapt Grocq and Azure Setup for it.

This commit is contained in:
Eugen Eisler 2024-08-21 00:11:18 +02:00
parent ebe0135d5b
commit e01d355d1b
3 changed files with 16 additions and 20 deletions

View File

@ -10,9 +10,7 @@ import (
func NewClient() (ret *Client) {
ret = &Client{}
ret.Client = openai.NewClientCompatible("Azure", ret.configure)
ret.ApiEndpoint = ret.AddSetupQuestion("API endpoint", true)
ret.Client = openai.NewClientCompatible("Azure", "", ret.configure)
ret.ApiDeployments = ret.AddSetupQuestionCustom("deployments", true,
"Enter your Azure deployments (comma separated)")
@ -21,7 +19,6 @@ func NewClient() (ret *Client) {
type Client struct {
*openai.Client
ApiEndpoint *common.SetupQuestion
ApiDeployments *common.SetupQuestion
apiDeployments []string
@ -29,7 +26,7 @@ type Client struct {
func (oi *Client) configure() (err error) {
oi.apiDeployments = strings.Split(oi.ApiDeployments.Value, ",")
oi.ApiClient = goopenai.NewClientWithConfig(goopenai.DefaultAzureConfig(oi.ApiKey.Value, oi.ApiEndpoint.Value))
oi.ApiClient = goopenai.NewClientWithConfig(goopenai.DefaultAzureConfig(oi.ApiKey.Value, oi.ApiBaseURL.Value))
return
}

View File

@ -2,22 +2,14 @@ package grocq
import (
"github.com/danielmiessler/fabric/vendors/openai"
goopenai "github.com/sashabaranov/go-openai"
)
func NewClient() (ret *Client) {
ret = &Client{}
ret.Client = openai.NewClientCompatible("Grocq", ret.configure)
ret.Client = openai.NewClientCompatible("Grocq", "https://api.groq.com/openai/v1", nil)
return
}
type Client struct {
*openai.Client
}
func (oi *Client) configure() (err error) {
config := goopenai.DefaultConfig(oi.ApiKey.Value)
config.BaseURL = "https://api.groq.com/openai/v1"
oi.ApiClient = goopenai.NewClientWithConfig(config)
return
}

View File

@ -13,10 +13,10 @@ import (
)
func NewClient() (ret *Client) {
return NewClientCompatible("OpenAI", nil)
return NewClientCompatible("OpenAI", "https://api.openai.com/v1", nil)
}
func NewClientCompatible(vendorName string, configureCustom func() error) (ret *Client) {
func NewClientCompatible(vendorName string, defaultBaseUrl string, configureCustom func() error) (ret *Client) {
ret = &Client{}
if configureCustom == nil {
@ -29,19 +29,26 @@ func NewClientCompatible(vendorName string, configureCustom func() error) (ret *
ConfigureCustom: configureCustom,
}
ret.ApiKey = ret.AddSetupQuestion("API key", true)
ret.ApiKey = ret.AddSetupQuestion("API Key", true)
ret.ApiBaseURL = ret.AddSetupQuestion("API Base URL", false)
ret.ApiBaseURL.Value = defaultBaseUrl
return
}
type Client struct {
*common.Configurable
ApiKey *common.SetupQuestion
ApiClient *openai.Client
ApiKey *common.SetupQuestion
ApiBaseURL *common.SetupQuestion
ApiClient *openai.Client
}
func (o *Client) configure() (ret error) {
o.ApiClient = openai.NewClient(o.ApiKey.Value)
config := openai.DefaultConfig(o.ApiKey.Value)
if o.ApiBaseURL.Value != "" {
config.BaseURL = o.ApiBaseURL.Value
}
o.ApiClient = openai.NewClientWithConfig(config)
return
}