mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 21:53:58 +01:00
parent
2dcdecc842
commit
38bc63f0ac
|
@ -1,16 +1,20 @@
|
||||||
import { ShareGPTSubmitBodyInterface } from '@type/api';
|
import { ShareGPTSubmitBodyInterface } from '@type/api';
|
||||||
import { ConfigInterface, MessageInterface } from '@type/chat';
|
import { ConfigInterface, MessageInterface } from '@type/chat';
|
||||||
|
import { isAzureEndpoint } from '@utils/api';
|
||||||
|
|
||||||
export const getChatCompletion = async (
|
export const getChatCompletion = async (
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
messages: MessageInterface[],
|
messages: MessageInterface[],
|
||||||
config: ConfigInterface,
|
config: ConfigInterface,
|
||||||
apiKey?: string
|
apiKey?: string,
|
||||||
|
customHeaders?: Record<string, string>
|
||||||
) => {
|
) => {
|
||||||
const headers: HeadersInit = {
|
const headers: HeadersInit = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
...customHeaders,
|
||||||
};
|
};
|
||||||
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
||||||
|
if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey;
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
const response = await fetch(endpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -31,12 +35,15 @@ export const getChatCompletionStream = async (
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
messages: MessageInterface[],
|
messages: MessageInterface[],
|
||||||
config: ConfigInterface,
|
config: ConfigInterface,
|
||||||
apiKey?: string
|
apiKey?: string,
|
||||||
|
customHeaders?: Record<string, string>
|
||||||
) => {
|
) => {
|
||||||
const headers: HeadersInit = {
|
const headers: HeadersInit = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
...customHeaders,
|
||||||
};
|
};
|
||||||
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
||||||
|
if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey;
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
const response = await fetch(endpoint, {
|
||||||
method: 'POST',
|
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