feat: Azure OpenAI endpoint support

fixes #208
This commit is contained in:
Jing Hua 2023-04-06 02:48:12 +08:00
parent 2dcdecc842
commit 38bc63f0ac
2 changed files with 12 additions and 2 deletions

View file

@ -1,16 +1,20 @@
import { ShareGPTSubmitBodyInterface } from '@type/api';
import { ConfigInterface, MessageInterface } from '@type/chat';
import { isAzureEndpoint } from '@utils/api';
export const getChatCompletion = async (
endpoint: string,
messages: MessageInterface[],
config: ConfigInterface,
apiKey?: string
apiKey?: string,
customHeaders?: Record<string, string>
) => {
const headers: HeadersInit = {
'Content-Type': 'application/json',
...customHeaders,
};
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey;
const response = await fetch(endpoint, {
method: 'POST',
@ -31,12 +35,15 @@ export const getChatCompletionStream = async (
endpoint: string,
messages: MessageInterface[],
config: ConfigInterface,
apiKey?: string
apiKey?: string,
customHeaders?: Record<string, string>
) => {
const headers: HeadersInit = {
'Content-Type': 'application/json',
...customHeaders,
};
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey;
const response = await fetch(endpoint, {
method: 'POST',

3
src/utils/api.ts Normal file
View file

@ -0,0 +1,3 @@
export const isAzureEndpoint = (endpoint: string) => {
return endpoint.includes('openai.azure.com');
};