Skip to content

Commit

Permalink
Enable use of Azure Endpoints for OpenAI
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS-ovm committed Dec 3, 2024
1 parent 5600877 commit 76322f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions llm/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ import (

// Creates a new OpenAI Provider. The user must pass in the API key, the model
// to use, and the name. The name is used in the subsequent names of all the
// assistants that are created
func NewOpenAIProvider(apiKey string, model string, name string, jsonMode bool) *openAIProvider {
cfg := openai.DefaultConfig(apiKey)
// assistants that are created. Set `azureBaseURL` to enable azure mode
func NewOpenAIProvider(apiKey string, azureBaseURL string, model string, name string, jsonMode bool) *openAIProvider {
var cfg openai.ClientConfig
if azureBaseURL != "" {
cfg = openai.DefaultAzureConfig(apiKey, azureBaseURL)
} else {
cfg = openai.DefaultConfig(apiKey)
}

cfg.HTTPClient = otelhttp.DefaultClient

return &openAIProvider{
Expand Down
2 changes: 1 addition & 1 deletion llm/openai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestNewOpenAIProvider(t *testing.T) {
t.Skip("OPENAI_API_KEY not set")
}

openaiProvider := NewOpenAIProvider(key, openai.GPT4oMini, t.Name(), false)
openaiProvider := NewOpenAIProvider(key, "", openai.GPT4oMini, t.Name(), false)

// Assert that the result matches the provider interface
var _ Provider = openaiProvider
Expand Down

0 comments on commit 76322f0

Please sign in to comment.