mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 15:33:59 +01:00
Azure OpenAI API Fix (#297)
* Azure OpenAI API Fix * improve code * improve code --------- Co-authored-by: Jing Hua <tohjinghua123@gmail.com>
This commit is contained in:
parent
82f8761397
commit
52fa56c1da
|
@ -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',
|
||||
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue