Fortsatta ändringar för tester och felsökningsändamål
This commit is contained in:
+12
-10
@@ -2,23 +2,25 @@
|
|||||||
# Import the necessary functions from ollama, Flask, requests, threading
|
# Import the necessary functions from ollama, Flask, requests, threading
|
||||||
from ollama import Client
|
from ollama import Client
|
||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
import requests
|
#import requests
|
||||||
#import threading
|
#import threading
|
||||||
|
|
||||||
# Initialize a Flask application
|
# Initialize a Flask application
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route('/chat', methods=['POST'])
|
@app.route('/api/chat', methods=['POST'])
|
||||||
def chat():
|
def chat():
|
||||||
# Get the message from the JSON in the request body
|
if request.method == 'POST':
|
||||||
data = request.get_json()
|
# Get the message from the JSON in the request body
|
||||||
message = data.get('query')
|
data = request.get_json()
|
||||||
|
message = data.get('query')
|
||||||
|
|
||||||
if message:
|
if message:
|
||||||
response = requests.post('http://localhost:11434', json={"model": "llama3",'prompt': message})
|
# response = requests.post('http://localhost:11434', json={"model": "llama3",'prompt': message})
|
||||||
return jsonify({'response': response.json().get('result')})
|
response = request.post('http://localhost:11434', json={"model": "llama3",'prompt': message})
|
||||||
else:
|
return jsonify({'response': response.json().get('result')})
|
||||||
return jsonify({'error': 'No query provided'}), 400
|
else:
|
||||||
|
return jsonify({'error': 'No query provided'}), 400
|
||||||
|
|
||||||
|
|
||||||
@app.route('/smartassist', methods=["POST"])
|
@app.route('/smartassist', methods=["POST"])
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ function sendMessage() {
|
|||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
// Configure the request
|
// 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
|
xhr.setRequestHeader('Content-Type', 'application/json'); // Essential for sending JSON
|
||||||
|
|
||||||
// Handle response data
|
// Handle response data
|
||||||
|
|||||||
Reference in New Issue
Block a user