Update app.py
#14
by
uskybox
- opened
app.py
CHANGED
@@ -47,6 +47,7 @@ class SpyAgent(BasicAgent):
|
|
47 |
def interact(self, req=AgentReq) -> AgentResp:
|
48 |
logger.info("spy interact: {}".format(req))
|
49 |
if req.status == STATUS_ROUND:
|
|
|
50 |
prompt = format_prompt(DESC_PROMPT,
|
51 |
{"name": self.memory.load_variable("name"),
|
52 |
"word": self.memory.load_variable("word"),
|
@@ -55,12 +56,15 @@ class SpyAgent(BasicAgent):
|
|
55 |
logger.info("prompt:" + prompt)
|
56 |
result = self.llm_caller(prompt)
|
57 |
logger.info("spy interact result: {}".format(result))
|
|
|
|
|
58 |
return AgentResp(success=True, result=result, errMsg=None)
|
59 |
|
60 |
elif req.status == STATUS_VOTE:
|
61 |
self.memory.append_history('主持人: 到了投票的时候了。每个人,请指向你认为可能是卧底的人。')
|
62 |
choices = [name for name in req.message.split(",") if name != self.memory.load_variable("name")] # 排除自己
|
63 |
self.memory.set_variable("choices", choices)
|
|
|
64 |
prompt = format_prompt(VOTE_PROMPT, {"name": self.memory.load_variable("name"),
|
65 |
"choices": choices,
|
66 |
"history": "\n".join(self.memory.load_history())
|
@@ -68,6 +72,8 @@ class SpyAgent(BasicAgent):
|
|
68 |
logger.info("prompt:" + prompt)
|
69 |
result = self.llm_caller(prompt)
|
70 |
logger.info("spy interact result: {}".format(result))
|
|
|
|
|
71 |
return AgentResp(success=True, result=result, errMsg=None)
|
72 |
else:
|
73 |
raise NotImplementedError
|
|
|
47 |
def interact(self, req=AgentReq) -> AgentResp:
|
48 |
logger.info("spy interact: {}".format(req))
|
49 |
if req.status == STATUS_ROUND:
|
50 |
+
# 填充 DESC_PROMPT 模板
|
51 |
prompt = format_prompt(DESC_PROMPT,
|
52 |
{"name": self.memory.load_variable("name"),
|
53 |
"word": self.memory.load_variable("word"),
|
|
|
56 |
logger.info("prompt:" + prompt)
|
57 |
result = self.llm_caller(prompt)
|
58 |
logger.info("spy interact result: {}".format(result))
|
59 |
+
# 将描述发送到公共聊天区域
|
60 |
+
self.memory.append_history(f"{self.memory.load_variable('name')}: {result}")
|
61 |
return AgentResp(success=True, result=result, errMsg=None)
|
62 |
|
63 |
elif req.status == STATUS_VOTE:
|
64 |
self.memory.append_history('主持人: 到了投票的时候了。每个人,请指向你认为可能是卧底的人。')
|
65 |
choices = [name for name in req.message.split(",") if name != self.memory.load_variable("name")] # 排除自己
|
66 |
self.memory.set_variable("choices", choices)
|
67 |
+
# 填充 VOTE_PROMPT 模板
|
68 |
prompt = format_prompt(VOTE_PROMPT, {"name": self.memory.load_variable("name"),
|
69 |
"choices": choices,
|
70 |
"history": "\n".join(self.memory.load_history())
|
|
|
72 |
logger.info("prompt:" + prompt)
|
73 |
result = self.llm_caller(prompt)
|
74 |
logger.info("spy interact result: {}".format(result))
|
75 |
+
# 将投票结果发送到公共聊天区域
|
76 |
+
self.memory.append_history(f"{self.memory.load_variable('name')}: 我投票给 {result}。")
|
77 |
return AgentResp(success=True, result=result, errMsg=None)
|
78 |
else:
|
79 |
raise NotImplementedError
|