Refaktoriseringar och test av alternativa lösningar.
This commit is contained in:
+34
-20
@@ -2,26 +2,23 @@
|
||||
# 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__)
|
||||
|
||||
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
|
||||
|
||||
def run_flask():
|
||||
# Flask endpoint for user interaction
|
||||
app.run(port=5000, debug=True)
|
||||
@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 message:
|
||||
response = requests.post('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'])
|
||||
@@ -37,13 +34,30 @@ def smartassist():
|
||||
# Return the response as a JSON object in the HTTP response
|
||||
return jsonify({"response": response})
|
||||
|
||||
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
|
||||
|
||||
def run_flask():
|
||||
# Flask endpoint for user interaction
|
||||
app.run(port=5000, debug=True)
|
||||
# app.run(port=5000, debug=True, use_reloader=False)
|
||||
|
||||
|
||||
# @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})
|
||||
# response = requests.post('localhost::11434', json={"model": "llama3",'prompt': query})
|
||||
# return jsonify({'response': response.json().get('result')})
|
||||
|
||||
@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__':
|
||||
|
||||
Reference in New Issue
Block a user