mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 19:24:00 +01:00
parent
2dcdecc842
commit
38bc63f0ac
|
@ -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
3
src/utils/api.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export const isAzureEndpoint = (endpoint: string) => {
|
||||
return endpoint.includes('openai.azure.com');
|
||||
};
|
Loading…
Reference in a new issue