This commit is contained in:
Timothy Jaeryang Baek
2026-08-13 00:07:31 -06:00
parent 3813fd4cdc
commit 85c3d0ae2f
10 changed files with 897 additions and 21 deletions
+177 -1
View File
@@ -131,9 +131,185 @@ export const getOpenAIModels = async (token: string, urlIdx?: number) => {
return res;
};
export const getProviderModelCatalog = async (token: string, urlIdx: number) => {
let error = null;
const res = await fetch(`${OPENAI_API_BASE_URL}/models/${urlIdx}/catalog`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token && { authorization: `Bearer ${token}` })
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err?.detail ?? err?.error?.message ?? 'Server connection failed';
return null;
});
if (error) {
throw error;
}
return res;
};
export const downloadProviderModel = async (token: string, urlIdx: number, model: string) => {
let error = null;
const res = await fetch(`${OPENAI_API_BASE_URL}/models/${urlIdx}/download`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({ model })
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err?.detail ?? err?.error?.message ?? 'Server connection failed';
return null;
});
if (error) {
throw error;
}
return res;
};
export const getProviderModelDownloadStatus = async (token: string, urlIdx: number, jobId: string) => {
let error = null;
const res = await fetch(
`${OPENAI_API_BASE_URL}/models/${urlIdx}/download/status/${encodeURIComponent(jobId)}`,
{
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
}
)
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err?.detail ?? err?.error?.message ?? 'Server connection failed';
return null;
});
if (error) {
throw error;
}
return res;
};
export const loadProviderModel = async (token: string, urlIdx: number, model: string) => {
let error = null;
const res = await fetch(`${OPENAI_API_BASE_URL}/models/${urlIdx}/load`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({ model })
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err?.detail ?? err?.error?.message ?? 'Server connection failed';
return null;
});
if (error) {
throw error;
}
return res;
};
export const unloadProviderModel = async (
token: string,
urlIdx: number,
model: string,
instanceId?: string
) => {
let error = null;
const res = await fetch(`${OPENAI_API_BASE_URL}/models/${urlIdx}/unload`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({ model, ...(instanceId ? { instance_id: instanceId } : {}) })
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err?.detail ?? err?.error?.message ?? 'Server connection failed';
return null;
});
if (error) {
throw error;
}
return res;
};
export const deleteProviderModel = async (token: string, urlIdx: number, model: string) => {
let error = null;
const res = await fetch(
`${OPENAI_API_BASE_URL}/models/${urlIdx}?${new URLSearchParams({ model })}`,
{
method: 'DELETE',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
}
)
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err?.detail ?? err?.error?.message ?? 'Server connection failed';
return null;
});
if (error) {
throw error;
}
return res;
};
export const verifyOpenAIConnection = async (
token: string = '',
connection: dict = {},
connection: Record<string, any> = {},
direct: boolean = false
) => {
const { url, key, config } = connection;