Testar olika metoder för att hantera Cross-Origin Resource Sharing
This commit is contained in:
+14
-10
@@ -2,25 +2,29 @@
|
|||||||
# 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
|
||||||
|
from flask_cors import CORS, cross_origin
|
||||||
#import requests
|
#import requests
|
||||||
#import threading
|
#import threading
|
||||||
|
|
||||||
# Initialize a Flask application
|
# Initialize a Flask application
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
CORS(app)
|
||||||
|
|
||||||
|
# @app.route('/api/chat', methods=['POST'])
|
||||||
|
# @cross_origin(origin='http://localhost:8000', headers=['Content-Type']) # Allow cross-origin requests from localhost:8000
|
||||||
@app.route('/api/chat', methods=['POST'])
|
@app.route('/api/chat', methods=['POST'])
|
||||||
|
@cross_origin(origin='*', headers=['Content-Type']) # Enable CORS for this route. Probably not necessary.
|
||||||
def chat():
|
def chat():
|
||||||
if request.method == 'POST':
|
# Get the message from the JSON in the request body
|
||||||
# Get the message from the JSON in the request body
|
data = request.get_json()
|
||||||
data = request.get_json()
|
message = data.get('query')
|
||||||
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})
|
||||||
response = request.post('http://localhost:11434', json={"model": "llama3",'prompt': message})
|
response = request.post('http://localhost:11434', json={"model": "llama3",'prompt': message})
|
||||||
return jsonify({'response': response.json().get('result')})
|
return jsonify({'response': response.json().get('result')})
|
||||||
else:
|
else:
|
||||||
return jsonify({'error': 'No query provided'}), 400
|
return jsonify({'error': 'No query provided'}), 400
|
||||||
|
|
||||||
|
|
||||||
@app.route('/smartassist', methods=["POST"])
|
@app.route('/smartassist', methods=["POST"])
|
||||||
|
|||||||
Reference in New Issue
Block a user