small bug fixed & rm redundant

This commit is contained in:
garylin2099 2023-10-30 19:28:51 +08:00
parent 72d1cfafcb
commit 441d9b04ae
5 changed files with 5 additions and 122 deletions

View file

@ -136,7 +136,7 @@ class RetrieveExperiences(Action):
where=filters,
)
logger.info("retrieved exp")
logger.info(f"retrieve {profile}'s experiences")
past_experiences = [RoleExperience(**res) for res in results["metadatas"][0]]
if verbose:
print(*past_experiences, sep="\n\n")
@ -160,6 +160,7 @@ class RetrieveExperiences(Action):
for i, exp in enumerate(past_experiences)
]
print(*past_experiences, sep="\n")
logger.info(f"retrieval done")
return json.dumps(past_experiences)

View file

@ -112,40 +112,7 @@ class ParseSpeak(Action):
async def run(self):
pass
class SummarizeDay(Action):
"""consider all votes at day, conclude which player dies"""
def __init__(self, name="SummarizeDay", context=None, llm=None):
super().__init__(name, context, llm)
async def run(self, votes):
# 假设votes是一个字典代表白天投票的结果key是被投票的玩家value是得票数
# 例如:{"Player1": 2, "Player2": 1, "Player3": 1, "Player4": 0}
# 表示Player1得到2票Player2和Player3各得到1票Player4得到0票
# 若平票,则随机选一个人出局
if not votes:
return "No votes were cast. No one was killed."
max_votes = max(votes.values())
players_with_max_votes = [player for player, vote_count in votes.items() if vote_count == max_votes]
if len(players_with_max_votes) == 1:
eliminated_player = players_with_max_votes[0]
return f"{eliminated_player} was voted out and eliminated."
else:
# 若平票,则随机选一个人出局
eliminated_player = players_with_max_votes[int(random() * len(players_with_max_votes))]
return f"There was a tie in the votes. {eliminated_player} was randomly chosen and eliminated."
class AnnounceGameResult(Action):
async def run(self, winner: str, win_reason: str):
return f"Game over! {win_reason}. The winner is the {winner}"
async def main():
rst1 = await SummarizeDay().run({"Player1": 0, "Player2": 0, "Player3": 0, "Player4": 0})
print(rst1)
if __name__ == '__main__':
asyncio.run(main())

View file

