Skip to content

Commit 1a91926

Browse files
authored
feat(client): add support for Azure OpenAI API (#361)
1 parent db59681 commit 1a91926

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

demos/use-client.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const clientOptions = {
88
// Warning: This will expose your `openaiApiKey` to a third party. Consider the risks before using this.
99
// reverseProxyUrl: 'https://chatgpt.hato.ai/completions',
1010
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
11+
// (Optional) to use Azure OpenAI API, set `azure` to true and `reverseProxyUrl` to your completion endpoint:
12+
// azure: true,
13+
// reverseProxyUrl: 'https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}',
1114
modelOptions: {
1215
// You can override the model name and any other parameters here, like so:
1316
model: 'gpt-3.5-turbo',

src/ChatGPTClient.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ export default class ChatGPTClient {
170170
headersTimeout: 0,
171171
}),
172172
};
173-
if (this.apiKey) {
173+
174+
if (this.apiKey && this.options.azure && this.options.reverseProxyUrl) {
175+
opts.headers['api-key'] = this.apiKey;
176+
} else if (this.apiKey) {
174177
opts.headers.Authorization = `Bearer ${this.apiKey}`;
175178
}
176179

0 commit comments

Comments
 (0)