Skip to content

Commit

Permalink
feat: Add support for user request parameter (#362)
Browse files Browse the repository at this point in the history
In certain OpenAI Azure setups, the `user` parameter is mandatory in the requests. Failing to include this parameter results in a 422 error code.
This patch introduces a mechanism to add the user parameter, allowing the use of mods in such setups.
I would appreciate your feedback on this change and any suggestions for improvement.
Thank you!
  • Loading branch information
fabio42 authored Sep 27, 2024
1 parent 68e252c commit 34d8469
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type API struct {
Version string `yaml:"version"`
BaseURL string `yaml:"base-url"`
Models map[string]Model `yaml:"models"`
User string `yaml:"user"`
}

// APIs is a type alias to allow custom YAML decoding.
Expand Down Expand Up @@ -175,6 +176,7 @@ type Config struct {
ListRoles bool
Delete string
DeleteOlderThan time.Duration
User string

cacheReadFromID, cacheWriteToID, cacheWriteToTitle string
}
Expand Down
3 changes: 3 additions & 0 deletions mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ func (m *Mods) startCompletionCmd(content string) tea.Cmd {
if mod.API == "azure-ad" {
ccfg.APIType = openai.APITypeAzureAD
}
if api.User != "" {
cfg.User = api.User
}
default:
key, err := m.ensureKey(api, "OPENAI_API_KEY", "https://platform.openai.com/account/api-keys")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (m *Mods) createOpenAIStream(content string, ccfg openai.ClientConfig, mod
Model: mod.Name,
Messages: m.messages,
Stream: true,
User: cfg.User,
}

if mod.API != "perplexity" || !strings.Contains(mod.Name, "online") {
Expand Down

0 comments on commit 34d8469

Please sign in to comment.