Skip to content

Commit c2b58e7

Browse files
biu7panjiajia
and
panjiajia
authored
Fixing missing OrgId assignment issue in the ChatCompletionStream (sashabaranov#268)
* Update client.go * Add test --------- Co-authored-by: panjiajia <[email protected]>
1 parent ecdea45 commit c2b58e7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

api_internal_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,47 @@ func TestRequestAuthHeader(t *testing.T) {
4242
APIType APIType
4343
HeaderKey string
4444
Token string
45+
OrgID string
4546
Expect string
4647
}{
4748
{
4849
"OpenAIDefault",
4950
"",
5051
"Authorization",
5152
"dummy-token-openai",
53+
"",
54+
"Bearer dummy-token-openai",
55+
},
56+
{
57+
"OpenAIOrg",
58+
APITypeOpenAI,
59+
"Authorization",
60+
"dummy-token-openai",
61+
"dummy-org-openai",
5262
"Bearer dummy-token-openai",
5363
},
5464
{
5565
"OpenAI",
5666
APITypeOpenAI,
5767
"Authorization",
5868
"dummy-token-openai",
69+
"",
5970
"Bearer dummy-token-openai",
6071
},
6172
{
6273
"AzureAD",
6374
APITypeAzureAD,
6475
"Authorization",
6576
"dummy-token-azure",
77+
"",
6678
"Bearer dummy-token-azure",
6779
},
6880
{
6981
"Azure",
7082
APITypeAzure,
7183
AzureAPIKeyHeader,
7284
"dummy-api-key-here",
85+
"",
7386
"dummy-api-key-here",
7487
},
7588
}
@@ -78,6 +91,7 @@ func TestRequestAuthHeader(t *testing.T) {
7891
t.Run(c.Name, func(t *testing.T) {
7992
az := DefaultConfig(c.Token)
8093
az.APIType = c.APIType
94+
az.OrgID = c.OrgID
8195

8296
cli := NewClientWithConfig(az)
8397
req, err := cli.newStreamRequest(context.Background(), "POST", "/chat/completions", nil)

client.go

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func (c *Client) newStreamRequest(
134134
// OpenAI or Azure AD authentication
135135
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.config.authToken))
136136
}
137+
if c.config.OrgID != "" {
138+
req.Header.Set("OpenAI-Organization", c.config.OrgID)
139+
}
137140
return req, nil
138141
}
139142

0 commit comments

Comments
 (0)