From 5f2b71c965fe68b8b9ed464833596fc60c0815fa Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Fri, 2 Aug 2024 23:09:15 +0200 Subject: [PATCH] =?UTF-8?q?Lagt=20till=20/api/tags=20f=C3=B6r=20att=20kunn?= =?UTF-8?q?a=20f=C3=A5=20ut=20lista=20av=20tillg=C3=A4ngliga=20modeller=20?= =?UTF-8?q?(LLM:er)=20p=C3=A5=20aktuell=20ollama-server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/backend.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/smartassist/src/backend.py b/smartassist/src/backend.py index 6615830..de7deb9 100644 --- a/smartassist/src/backend.py +++ b/smartassist/src/backend.py @@ -87,6 +87,19 @@ CORS(app, resources={ } }) +@app.route('/api/tags', methods=['GET']) +def tag(url = "http://localhost:11434/api/tags", headers = None): +# def tag(url = "http://localhost:11434/api/tags", headers = {"Content-Type": "application/json"}): + """Get a list of models for the server located at url.""" + try: + logger.debug(f"url: {url} headers: {headers}") + response = requests.get(url, headers=headers) + return response.json() + # return response + except requests.exceptions.RequestException as e: + logger.error("Request Exception: %s", str(e)) + return {'error': 'Failed to process request'} + @app.route('/api/chat', methods=['POST']) def chat(model = "phi3:mini"): @@ -101,7 +114,7 @@ def chat(model = "phi3:mini"): data = request.get_json() message = data.get('query') url_server = data.get('url_server', "https://ollama-test.wara-ops.org/api/generate") # Use provided URL or default - model = data.get('model', model) # Use provided model or default + model = data.get('model', model) # Use provided model or default if not provided # Get chat history from session storage (e.g., a dictionary) chat_history = session.get('chat_history', [])