Cleanup and fixing Ollama models not showing up after merging changes

This commit is contained in:
Cole Medin
2024-10-24 08:46:34 -05:00
parent b21b1457f2
commit 8ab8e678cb
3 changed files with 260 additions and 11 deletions

View File

@@ -50,8 +50,7 @@ export let MODEL_LIST: ModelInfo[] = [...staticModels];
async function getOllamaModels(): Promise<ModelInfo[]> {
try {
const base_url = import.meta.env.OLLAMA_API_BASE_URL || "http://localhost:11434";
const url = new URL(base_url).toString();
const response = await fetch(`${url}/api/tags`);
const response = await fetch(`${base_url}/api/tags`);
const data = await response.json() as OllamaApiResponse;
return data.models.map((model: OllamaModel) => ({
@@ -65,20 +64,18 @@ async function getOllamaModels(): Promise<ModelInfo[]> {
}
async function getOpenAILikeModels(): Promise<ModelInfo[]> {
try {
const base_url =import.meta.env.OPENAI_LIKE_API_BASE_URL || "";
if (!base_url) {
return [];
}
const url = new URL(base_url).toString();
const api_key = import.meta.env.OPENAI_LIKE_API_KEY ?? "";
const response = await fetch(`${url}/models`, {
const response = await fetch(`${base_url}/models`, {
headers: {
Authorization: `Bearer ${api_key}`,
}
});
const res = await response.json();
const res = await response.json() as any;
return res.data.map((model: any) => ({
name: model.id,
label: model.id,
@@ -92,8 +89,7 @@ async function getOpenAILikeModels(): Promise<ModelInfo[]> {
async function initializeModelList(): Promise<void> {
const ollamaModels = await getOllamaModels();
const openAiLikeModels = await getOpenAILikeModels();
console.log(openAiLikeModels);
MODEL_LIST = [...ollamaModels,...openAiLikeModels, ...staticModels];
}
initializeModelList().then();
export { getOllamaModels, initializeModelList };
export { getOllamaModels, getOpenAILikeModels, initializeModelList };