Commit fbdac832 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

feat: multiple ollama model management

parent 8181d98e
...@@ -207,9 +207,12 @@ async def pull_model( ...@@ -207,9 +207,12 @@ async def pull_model(
form_data: ModelNameForm, url_idx: int = 0, user=Depends(get_admin_user) form_data: ModelNameForm, url_idx: int = 0, user=Depends(get_admin_user)
): ):
url = app.state.OLLAMA_BASE_URLS[url_idx] url = app.state.OLLAMA_BASE_URLS[url_idx]
print(url)
r = None r = None
def get_request(url): def get_request():
nonlocal url
nonlocal r nonlocal r
try: try:
...@@ -235,7 +238,7 @@ async def pull_model( ...@@ -235,7 +238,7 @@ async def pull_model(
raise e raise e
try: try:
return await run_in_threadpool(get_request(url)) return await run_in_threadpool(get_request)
except Exception as e: except Exception as e:
print(e) print(e)
error_detail = "Open WebUI: Server Connection Error" error_detail = "Open WebUI: Server Connection Error"
...@@ -454,6 +457,7 @@ async def delete_model( ...@@ -454,6 +457,7 @@ async def delete_model(
) )
url = app.state.OLLAMA_BASE_URLS[url_idx] url = app.state.OLLAMA_BASE_URLS[url_idx]
print(url)
try: try:
r = requests.request( r = requests.request(
......
...@@ -318,20 +318,23 @@ export const createModel = async (token: string, tagName: string, content: strin ...@@ -318,20 +318,23 @@ export const createModel = async (token: string, tagName: string, content: strin
return res; return res;
}; };
export const deleteModel = async (token: string, tagName: string) => { export const deleteModel = async (token: string, tagName: string, urlIdx: string | null = null) => {
let error = null; let error = null;
const res = await fetch(`${OLLAMA_API_BASE_URL}/api/delete`, { const res = await fetch(
method: 'DELETE', `${OLLAMA_API_BASE_URL}/api/delete${urlIdx !== null ? `/${urlIdx}` : ''}`,
headers: { {
Accept: 'application/json', method: 'DELETE',
'Content-Type': 'application/json', headers: {
Authorization: `Bearer ${token}` Accept: 'application/json',
}, 'Content-Type': 'application/json',
body: JSON.stringify({ Authorization: `Bearer ${token}`
name: tagName },
}) body: JSON.stringify({
}) name: tagName
})
}
)
.then(async (res) => { .then(async (res) => {
if (!res.ok) throw await res.json(); if (!res.ok) throw await res.json();
return res.json(); return res.json();
...@@ -358,10 +361,10 @@ export const deleteModel = async (token: string, tagName: string) => { ...@@ -358,10 +361,10 @@ export const deleteModel = async (token: string, tagName: string) => {
return res; return res;
}; };
export const pullModel = async (token: string, tagName: string) => { export const pullModel = async (token: string, tagName: string, urlIdx: string | null = null) => {
let error = null; let error = null;
const res = await fetch(`${OLLAMA_API_BASE_URL}/api/pull`, { const res = await fetch(`${OLLAMA_API_BASE_URL}/api/pull${urlIdx !== null ? `/${urlIdx}` : ''}`, {
method: 'POST', method: 'POST',
headers: { headers: {
Accept: 'application/json', Accept: 'application/json',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment