From 3c6679032d5e603de7f7b3d5066e2be973e508fe Mon Sep 17 00:00:00 2001 From: 997146918 <997146918@qq.com> Date: Mon, 7 Jul 2025 18:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=A7=92=E8=89=B2=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIGC/data.db | Bin 16384 -> 16384 bytes AIGC/main.py | 13 +++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/AIGC/data.db b/AIGC/data.db index 86548e74aeec9fa01cd406262843dbf0cf387b57..83fb5d4396e1b062865af9f184b1f7884d6dac3f 100644 GIT binary patch delta 141 zcmZo@U~Fh$oFL7}K2gS*k$q#r5`HdbzHA151HPAh*_#CgV)<-pm^m5b86~w18wH>4 zS@5)fEf5($>zMGoZT|Ch)1Pgg`gHr!=PSCO?&x^2ZXrly&aUU1cRyP{^~sJ|llRFx oZGI^y&B(>ff0u#(8~pwCkStTtuHD703$FHGynhq diff --git a/AIGC/main.py b/AIGC/main.py index 9dfd16d..6c81eae 100644 --- a/AIGC/main.py +++ b/AIGC/main.py @@ -95,6 +95,14 @@ async def handle_characterlist(client: WebSocket): protocol["data"] = json.dumps(characterforUE) await senddata(client, protocol) +async def handle_addcharacter(client: WebSocket, chracterJson: str): + ### 添加角色到数据库 ### + character_info = json.loads(chracterJson) + id = database.add_character(character_info) + logger.log(logging.INFO, f"添加角色到数据库 id = {id}") + # id = database.add_character({"name":"张三","age":35,"personality":"成熟稳重/惜字如金","profession":"阿里巴巴算法工程师" + # ,"characterBackground":"浙大计算机系毕业,专注AI优化项目","chat_style":"请在对话中表现出专业、冷静、惜字如金。用口语化的方式简短回答"}) + async def process_protocol_json(json_str: str, client: WebSocket): ### 处理协议JSON ### try: @@ -103,6 +111,8 @@ async def process_protocol_json(json_str: str, client: WebSocket): data = protocol.get("data") if cmd == "CharacterList": await handle_characterlist(client) + elif cmd == "AddCharacter": + await handle_addcharacter(client, data) except json.JSONDecodeError as e: print(f"JSON解析错误: {e}") @@ -263,8 +273,7 @@ if __name__ == "__main__": #Test database database = DatabaseHandle() - id = database.add_character({"name":"张三","age":35,"personality":"成熟稳重/惜字如金","profession":"阿里巴巴算法工程师" - ,"characterBackground":"浙大计算机系毕业,专注AI优化项目","chat_style":"请在对话中表现出专业、冷静、惜字如金。用口语化的方式简短回答"}) + id = database.add_character({"name":"李明","age":30,"personality":"活泼健谈","profession":"产品经理" ,"characterBackground":"公司资深产品经理","chat_style":"热情"})