diff --git a/AIGC/data.db b/AIGC/data.db index 86548e7..83fb5d4 100644 Binary files a/AIGC/data.db and b/AIGC/data.db differ 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":"热情"})