-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update the config command to set OpenAI deployments. * Add documentation for using Azure OpenAI.
- Loading branch information
Showing
7 changed files
with
334 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package config | ||
|
||
func SetAzureDeployment(cfg *Config, d AzureDeployment) { | ||
if cfg.AzureOpenAI == nil { | ||
cfg.AzureOpenAI = &AzureOpenAIConfig{} | ||
} | ||
if cfg.AzureOpenAI.Deployments == nil { | ||
cfg.AzureOpenAI.Deployments = make([]AzureDeployment, 0, 1) | ||
} | ||
// First check if there is a deployment for the model and if there is update it | ||
for i := range cfg.AzureOpenAI.Deployments { | ||
if cfg.AzureOpenAI.Deployments[i].Model == d.Model { | ||
cfg.AzureOpenAI.Deployments[i].Deployment = d.Deployment | ||
return | ||
} | ||
} | ||
|
||
cfg.AzureOpenAI.Deployments = append(cfg.AzureOpenAI.Deployments, d) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package oai | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/jlewi/foyle/app/pkg/config" | ||
) | ||
|
||
func Test_BuildAzureAIConfig(t *testing.T) { | ||
f, err := os.CreateTemp("", "key.txt") | ||
if err != nil { | ||
t.Fatalf("Error creating temp file: %v", err) | ||
} | ||
if _, err := f.WriteString("somekey"); err != nil { | ||
t.Fatalf("Error writing to temp file: %v", err) | ||
} | ||
|
||
cfg := &config.Config{ | ||
AzureOpenAI: &config.AzureOpenAIConfig{ | ||
APIKeyFile: f.Name(), | ||
BaseURL: "https://someurl.com", | ||
Deployments: []config.AzureDeployment{ | ||
{ | ||
Model: DefaultModel, | ||
Deployment: "somedeployment", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
if err := f.Close(); err != nil { | ||
t.Fatalf("Error closing temp file: %v", err) | ||
} | ||
defer os.Remove(f.Name()) | ||
|
||
clientConfig, err := buildAzureConfig(*cfg) | ||
if err != nil { | ||
t.Fatalf("Error building Azure config: %v", err) | ||
} | ||
|
||
if clientConfig.BaseURL != "https://someurl.com" { | ||
t.Fatalf("Expected BaseURL to be https://someurl.com but got %v", clientConfig.BaseURL) | ||
} | ||
} |
Oops, something went wrong.