updated ollama to use defined base URL for model calls

This commit is contained in:
noobydp 2024-10-24 16:49:11 +08:00
parent 94fa108142
commit 8ce82b5a1c
4 changed files with 9 additions and 5 deletions

2
.gitignore vendored
View File

@ -12,7 +12,7 @@ dist-ssr
*.local
.vscode/*
!.vscode/launch.json
.vscode/launch.json
!.vscode/extensions.json
.idea
.DS_Store

View File

@ -30,6 +30,8 @@ export function getBaseURL(cloudflareEnv: Env, provider: string) {
switch (provider) {
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;
default:
return "";
}

View File

@ -47,8 +47,10 @@ export function getGroqModel(apiKey: string, model: string) {
return openai(model);
}
export function getOllamaModel(model: string) {
return ollama(model);
export function getOllamaModel(baseURL: string, model: string) {
let Ollama = ollama(model);
Ollama.config.baseURL = `${baseURL}/api`;
return Ollama;
}
export function getOpenRouterModel(apiKey: string, model: string) {
@ -77,6 +79,6 @@ export function getModel(provider: string, model: string, env: Env) {
case 'OpenAILike':
return getOpenAILikeModel(baseURL,apiKey, model);
default:
return getOllamaModel(model);
return getOllamaModel(baseURL, model);
}
}

View File

@ -38,7 +38,7 @@ 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(`${url}api/tags`);
const data = await response.json();
return data.models.map((model: any) => ({