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) {
|
func NewClient() (ret *Client) {
|
||||||
ret = &Client{}
|
ret = &Client{}
|
||||||
ret.Client = openai.NewClientCompatible("Azure", ret.configure)
|
ret.Client = openai.NewClientCompatible("Azure", "", ret.configure)
|
||||||
|
|
||||||
ret.ApiEndpoint = ret.AddSetupQuestion("API endpoint", true)
|
|
||||||
ret.ApiDeployments = ret.AddSetupQuestionCustom("deployments", true,
|
ret.ApiDeployments = ret.AddSetupQuestionCustom("deployments", true,
|
||||||
"Enter your Azure deployments (comma separated)")
|
"Enter your Azure deployments (comma separated)")
|
||||||
|
|
||||||
@ -21,7 +19,6 @@ func NewClient() (ret *Client) {
|
|||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
*openai.Client
|
*openai.Client
|
||||||
ApiEndpoint *common.SetupQuestion
|
|
||||||
ApiDeployments *common.SetupQuestion
|
ApiDeployments *common.SetupQuestion
|
||||||
|
|
||||||
apiDeployments []string
|
apiDeployments []string
|
||||||
@ -29,7 +26,7 @@ type Client struct {
|
|||||||
|
|
||||||
func (oi *Client) configure() (err error) {
|
func (oi *Client) configure() (err error) {
|
||||||
oi.apiDeployments = strings.Split(oi.ApiDeployments.Value, ",")
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
vendors/grocq/grocq.go
vendored
10
vendors/grocq/grocq.go
vendored
@ -2,22 +2,14 @@ package grocq
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/danielmiessler/fabric/vendors/openai"
|
"github.com/danielmiessler/fabric/vendors/openai"
|
||||||
goopenai "github.com/sashabaranov/go-openai"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewClient() (ret *Client) {
|
func NewClient() (ret *Client) {
|
||||||
ret = &Client{}
|
ret = &Client{}
|
||||||
ret.Client = openai.NewClientCompatible("Grocq", ret.configure)
|
ret.Client = openai.NewClientCompatible("Grocq", "https://api.groq.com/openai/v1", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
*openai.Client
|
*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) {
|
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{}
|
ret = &Client{}
|
||||||
|
|
||||||
if configureCustom == nil {
|
if configureCustom == nil {
|
||||||
@ -29,19 +29,26 @@ func NewClientCompatible(vendorName string, configureCustom func() error) (ret *
|
|||||||
ConfigureCustom: configureCustom,
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
*common.Configurable
|
*common.Configurable
|
||||||
ApiKey *common.SetupQuestion
|
ApiKey *common.SetupQuestion
|
||||||
ApiClient *openai.Client
|
ApiBaseURL *common.SetupQuestion
|
||||||
|
ApiClient *openai.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Client) configure() (ret error) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user