Skip to content

Commit

Permalink
Merge pull request stackblitz-labs#64 from noobydp/main
Browse files Browse the repository at this point in the history
Further changes to support OLLAMA_API_BASE_URL with ollama models
  • Loading branch information
coleam00 authored Oct 24, 2024
2 parents 5f6a595 + f1b8c02 commit b21b145
Show file tree
Hide file tree
Showing 3 changed files with 10 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 @@ -34,6 +34,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
11 changes: 7 additions & 4 deletions app/lib/.server/llm/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export function getGroqModel(apiKey: string, model: string) {
return openai(model);
}

export function getOllamaModel(baseURL: string, model: string) {
let Ollama = ollama(model);
Ollama.config.baseURL = `${baseURL}/api`;
return Ollama;
}

export function getDeepseekModel(apiKey: string, model: string){
const openai = createOpenAI({
baseURL: 'https://api.deepseek.com/beta',
Expand All @@ -65,9 +71,6 @@ export function getDeepseekModel(apiKey: string, model: string){

return openai(model);
}
export function getOllamaModel(model: string) {
return ollama(model);
}

export function getOpenRouterModel(apiKey: string, model: string) {
const openRouter = createOpenRouter({
Expand Down Expand Up @@ -99,6 +102,6 @@ export function getModel(provider: string, model: string, env: Env) {
case 'Mistral':
return getMistralModel(apiKey, model);
default:
return getOllamaModel(model);
return getOllamaModel(baseURL, model);
}
}

0 comments on commit b21b145

Please sign in to comment.