Skip to content

chore: remove broken builtin support for azure gpt models in favor of external providers #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ Download and install the archive for your platform and architecture from the [re
export OPENAI_API_KEY="your-api-key"
```

Alternatively Azure OpenAI can be utilized. If the [Azure deployment name is different than the model being used](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints#keyword-argument-for-model), be sure to include the `OPENAI_AZURE_DEPLOYMENT` argument.

```shell
export OPENAI_API_KEY="your-api-key"
export OPENAI_BASE_URL="https://<your-endpoint>.openai.azure.com/"
export OPENAI_API_TYPE="AZURE"
export OPENAI_AZURE_DEPLOYMENT="<your-deployment-name>"
```

#### Windows

```powershell
Expand All @@ -118,9 +109,7 @@ OUTPUT:
Hello, World!
```

The model used by default is `gpt-4-turbo` and you must have access to that model in your OpenAI account.

If using Azure OpenAI, make sure you configure the model to be one of the supported versions with the `--default-model` argument.
The model used by default is `gpt-4o` and you must have access to that model in your OpenAI account.

### 4. Extra Credit: Examples and Run Debugging UI

Expand Down
13 changes: 1 addition & 12 deletions docs/docs/02-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ Download and install the archive for your platform and architecture from the [re
export OPENAI_API_KEY="your-api-key"
```

Alternatively Azure OpenAI can be utilized. If the [Azure deployment name is different than the model being used](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints#keyword-argument-for-model), be sure to include the `OPENAI_AZURE_DEPLOYMENT` argument.

```shell
export OPENAI_API_KEY="your-api-key"
export OPENAI_BASE_URL="https://<your-endpoint>.openai.azure.com/"
export OPENAI_API_TYPE="AZURE"
export OPENAI_AZURE_DEPLOYMENT="<your-deployment-name>"
```

#### Windows

```powershell
Expand All @@ -59,9 +50,7 @@ OUTPUT:
Hello, World!
```

The model used by default is `gpt-4-turbo` and you must have access to that model in your OpenAI account.

If using Azure OpenAI, make sure you configure the model to be one of the supported versions with the `--default-model` argument.
The model used by default is `gpt-4o` and you must have access to that model in your OpenAI account.

### 4. Extra Credit: Examples and Run Debugging UI

Expand Down
43 changes: 9 additions & 34 deletions pkg/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ const (
)

var (
key = os.Getenv("OPENAI_API_KEY")
url = os.Getenv("OPENAI_URL")
azureModel = os.Getenv("OPENAI_AZURE_DEPLOYMENT")
key = os.Getenv("OPENAI_API_KEY")
url = os.Getenv("OPENAI_URL")
)

type Client struct {
Expand All @@ -38,15 +37,13 @@ type Client struct {
}

type Options struct {
BaseURL string `usage:"OpenAI base URL" name:"openai-base-url" env:"OPENAI_BASE_URL"`
APIKey string `usage:"OpenAI API KEY" name:"openai-api-key" env:"OPENAI_API_KEY"`
APIVersion string `usage:"OpenAI API Version (for Azure)" name:"openai-api-version" env:"OPENAI_API_VERSION"`
APIType openai.APIType `usage:"OpenAI API Type (valid: OPEN_AI, AZURE, AZURE_AD)" name:"openai-api-type" env:"OPENAI_API_TYPE"`
OrgID string `usage:"OpenAI organization ID" name:"openai-org-id" env:"OPENAI_ORG_ID"`
DefaultModel string `usage:"Default LLM model to use" default:"gpt-4o"`
ConfigFile string `usage:"Path to GPTScript config file" name:"config"`
SetSeed bool `usage:"-"`
CacheKey string `usage:"-"`
BaseURL string `usage:"OpenAI base URL" name:"openai-base-url" env:"OPENAI_BASE_URL"`
APIKey string `usage:"OpenAI API KEY" name:"openai-api-key" env:"OPENAI_API_KEY"`
OrgID string `usage:"OpenAI organization ID" name:"openai-org-id" env:"OPENAI_ORG_ID"`
DefaultModel string `usage:"Default LLM model to use" default:"gpt-4o"`
ConfigFile string `usage:"Path to GPTScript config file" name:"config"`
SetSeed bool `usage:"-"`
CacheKey string `usage:"-"`
Cache *cache.Client
}

Expand All @@ -56,8 +53,6 @@ func complete(opts ...Options) (result Options, err error) {
result.APIKey = types.FirstSet(opt.APIKey, result.APIKey)
result.OrgID = types.FirstSet(opt.OrgID, result.OrgID)
result.Cache = types.FirstSet(opt.Cache, result.Cache)
result.APIVersion = types.FirstSet(opt.APIVersion, result.APIVersion)
result.APIType = types.FirstSet(opt.APIType, result.APIType)
result.DefaultModel = types.FirstSet(opt.DefaultModel, result.DefaultModel)
result.SetSeed = types.FirstSet(opt.SetSeed, result.SetSeed)
result.CacheKey = types.FirstSet(opt.CacheKey, result.CacheKey)
Expand All @@ -80,35 +75,15 @@ func complete(opts ...Options) (result Options, err error) {
return result, err
}

func GetAzureMapperFunction(defaultModel, azureModel string) func(string) string {
if azureModel == "" {
return func(model string) string {
return model
}
}
return func(model string) string {
return map[string]string{
defaultModel: azureModel,
}[model]
}
}

func NewClient(opts ...Options) (*Client, error) {
opt, err := complete(opts...)
if err != nil {
return nil, err
}

cfg := openai.DefaultConfig(opt.APIKey)
if strings.Contains(string(opt.APIType), "AZURE") {
cfg = openai.DefaultAzureConfig(key, url)
cfg.AzureModelMapperFunc = GetAzureMapperFunction(opt.DefaultModel, azureModel)
}

cfg.BaseURL = types.FirstSet(opt.BaseURL, cfg.BaseURL)
cfg.OrgID = types.FirstSet(opt.OrgID, cfg.OrgID)
cfg.APIVersion = types.FirstSet(opt.APIVersion, cfg.APIVersion)
cfg.APIType = types.FirstSet(opt.APIType, cfg.APIType)

cacheKeyBase := opt.CacheKey
if cacheKeyBase == "" {
Expand Down