Merge pull request #64 from noobydp/main

Further changes to support OLLAMA_API_BASE_URL with ollama models
This commit is contained in:
Cole Medin 2024-10-24 08:25:23 -05:00 committed by GitHub
commit b21b1457f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

2
.gitignore vendored
View File

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

View File

@ -34,6 +34,8 @@ export function getBaseURL(cloudflareEnv: Env, provider: string) {
switch (provider) { switch (provider) {
case 'OpenAILike': case 'OpenAILike':
return env.OPENAI_LIKE_API_BASE_URL || cloudflareEnv.OPENAI_LIKE_API_BASE_URL; 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: default:
return ""; return "";
} }

View File

@ -57,6 +57,12 @@ export function getGroqModel(apiKey: string, model: string) {
return openai(model); 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){ export function getDeepseekModel(apiKey: string, model: string){
const openai = createOpenAI({ const openai = createOpenAI({
baseURL: 'https://api.deepseek.com/beta', baseURL: 'https://api.deepseek.com/beta',
@ -65,9 +71,6 @@ export function getDeepseekModel(apiKey: string, model: string){
return openai(model); return openai(model);
} }
export function getOllamaModel(model: string) {
return ollama(model);
}
export function getOpenRouterModel(apiKey: string, model: string) { export function getOpenRouterModel(apiKey: string, model: string) {
const openRouter = createOpenRouter({ const openRouter = createOpenRouter({
@ -99,6 +102,6 @@ export function getModel(provider: string, model: string, env: Env) {
case 'Mistral': case 'Mistral':
return getMistralModel(apiKey, model); return getMistralModel(apiKey, model);
default: default:
return getOllamaModel(model); return getOllamaModel(baseURL, model);
} }
} }