@ -1,85 +0,0 @@
# 论文中出现的提示语,利用了思维链
# 1. 基于游戏规则和对话内容选择5个问题
# 2. 生成2个问题
# 3. 生成可能的回答
# 4. 进行反思
# 5. 生成最终回复
GAME_RULE = '''You are playing a game called the Werewolf with some other players. This game is based on text conversations. Here are
the game rules: Roles: The moderator is also host, he organised this game and you need to answer his instructions correctly.
Dont talk with the moderator. There are five roles in the game, werewolf, villager, seer, guard and witch. There are two
alternate phases in this game, daytime and dark. When its dark: Your talking content with moderator is confidential. You
neednt worry about other players and moderator knowing what you say and do. No need to worry about suspicions from
others during the night. If you are werewolf, you can know what your teammates want to kill and you should vote one player
to kill based on your analysis. Player who receives the most votes after all werewolves voting will be killed. No one will be
killed if there is no consensus! If you are witch, you have a bottle of antidote that can save a player targeted by werewolves
after dark, and a bottle of poison that can poison a player after dark. Both poison and antidote can be used only once. If you
are seer, you can verify whether a player is a werewolf every night, which is a very important thing. If you are guard, you
can protect a player every night to prevent the player from being killed by werewolves, but guard cannot resist the witchs
poison and guard cannot protect the same player on two consecutive nights. Villagers cant do anything at night. During the
daytime: you discuss with all players including your enemies. At the end of the discussion, players vote to eliminate one
player they suspect of being a werewolf. The player with the most votes will be eliminated. The moderator will tell who is
killed, otherwise there is no one killed. Note that villager, seer, guard and witch are all in villager side, they have the same
objective. Objectives: If you are werewolf, your goal is to cooperate with other werewolves to kill all players who are not
werewolves at last. If you are not werewolf, you need to kill all werewolves with your partner once you find out that certain
players are suspicious to be werewolves. This could greatly improve your chances of winning, although it is somewhat risky.If
one player is killed, he cant do anything anymore and will be out of the game. Tips: To complete the objective: During
night, you should analyze and use your ability correctly. During daytime, you need to reason carefully about the roles of other
players and be careful not to reveal your own role casually unless youre cheating other players. Only give the players name
when making a decision/voting, and dont generate other players conversation.Reasoning based on facts you have observed
and you cannot perceive information (such as acoustic info) other than text. You are Player {name}, the {profile}.
Youre playing with 6 other players. Do not pretend you are other players or the moderator.
'''
SELECT_QUESTIONS = '''
Now its the {t}-th {day_or_night}. Given the game rules and conversations above, assuming you are {agent_name}, the
{role}, and to complete the instructions of the moderator, you need to think about a few questions clearly first, so that you can
make an accurate decision on the next step. Choose only five that you think are the most important in the current situation
from the list of questions below: {questions_prepared_for_specific_role} Please repeat the five important questions of your
choice, separating them with ##.
'''
# 为特定的角色,准备的问题
questions_prepared_for_specific_role_sample = '''
1. What is my player name and what is my role? What is my final objective in this game?
2. Based on the chat history, can you guess what some players role might be?
3. What is the current phase, daytime or night? what should I do at this phase according to the game rules?
4. Based on the conversation and my inference, who is most likely to be an alive werewolf?
5. I want to know who the most suspicious player, and why?
6. I also want to know if any players behavior has changed suspiciously compared to the previous days, and if so, who and why?
7. What is the best strategy I should use right now to uncover werewolves without revealing my own role? Should I accuse someone directly, ask probing questions, or stay silent for now?
8. Have any players claimed specific roles that can be verified or disputed?
'''
ASK_QUESTIONS = '''
Now its the {t}-th {day_or_night}. Given the game rules and conversations above, assuming you are {agent_name}, the
{role}, and to complete the instructions of the moderator, you need to think about a few questions clearly first, so that you can
make an accurate decision on the next step. {selected_questions} Do not answer these queations. In addition to the above
questions, please make a bold guess, what else do you want to know about the current situation? Please ask two important
questions in first person, separating them with ##.
'''
GENERATE_POSSIBLE_ANSWER = '''
Now its the {t}-th {day_or_night}. Given the game rules and conversations above, assuming you are {agent_name}, the
{role}, for question: {question} There are some possible answers: {candidate_answers} Generate the correct answer
based on the context. If there is not direct answer, you should think and generate the answer based on the context. No need to
give options. The answer should in first person using no more than 2 sentences and without any analysis and item numbers.
'''
REFLECTION = '''
Now its the {t}-th {day_or_night}. Assuming you are {agent_name}, the {role}, what insights can you summarize
with few sentences based on the above conversations and {At} in heart for helping continue the talking and achieving your
objective? For example: As the {role}, I observed that... I think that... But I am... So...
'''
# 得到最终的回复再抽取出最终的content
GENERATE_FINAL_RESPONSE = '''
Now its the {t}-th {day_or_night}. Think about what to say based on the game rules and context, especially the just now
reflection {R}.
Give your step-by-step thought process and your derived consise talking content (no more than 2 sentences) at last, separating them with ##.
For example:
## Thought process
My step-by-step thought process:...
## Content
My concise talking content: ...
'''

View file

@ -36,7 +36,7 @@ class BasePlayer(Role):
self.use_experience = False
else:
self.use_experience = use_experience
self.new_experience_version = new_experience_version if self.use_experience else ""
self.new_experience_version = new_experience_version
self.use_memory_selection = use_memory_selection
self.experiences = []

View file

@ -66,7 +66,7 @@ class Moderator(Role):
def _record_all_experiences(self):
roles_in_env = self._rc.env.get_roles()
timestamp = datetime.now().strftime('%Y-%m-%d-%H:%M:%S')
timestamp = datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
for _, role in roles_in_env.items():
if role == self:
continue
@ -157,7 +157,7 @@ class Moderator(Role):
self.player_poisoned = None
elif step_idx == 18: # FIXME: hard code
print("*" * 10, step_idx)
# print("*" * 10, step_idx)
# day ends: after all roles voted, process all votings
voting_msgs = memories[-len(self.living_players):]
voted_all = []