From 8d9369c5027dbcb6b38640b015e8e7934b29c0b9 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Tue, 16 Jul 2024 11:26:16 +0200 Subject: [PATCH] More comments in the code --- smartassist/src/ollama_interact.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/smartassist/src/ollama_interact.py b/smartassist/src/ollama_interact.py index 3b1ca60..2d942f8 100644 --- a/smartassist/src/ollama_interact.py +++ b/smartassist/src/ollama_interact.py @@ -1,21 +1,35 @@ -# Example function to interact with OLLAMA + +# Import the necessary library from ollama module from ollama import Client def get_response(user_query): + # Create a client object for interacting with OLLAMA API client = Client() + + # Generate and retrieve the response based on user's query response = client.generate_response(user_query) + + # Return the generated response return response # Flask endpoint for user interaction from flask import Flask, request, jsonify + +# Initialize a Flask application app = Flask(__name__) @app.route('/smartassist', methods=['POST']) def smartassist(): + # Extract the query from the incoming JSON data data = request.json user_query = data['query'] + + # Get the response from the OLLAMA API based on the user's query response = get_response(user_query) + + # Return the response as a JSON object in the HTTP response return jsonify({"response": response}) +# Run the Flask application if this script is executed directly if __name__ == '__main__': app.run(debug=True)