Omdöpt till backend.py
This commit is contained in:
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
# 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
|
|
||||||
import requests
|
|
||||||
|
|
||||||
# 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})
|
|
||||||
|
|
||||||
|
|
||||||
@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__':
|
|
||||||
# Run the Flask application on port 5000
|
|
||||||
app.run(port=5000, debug=True)
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user