Bakalarska_praca/Backend/server.py

29 lines
927 B
Python
Raw Normal View History

2024-10-12 12:08:12 +00:00
from flask import Flask, request, jsonify
from flask_cors import CORS
import logging
# Импортируем функцию обработки из model.py
2024-10-12 12:08:12 +00:00
from model import process_query_with_mistral
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
2024-10-12 12:08:12 +00:00
# Создаем Flask приложение
2024-10-12 12:08:12 +00:00
app = Flask(__name__)
CORS(app) # Разрешаем CORS для всех доменов
CORS(app, resources={r"/api/*": {"origins": "http://localhost:5173"}})
2024-10-12 12:08:12 +00:00
# Маршрут для обработки запросов от фронтенда
2024-10-12 12:08:12 +00:00
@app.route('/api/chat', methods=['POST'])
def chat():
data = request.get_json()
query = data.get('query', '')
if not query:
return jsonify({'error': 'No query provided'}), 400
2024-10-12 12:08:12 +00:00
response = process_query_with_mistral(query)
return jsonify(response)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)