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

Azure OpenAI API Fix #297

Merged
merged 3 commits into from May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/api/api.ts
Expand Up @@ -14,7 +14,24 @@ export const getChatCompletion = async (
...customHeaders,
};
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey;

if (isAzureEndpoint(endpoint) && apiKey) {
headers['api-key'] = apiKey;

const gpt3forAzure = 'gpt-35-turbo';
const model =
config.model === 'gpt-3.5-turbo' ? gpt3forAzure : config.model;
const apiVersion = '2023-03-15-preview';

const path = `openai/deployments/${model}/chat/completions?api-version=${apiVersion}`;

if (!endpoint.endsWith(path)) {
if (!endpoint.endsWith('/')) {
endpoint += '/';
}
endpoint += path;
}
}

const response = await fetch(endpoint, {
method: 'POST',
Expand Down Expand Up @@ -43,7 +60,24 @@ export const getChatCompletionStream = async (
...customHeaders,
};
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey;

if (isAzureEndpoint(endpoint) && apiKey) {
headers['api-key'] = apiKey;

const gpt3forAzure = 'gpt-35-turbo';
const model =
config.model === 'gpt-3.5-turbo' ? gpt3forAzure : config.model;
const apiVersion = '2023-03-15-preview';

const path = `openai/deployments/${model}/chat/completions?api-version=${apiVersion}`;

if (!endpoint.endsWith(path)) {
if (!endpoint.endsWith('/')) {
endpoint += '/';
}
endpoint += path;
}
}

const response = await fetch(endpoint, {
method: 'POST',
Expand Down