first commit
This commit is contained in:
32
main.py
Normal file
32
main.py
Normal file
@@ -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)
|
||||
BIN
misc/__pycache__/random_string.cpython-312.pyc
Normal file
BIN
misc/__pycache__/random_string.cpython-312.pyc
Normal file
Binary file not shown.
33
misc/conversations.py
Normal file
33
misc/conversations.py
Normal file
@@ -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]
|
||||
|
||||
10
misc/random_string.py
Normal file
10
misc/random_string.py
Normal file
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user