完善角色信息的添加
This commit is contained in:
parent
34bc37e864
commit
3c6679032d
BIN
AIGC/data.db
BIN
AIGC/data.db
Binary file not shown.
13
AIGC/main.py
13
AIGC/main.py
@ -95,6 +95,14 @@ async def handle_characterlist(client: WebSocket):
|
|||||||
protocol["data"] = json.dumps(characterforUE)
|
protocol["data"] = json.dumps(characterforUE)
|
||||||
await senddata(client, protocol)
|
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):
|
async def process_protocol_json(json_str: str, client: WebSocket):
|
||||||
### 处理协议JSON ###
|
### 处理协议JSON ###
|
||||||
try:
|
try:
|
||||||
@ -103,6 +111,8 @@ async def process_protocol_json(json_str: str, client: WebSocket):
|
|||||||
data = protocol.get("data")
|
data = protocol.get("data")
|
||||||
if cmd == "CharacterList":
|
if cmd == "CharacterList":
|
||||||
await handle_characterlist(client)
|
await handle_characterlist(client)
|
||||||
|
elif cmd == "AddCharacter":
|
||||||
|
await handle_addcharacter(client, data)
|
||||||
|
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
print(f"JSON解析错误: {e}")
|
print(f"JSON解析错误: {e}")
|
||||||
@ -263,8 +273,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
#Test database
|
#Test database
|
||||||
database = DatabaseHandle()
|
database = DatabaseHandle()
|
||||||
id = database.add_character({"name":"张三","age":35,"personality":"成熟稳重/惜字如金","profession":"阿里巴巴算法工程师"
|
|
||||||
,"characterBackground":"浙大计算机系毕业,专注AI优化项目","chat_style":"请在对话中表现出专业、冷静、惜字如金。用口语化的方式简短回答"})
|
|
||||||
|
|
||||||
id = database.add_character({"name":"李明","age":30,"personality":"活泼健谈","profession":"产品经理"
|
id = database.add_character({"name":"李明","age":30,"personality":"活泼健谈","profession":"产品经理"
|
||||||
,"characterBackground":"公司资深产品经理","chat_style":"热情"})
|
,"characterBackground":"公司资深产品经理","chat_style":"热情"})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user