commit 0ef49fade8a959d8c48aa600733df3575189bf2d Author: MoonDev Date: Sun May 4 16:30:07 2025 +0300 first commit diff --git a/main.py b/main.py new file mode 100644 index 0000000..291a9c7 --- /dev/null +++ b/main.py @@ -0,0 +1,32 @@ +from flask import Flask, request, jsonify +from misc.random_string import generate_secure_string + + +app = Flask(__name__) + +@app.route('/') +def index(): + return "Добро пожаловать на Flask сервер!" + +@app.route('/api/new-request', methods=['POST']) +def handle_data(): + # Получаем JSON из запроса + data = request.get_json() + + if not data: + return jsonify({"error": "No JSON payload received"}), 400 + + # Выводим полученные данные в консоль + print("Полученные данные:", data) + + # Формируем ответ + response = { + "message": "Data received successfully", + "yourData": data, + "conversation_id":generate_secure_string(40) + } + + return jsonify(response), 200 + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/misc/__pycache__/random_string.cpython-312.pyc b/misc/__pycache__/random_string.cpython-312.pyc new file mode 100644 index 0000000..682853b Binary files /dev/null and b/misc/__pycache__/random_string.cpython-312.pyc differ diff --git a/misc/conversations.py b/misc/conversations.py new file mode 100644 index 0000000..e33412d --- /dev/null +++ b/misc/conversations.py @@ -0,0 +1,33 @@ +from random_string import generate_secure_string + +CONVERSATIONS = {} +""" +{ +messages: + [{ + role:str, + content:str, + id:int + }], +last_message_id: int, +workspace: str, +user_name: str, +problem_type: int +} + +""" + +class Conversations: + def __init__(self): + self.id = "" + + def create(self,user_message,workspace,user_name,problem_type): + self.id = generate_secure_string(40) + CONVERSATIONS[self.id] = { + "messages":[], + "last_message_id":0, + "workspace":workspace, + "user_name":user_name, + "problem_type":problem_type} + return CONVERSATIONS[self.id] + diff --git a/misc/random_string.py b/misc/random_string.py new file mode 100644 index 0000000..9c641d7 --- /dev/null +++ b/misc/random_string.py @@ -0,0 +1,10 @@ +import secrets +import string + +def generate_secure_string(length): + if length <= 0: + return "" + + characters = string.ascii_letters + string.digits + return ''.join(secrets.choice(characters) for _ in range(length)) +