Closed laovvvcom closed 1 year ago
我这边想在代码基础上加入个逻辑,用户id得来自于数据库, 尝试加了个user_exist方法,并给new_user_dict添加了个逻辑,但达不到需求 `def user_exists(user_id):
conn = pymysql.connect(host=host, user=user, password=password, database=database) sql_select_wechatnumber = f"SELECT *FROM table WHERE wechatnumber = '{user_id}'" with conn.cursor() as cursor: cursor.execute(sql_select_wechatnumber) sql_select_number_result = cursor.fetchall() return bool(sql_select_number_result)
def new_user_dict(user_id, send_time): if not user_exists(user_id): return "用户 ID 不存在于数据库,请重新输入或选择已有用户 ID"
chat_id = str(uuid.uuid1()) user_dict = {"chats": {chat_id: new_chat_dict(user_id, "默认对话", send_time)}, "selected_chat_id": chat_id, "default_chat_id": chat_id} user_dict['chats'][chat_id]['messages_history'].insert(1, {"role": "assistant", "content": "- 创建新的用户id成功,请牢记该id \n" }) return user_dict`
能提供下修改思路吗,比如涉及哪些函数等
还需要在return_message函数中处理,判断没有时,直接返回url_redirect
感谢,已经解决了
我这边想在代码基础上加入个逻辑,用户id得来自于数据库, 尝试加了个user_exist方法,并给new_user_dict添加了个逻辑,但达不到需求 `def user_exists(user_id):
连接数据库,查询用户id是否存在
def new_user_dict(user_id, send_time): if not user_exists(user_id): return "用户 ID 不存在于数据库,请重新输入或选择已有用户 ID"
能提供下修改思路吗,比如涉及哪些函数等