Skip to content

Commit

Permalink
Cleanup and fixing Ollama models not showing up after merging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
coleam00 committed Oct 24, 2024
1 parent b21b145 commit 8ab8e67
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/lib/.server/llm/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function getBaseURL(cloudflareEnv: Env, provider: string) {
case 'OpenAILike':
return env.OPENAI_LIKE_API_BASE_URL || cloudflareEnv.OPENAI_LIKE_API_BASE_URL;
case 'Ollama':
return env.OLLAMA_API_BASE_URL || cloudflareEnv.OLLAMA_API_BASE_URL;
return env.OLLAMA_API_BASE_URL || cloudflareEnv.OLLAMA_API_BASE_URL || "http://localhost:11434";
default:
return "";
}
Expand Down
12 changes: 4 additions & 8 deletions app/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand All @@ -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,
Expand All @@ -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 };
Loading

0 comments on commit 8ab8e67

Please sign in to comment.