From cecc2f7520c609f9e9291fca23cd1e48a9bed15c Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Wed, 17 Jul 2024 09:21:34 +0200 Subject: [PATCH] =?UTF-8?q?Fortsatta=20=C3=A4ndringar=20f=C3=B6r=20tester?= =?UTF-8?q?=20och=20fels=C3=B6knings=C3=A4ndam=C3=A5l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/backend.py | 22 ++++++++++++---------- smartassist/src/frontend.js | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/smartassist/src/backend.py b/smartassist/src/backend.py index 3e4ab1e..7266f7f 100644 --- a/smartassist/src/backend.py +++ b/smartassist/src/backend.py @@ -2,23 +2,25 @@ # Import the necessary functions from ollama, Flask, requests, threading from ollama import Client from flask import Flask, request, jsonify -import requests +#import requests #import threading # Initialize a Flask application app = Flask(__name__) -@app.route('/chat', methods=['POST']) +@app.route('/api/chat', methods=['POST']) def chat(): - # Get the message from the JSON in the request body - data = request.get_json() - message = data.get('query') + if request.method == 'POST': + # Get the message from the JSON in the request body + data = request.get_json() + message = data.get('query') - if message: - response = requests.post('http://localhost:11434', json={"model": "llama3",'prompt': message}) - return jsonify({'response': response.json().get('result')}) - else: - return jsonify({'error': 'No query provided'}), 400 + if message: + # response = requests.post('http://localhost:11434', json={"model": "llama3",'prompt': message}) + response = request.post('http://localhost:11434', json={"model": "llama3",'prompt': message}) + return jsonify({'response': response.json().get('result')}) + else: + return jsonify({'error': 'No query provided'}), 400 @app.route('/smartassist', methods=["POST"]) diff --git a/smartassist/src/frontend.js b/smartassist/src/frontend.js index 40cad39..0b80540 100644 --- a/smartassist/src/frontend.js +++ b/smartassist/src/frontend.js @@ -41,7 +41,7 @@ function sendMessage() { const xhr = new XMLHttpRequest(); // Configure the request - xhr.open('POST', '/chat'); // Set method to POST and URL + xhr.open('POST', '/api/chat'); // Set method to POST and URL xhr.setRequestHeader('Content-Type', 'application/json'); // Essential for sending JSON // Handle response data