add get_embedding log

This commit is contained in:
better629 2024-04-10 17:17:33 +08:00
parent d4a40bd988
commit c43a1cada7
3 changed files with 21 additions and 19 deletions

View file

@ -46,8 +46,8 @@ STEP_INSTRUCTIONS = {
},
2: {
"content": """Guard, now tell me who you protect tonight?
You only choose one from the following living options please: {living_players}.
Or you can pass. For example: Protect ...""",
You only choose one from the following living options please: {living_players}.
Or you can pass. For example: Protect ...""",
"send_to": {RoleType.GUARD.value},
"restricted_to": {RoleType.MODERATOR.value, RoleType.GUARD.value},
},
@ -59,9 +59,9 @@ STEP_INSTRUCTIONS = {
},
5: {
"content": """Werewolves, I secretly tell you that {werewolf_players} are
all of the 2 werewolves! Keep in mind you are teammates. The rest players are not werewolves.
choose one from the following living options please:
{living_players}. For example: Kill ...""",
all of the 2 werewolves! Keep in mind you are teammates. The rest players are not werewolves.
choose one from the following living options please:
{living_players}. For example: Kill ...""",
"send_to": {RoleType.WEREWOLF.value},
"restricted_to": {RoleType.MODERATOR.value, RoleType.WEREWOLF.value},
},
@ -69,14 +69,14 @@ STEP_INSTRUCTIONS = {
7: {"content": "Witch, please open your eyes!", "send_to": {RoleType.MODERATOR.value}, "restricted_to": empty_set},
8: {
"content": """Witch, tonight {player_hunted} has been killed by the werewolves.
You have a bottle of antidote, would you like to save him/her? If so, say "Save", else, say "Pass".""",
You have a bottle of antidote, would you like to save him/her? If so, say "Save", else, say "Pass".""",
"send_to": {RoleType.WITCH.value},
"restricted_to": {RoleType.MODERATOR.value, RoleType.WITCH.value},
}, # 要先判断女巫是否有解药,再去询问女巫是否使用解药救人
9: {
"content": """Witch, you also have a bottle of poison, would you like to use it to kill one of the living players?
Choose one from the following living options: {living_players}.
If so, say ONLY "Poison PlayerX", replace PlayerX with the actual player name, else, say "Pass".""",
Choose one from the following living options: {living_players}.
If so, say ONLY "Poison PlayerX", replace PlayerX with the actual player name, else, say "Pass".""",
"send_to": {RoleType.WITCH.value},
"restricted_to": {RoleType.MODERATOR.value, RoleType.WITCH.value},
}, #
@ -84,7 +84,7 @@ STEP_INSTRUCTIONS = {
11: {"content": "Seer, please open your eyes!", "send_to": {RoleType.MODERATOR.value}, "restricted_to": empty_set},
12: {
"content": """Seer, you can check one player's identity. Who are you going to verify its identity tonight?
Choose only one from the following living options:{living_players}.""",
Choose only one from the following living options:{living_players}.""",
"send_to": {RoleType.SEER.value},
"restricted_to": {RoleType.MODERATOR.value, RoleType.SEER.value},
},
@ -102,14 +102,14 @@ STEP_INSTRUCTIONS = {
},
16: {
"content": """Living players: {living_players}, now freely talk about the current situation based on your observation and
reflection with a few sentences. Decide whether to reveal your identity based on your reflection.""",
reflection with a few sentences. Decide whether to reveal your identity based on your reflection.""",
"send_to": {MESSAGE_ROUTE_TO_ALL}, # send to all to speak in daytime
"restricted_to": empty_set,
},
17: {
"content": """Now vote and tell me who you think is the werewolf. Dont mention your role.
You only choose one from the following living options please:
{living_players}. Say ONLY: I vote to eliminate ...""",
You only choose one from the following living options please:
{living_players}. Say ONLY: I vote to eliminate ...""",
"send_to": {MESSAGE_ROUTE_TO_ALL},
"restricted_to": empty_set,
},

View file

@ -19,7 +19,7 @@ class WerewolfExtEnv(ExtEnv):
model_config = ConfigDict(arbitrary_types_allowed=True)
players_state: dict[str, tuple[str, RoleState]] = Field(
default=dict(), description="the player's role type and state by player_name"
default_factory=dict, description="the player's role type and state by player_name"
)
round_idx: int = Field(default=0) # the current round
@ -36,9 +36,9 @@ class WerewolfExtEnv(ExtEnv):
witch_antidote_left: int = Field(default=1, description="should be 1 or 0")
# game current round states, a round is from closing your eyes to the next time you close your eyes
round_hunts: dict[str, str] = Field(default=dict(), description="nighttime wolf hunt result")
round_hunts: dict[str, str] = Field(default_factory=dict, description="nighttime wolf hunt result")
round_votes: dict[str, str] = Field(
default=dict(), description="daytime all players vote result, key=voter, value=voted one"
default_factory=dict, description="daytime all players vote result, key=voter, value=voted one"
)
player_hunted: Optional[str] = Field(default=None)
player_protected: Optional[str] = Field(default=None)
@ -252,8 +252,8 @@ class WerewolfExtEnv(ExtEnv):
if list(self.round_votes.keys()) == self.living_players:
voted_all = list(self.round_votes.values()) # TODO in case of tie vote, check who was voted first
voted_all = [item for item in voted_all if item]
self.player_current_dead = Counter(voted_all).most_common()[0][0]
self._update_players_state([self.player_current_dead])
self.player_current_dead = [Counter(voted_all).most_common()[0][0]]
self._update_players_state(self.player_current_dead)
@mark_as_writeable
def wolf_kill_someone(self, wolf_name: str, player_name: str):
@ -321,7 +321,7 @@ class WerewolfExtEnv(ExtEnv):
if self.player_poisoned:
self.player_current_dead.append(self.player_poisoned)
self._update_players_state([self.player_current_dead])
self._update_players_state(self.player_current_dead)
# reset
self.player_hunted = None
self.player_protected = None

View file

@ -49,6 +49,7 @@ def read_csv_to_list(curr_file: str, header=False, strip_trail=True):
def get_embedding(text, model: str = "text-embedding-ada-002"):
text = text.replace("\n", " ")
embedding = None
if not text:
text = "this is blank"
for idx in range(3):
@ -56,7 +57,8 @@ def get_embedding(text, model: str = "text-embedding-ada-002"):
embedding = (
OpenAI(api_key=config.llm.api_key).embeddings.create(input=[text], model=model).data[0].embedding
)
except Exception:
except Exception as exp:
logger.info(f"get_embedding failed, exp: {exp}, will retry.")
time.sleep(5)
if not embedding:
raise ValueError("get_embedding failed")