Skip to content

Commit

Permalink
updated ollama to use defined base URL for model calls
Browse files Browse the repository at this point in the history
  • Loading branch information
noobydp committed Oct 24, 2024
1 parent 94fa108 commit 8ce82b5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dist-ssr
*.local

.vscode/*
!.vscode/launch.json
.vscode/launch.json
!.vscode/extensions.json
.idea
.DS_Store
Expand Down
2 changes: 2 additions & 0 deletions app/lib/.server/llm/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
Expand Down
8 changes: 5 additions & 3 deletions app/lib/.server/llm/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion app/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down

0 comments on commit 8ce82b5

Please sign in to comment.