mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-08 07:11:06 +00:00
feat: Base URL Setup for OpenAPI-Compatible and Proxy Providers. Adapt Grocq and Azure Setup for it.
This commit is contained in:
parent
ebe0135d5b
commit
e01d355d1b
7
vendors/azure/azure.go
vendored
7
vendors/azure/azure.go
vendored
@ -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
|
||||
}
|
||||
|
||||
|
10
vendors/grocq/grocq.go
vendored
10
vendors/grocq/grocq.go
vendored
@ -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
|
||||
}
|
||||
|
19
vendors/openai/openai.go
vendored
19
vendors/openai/openai.go
vendored
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user