Skip to content

Commit

Permalink
Fixing missing OrgId assignment issue in the ChatCompletionStream (sa…
Browse files Browse the repository at this point in the history
…shabaranov#268)

* Update client.go

* Add test

---------

Co-authored-by: panjiajia <panjiajia@haoshuo.com>
  • Loading branch information
biu7 and panjiajia authored Apr 20, 2023
1 parent ecdea45 commit c2b58e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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 @@ -134,6 +134,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

0 comments on commit c2b58e7

Please sign in to comment.