Updated the backen and the requirements to allow chat interaction

This commit is contained in:
Joakim Persson
2024-07-16 11:44:23 +02:00
parent 8d9369c502
commit 1837c1282a
2 changed files with 20 additions and 7 deletions
+6 -4
View File
@@ -1,6 +1,8 @@
# A requirements file for the project. This file specifies # A requirements file for the project.
# the development environment: #
# - Python 3.8+ # Run 'pip install -r requirements.txt' to install all required packages.
# - pipenv
ollama ollama
Flask Flask
requests
+13 -2
View File
@@ -14,6 +14,7 @@ def get_response(user_query):
# Flask endpoint for user interaction # Flask endpoint for user interaction
from flask import Flask, request, jsonify from flask import Flask, request, jsonify
import requests
# Initialize a Flask application # Initialize a Flask application
app = Flask(__name__) app = Flask(__name__)
@@ -30,6 +31,16 @@ def smartassist():
# Return the response as a JSON object in the HTTP response # Return the response as a JSON object in the HTTP response
return jsonify({"response": response}) return jsonify({"response": response})
# Run the Flask application if this script is executed directly
@app.route('/api/chat', methods=['POST'])
def chat():
data = request.get_json()
query = data['query']
response = requests.post('http://ollama-server/api/v1/chat', json={'prompt': query})
return jsonify({'response': response.json().get('result')})
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) # Run the Flask application on port 5000
app.run(port=5000, debug=True)