refac: openai allow empty key

This commit is contained in:
Timothy J. Baek
2024-05-29 01:12:25 -07:00
parent 943baad689
commit e8d4e03c0d
5 changed files with 91 additions and 44 deletions
+3 -16
View File
@@ -203,10 +203,10 @@ export const updateOpenAIKeys = async (token: string = '', keys: string[]) => {
return res.OPENAI_API_KEYS;
};
export const getOpenAIModels = async (token: string = '') => {
export const getOpenAIModels = async (token: string, urlIdx?: number) => {
let error = null;
const res = await fetch(`${OPENAI_API_BASE_URL}/models`, {
const res = await fetch(`${OPENAI_API_BASE_URL}/models${urlIdx ? `/${urlIdx}` : ''}`, {
method: 'GET',
headers: {
Accept: 'application/json',
@@ -227,20 +227,7 @@ export const getOpenAIModels = async (token: string = '') => {
throw error;
}
const models = Array.isArray(res) ? res : res?.data ?? null;
return models
? models
.map((model) => ({
id: model.id,
name: model.name ?? model.id,
external: true,
custom_info: model.custom_info
}))
.sort((a, b) => {
return a.name.localeCompare(b.name);
})
: models;
return res;
};
export const getOpenAIModelsDirect = async (