Skip to content

Commit 62ebb52

Browse files
committed
Improve Custom OpenAI API, fix some bugs
1 parent e374807 commit 62ebb52

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/api/Providers/special/custom_openai.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fetch from "#root/src/api/fetch.js";
44
const getHeaders = (apiKey) => {
55
return {
66
"Content-Type": "application/json",
7+
"Accept": "*/*",
78
Authorization: apiKey ? `Bearer ${apiKey}` : undefined,
89
};
910
};
@@ -32,12 +33,20 @@ export const CustomOpenAIProvider = {
3233
// eslint-disable-next-line no-empty
3334
} catch {}
3435

35-
const api_url = url + "/chat/completions";
36+
const api_url = url.endsWith("/chat/completions") ? url : url + "/chat/completions";
3637
const model = options.model;
3738
const api_key = options.apiKey || apiData.apiKey;
3839
const config = apiData.config || {};
3940

4041
chat = messages_to_json(chat);
42+
43+
let headers = {
44+
...getHeaders(api_key),
45+
...config?.HEADERS,
46+
};
47+
48+
delete config.HEADERS;
49+
4150
let body = {
4251
messages: chat,
4352
stream: true,
@@ -49,7 +58,7 @@ export const CustomOpenAIProvider = {
4958
api_url,
5059
{
5160
method: "POST",
52-
headers: getHeaders(api_key),
61+
headers: headers,
5362
body: JSON.stringify(body),
5463
},
5564
{ timeout: 0 } // disable timeout

0 commit comments

Comments
 (0)