Skip to content

Commit

Permalink
feat: allow to set a baseURL for OpenAI providers
Browse files Browse the repository at this point in the history
This allows to run local models that have a compatible OpenAI API, or
for instance use a proxy.

Signed-off-by: mudler <mudler@mocaccino.org>
  • Loading branch information
mudler committed Apr 20, 2023
1 parent 2102f06 commit 9c2929b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/ai/iai.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type IAI interface {
type IAIConfig interface {
GetPassword() string
GetModel() string
GetBaseURL() string
}

func NewClient(provider string) IAI {
Expand All @@ -35,6 +36,11 @@ type AIProvider struct {
Name string `mapstructure:"name"`
Model string `mapstructure:"model"`
Password string `mapstructure:"password"`
BaseURL string `mapstructure:"base_url"`
}

func (p *AIProvider) GetBaseURL() string {
return p.BaseURL
}

func (p *AIProvider) GetPassword() string {
Expand Down
6 changes: 6 additions & 0 deletions pkg/ai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ type OpenAIClient struct {
func (c *OpenAIClient) Configure(config IAIConfig, language string) error {
token := config.GetPassword()
defaultConfig := openai.DefaultConfig(token)

baseURL := config.GetBaseURL()
if baseURL != "" {
defaultConfig.BaseURL = baseURL
}

client := openai.NewClientWithConfig(defaultConfig)
if client == nil {
return errors.New("error creating OpenAI client")
Expand Down

0 comments on commit 9c2929b

Please sign in to comment.