Skip to content

Commit

Permalink
feat(client): add support for Azure OpenAI API (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila authored May 16, 2023
1 parent db59681 commit 1a91926
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions demos/use-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const clientOptions = {
// Warning: This will expose your `openaiApiKey` to a third party. Consider the risks before using this.
// reverseProxyUrl: 'https://chatgpt.hato.ai/completions',
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
// (Optional) to use Azure OpenAI API, set `azure` to true and `reverseProxyUrl` to your completion endpoint:
// azure: true,
// reverseProxyUrl: 'https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}',
modelOptions: {
// You can override the model name and any other parameters here, like so:
model: 'gpt-3.5-turbo',
Expand Down
5 changes: 4 additions & 1 deletion src/ChatGPTClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ export default class ChatGPTClient {
headersTimeout: 0,
}),
};
if (this.apiKey) {

if (this.apiKey && this.options.azure && this.options.reverseProxyUrl) {
opts.headers['api-key'] = this.apiKey;
} else if (this.apiKey) {
opts.headers.Authorization = `Bearer ${this.apiKey}`;
}

Expand Down

0 comments on commit 1a91926

Please sign in to comment.