diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index f77f7ea12..9310ea85b 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -30,7 +30,8 @@ async def get_ollama_api_url(user=Depends(get_current_user)): if user and user.role == "admin": return {"OLLAMA_API_BASE_URL": app.state.OLLAMA_API_BASE_URL} else: - raise HTTPException(status_code=401, detail=ERROR_MESSAGES.ACCESS_PROHIBITED) + raise HTTPException(status_code=401, + detail=ERROR_MESSAGES.ACCESS_PROHIBITED) class UrlUpdateForm(BaseModel): @@ -38,14 +39,14 @@ class UrlUpdateForm(BaseModel): @app.post("/url/update") -async def update_ollama_api_url( - form_data: UrlUpdateForm, user=Depends(get_current_user) -): +async def update_ollama_api_url(form_data: UrlUpdateForm, + user=Depends(get_current_user)): if user and user.role == "admin": app.state.OLLAMA_API_BASE_URL = form_data.url return {"OLLAMA_API_BASE_URL": app.state.OLLAMA_API_BASE_URL} else: - raise HTTPException(status_code=401, detail=ERROR_MESSAGES.ACCESS_PROHIBITED) + raise HTTPException(status_code=401, + detail=ERROR_MESSAGES.ACCESS_PROHIBITED) @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"]) @@ -58,11 +59,11 @@ async def proxy(path: str, request: Request, user=Depends(get_current_user)): if user.role in ["user", "admin"]: if path in ["pull", "delete", "push", "copy", "create"]: if user.role != "admin": - raise HTTPException( - status_code=401, detail=ERROR_MESSAGES.ACCESS_PROHIBITED - ) + raise HTTPException(status_code=401, + detail=ERROR_MESSAGES.ACCESS_PROHIBITED) else: - raise HTTPException(status_code=401, detail=ERROR_MESSAGES.ACCESS_PROHIBITED) + raise HTTPException(status_code=401, + detail=ERROR_MESSAGES.ACCESS_PROHIBITED) headers.pop("Host", None) headers.pop("Authorization", None) diff --git a/backend/apps/ollama/old_main.py b/backend/apps/ollama/old_main.py index 2e6800930..f809d4420 100644 --- a/backend/apps/ollama/old_main.py +++ b/backend/apps/ollama/old_main.py @@ -1,11 +1,9 @@ from flask import Flask, request, Response, jsonify from flask_cors import CORS - import requests import json - from apps.web.models.users import Users from constants import ERROR_MESSAGES from utils.utils import decode_token @@ -77,7 +75,9 @@ def update_ollama_api_url(): ) -@app.route("/", defaults={"path": ""}, methods=["GET", "POST", "PUT", "DELETE"]) +@app.route("/", + defaults={"path": ""}, + methods=["GET", "POST", "PUT", "DELETE"]) @app.route("/", methods=["GET", "POST", "PUT", "DELETE"]) def proxy(path): # Combine the base URL of the target server with the requested path @@ -106,13 +106,17 @@ def proxy(path): pass else: return ( - jsonify({"detail": ERROR_MESSAGES.ACCESS_PROHIBITED}), + jsonify({ + "detail": + ERROR_MESSAGES.ACCESS_PROHIBITED + }), 401, ) else: pass else: - return jsonify({"detail": ERROR_MESSAGES.ACCESS_PROHIBITED}), 401 + return jsonify( + {"detail": ERROR_MESSAGES.ACCESS_PROHIBITED}), 401 else: return jsonify({"detail": ERROR_MESSAGES.UNAUTHORIZED}), 401 else: @@ -162,12 +166,10 @@ def proxy(path): print(res) return ( - jsonify( - { - "detail": error_detail, - "message": str(e), - } - ), + jsonify({ + "detail": error_detail, + "message": str(e), + }), 400, ) diff --git a/backend/main.py b/backend/main.py index 704ece781..53931dccd 100644 --- a/backend/main.py +++ b/backend/main.py @@ -50,4 +50,6 @@ app.mount("/api/v1", webui_app) # app.mount("/ollama/api", WSGIMiddleware(ollama_app)) app.mount("/ollama/api", ollama_app) -app.mount("/", SPAStaticFiles(directory="../build", html=True), name="spa-static-files") +app.mount("/", + SPAStaticFiles(directory="../build", html=True), + name="spa-static-files")