diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 8bb01ed46..5d66979ce 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -963,6 +963,9 @@ async def download_file_stream( done = current_size == total_size progress = round((current_size / total_size) * 100, 2) + + print(progress) + yield f'data: {{"progress": {progress}, "completed": {current_size}, "total": {total_size}}}\n\n' if done: @@ -986,6 +989,11 @@ async def download_file_stream( raise "Ollama: Could not create blob, Please try again." +# def number_generator(): +# for i in range(1, 101): +# yield f"data: {i}\n" + + # url = "https://huggingface.co/TheBloke/stablelm-zephyr-3b-GGUF/resolve/main/stablelm-zephyr-3b.Q2_K.gguf" @app.post("/models/download") @app.post("/models/download/{url_idx}") @@ -1002,9 +1010,8 @@ async def download_model( if file_name: file_path = f"{UPLOAD_DIR}/{file_name}" - return StreamingResponse( - download_file_stream(url, form_data.url, file_path, file_name) + download_file_stream(url, form_data.url, file_path, file_name), ) else: return None diff --git a/src/lib/apis/ollama/index.ts b/src/lib/apis/ollama/index.ts index a461d71bd..c3b37e007 100644 --- a/src/lib/apis/ollama/index.ts +++ b/src/lib/apis/ollama/index.ts @@ -402,6 +402,8 @@ export const downloadModel = async ( { method: 'POST', headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }, body: JSON.stringify({ diff --git a/src/lib/components/chat/Settings/Models.svelte b/src/lib/components/chat/Settings/Models.svelte index f74e85ff4..9b319b951 100644 --- a/src/lib/components/chat/Settings/Models.svelte +++ b/src/lib/components/chat/Settings/Models.svelte @@ -196,7 +196,7 @@ const file = modelInputFile ? modelInputFile[0] : null; if (file) { - fileResponse = uploadModel(localStorage.token, file, selectedOllamaUrlIdx).catch( + fileResponse = await uploadModel(localStorage.token, file, selectedOllamaUrlIdx).catch( (error) => { toast.error(error); return null; @@ -204,12 +204,14 @@ ); } } else { - fileResponse = downloadModel(localStorage.token, modelFileUrl, selectedOllamaUrlIdx).catch( - (error) => { - toast.error(error); - return null; - } - ); + fileResponse = await downloadModel( + localStorage.token, + modelFileUrl, + selectedOllamaUrlIdx + ).catch((error) => { + toast.error(error); + return null; + }); } if (fileResponse && fileResponse.ok) { @@ -313,7 +315,10 @@ } modelFileUrl = ''; - modelUploadInputElement.value = ''; + + if (modelUploadInputElement) { + modelUploadInputElement.value = ''; + } modelInputFile = null; modelTransferring = false; uploadProgress = null; @@ -741,7 +746,7 @@ {#if (modelUploadMode === 'file' && modelInputFile && modelInputFile.length > 0) || (modelUploadMode === 'url' && modelFileUrl !== '')}