Skip to content
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

Fixing missing OrgId assignment issue in the ChatCompletionStream #268

Merged
merged 2 commits into from
Apr 20, 2023
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
14 changes: 14 additions & 0 deletions api_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,47 @@ func TestRequestAuthHeader(t *testing.T) {
APIType APIType
HeaderKey string
Token string
OrgID string
Expect string
}{
{
"OpenAIDefault",
"",
"Authorization",
"dummy-token-openai",
"",
"Bearer dummy-token-openai",
},
{
"OpenAIOrg",
APITypeOpenAI,
"Authorization",
"dummy-token-openai",
"dummy-org-openai",
"Bearer dummy-token-openai",
},
{
"OpenAI",
APITypeOpenAI,
"Authorization",
"dummy-token-openai",
"",
"Bearer dummy-token-openai",
},
{
"AzureAD",
APITypeAzureAD,
"Authorization",
"dummy-token-azure",
"",
"Bearer dummy-token-azure",
},
{
"Azure",
APITypeAzure,
AzureAPIKeyHeader,
"dummy-api-key-here",
"",
"dummy-api-key-here",
},
}
Expand All @@ -78,6 +91,7 @@ func TestRequestAuthHeader(t *testing.T) {
t.Run(c.Name, func(t *testing.T) {
az := DefaultConfig(c.Token)
az.APIType = c.APIType
az.OrgID = c.OrgID

cli := NewClientWithConfig(az)
req, err := cli.newStreamRequest(context.Background(), "POST", "/chat/completions", nil)
Expand Down
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func (c *Client) newStreamRequest(
// OpenAI or Azure AD authentication
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.config.authToken))
}
if c.config.OrgID != "" {
req.Header.Set("OpenAI-Organization", c.config.OrgID)
}
return req, nil
}

Expand Down