2024-10-12 12:08:12 +00:00
|
|
|
from flask import Flask, request, jsonify
|
2024-10-31 14:05:21 +00:00
|
|
|
from flask_cors import CORS
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# Импортируем функцию обработки из model.py
|
2024-10-12 12:08:12 +00:00
|
|
|
from model import process_query_with_mistral
|
|
|
|
|
2024-10-31 14:05:21 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
logger = logging.getLogger(__name__)
|
2024-10-12 12:08:12 +00:00
|
|
|
|
2024-10-31 14:05:21 +00:00
|
|
|
# Создаем Flask приложение
|
2024-10-12 12:08:12 +00:00
|
|
|
app = Flask(__name__)
|
2024-10-31 14:05:21 +00:00
|
|
|
CORS(app) # Разрешаем CORS для всех доменов
|
|
|
|
CORS(app, resources={r"/api/*": {"origins": "http://localhost:5173"}})
|
2024-10-12 12:08:12 +00:00
|
|
|
|
2024-10-31 14:05:21 +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', '')
|
2024-10-31 14:05:21 +00:00
|
|
|
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)
|
|
|
|
|
2024-10-31 14:05:21 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host='0.0.0.0', port=5000, debug=True)
|