WhoIsSpyAIAgents commited on
Commit
10ec55c
·
verified ·
1 Parent(s): 86f8dbe

Upload 5 files

Browse files
Files changed (4) hide show
  1. Dockerfile +1 -1
  2. README.md +1 -1
  3. app.py +21 -17
  4. prompts.py +4 -5
Dockerfile CHANGED
@@ -8,7 +8,7 @@ WORKDIR /app
8
 
9
  COPY --chown=user ./requirements.txt requirements.txt
10
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
- RUN pip3 install spy-agent-build-sdk==0.0.16
12
  COPY --chown=user . /app
13
 
14
  CMD ["python3", "app.py"]
 
8
 
9
  COPY --chown=user ./requirements.txt requirements.txt
10
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+ RUN pip3 install spy-agent-build-sdk==0.0.18
12
  COPY --chown=user . /app
13
 
14
  CMD ["python3", "app.py"]
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: 谁是卧底Agent示例
3
  emoji: 😻
4
  colorFrom: yellow
5
  colorTo: blue
 
1
  ---
2
+ title: Who Is Spy Agent Example
3
  emoji: 😻
4
  colorFrom: yellow
5
  colorTo: blue
app.py CHANGED
@@ -12,8 +12,8 @@ import os
12
 
13
  def get_aliyun_response(prompt, model_name="qwen-turbo"):
14
  client = OpenAI(
15
- api_key=os.getenv('API_KEY'), # 请在此处用您的API Key进行替换
16
- base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # 填写DashScope服务的base_url
17
  )
18
  completion = client.chat.completions.create(
19
  model=model_name,
@@ -34,30 +34,34 @@ class SpyAgent(BasicAgent):
34
 
35
  def perceive(self, req=AgentReq):
36
  logger.info("spy perceive: {}".format(req))
37
- if req.status == STATUS_START: # 开始新的一局比赛
38
  self.memory.clear()
39
  self.memory.set_variable("name", req.message)
40
  self.memory.append_history(
41
- '主持人: 女士们先生们,欢迎来到《谁是卧底》游戏!我们有一个由6名玩家组成的小组,在其中有一名卧底。让我们开始吧!每个人都会收到一张纸。其中5人的纸上拥有相同的单词,而卧底则会收到含义上相似的单词。我们将大多数人拿到的单词称为"公共词",将卧底拿到的单词称为"卧底词"。一旦你拿到了你的单词,首先需要根据其他人的发言判断自己是否拿到了卧底词。如果判断自己拿到了卧底词,请猜测公共词是什么,然后描述公共词来混淆视听,避免被投票淘汰。如果判断自己拿到了公共词,请思考如何巧妙地描述它而不泄露它,不能让卧底察觉,也要给同伴暗示。每人每轮用一句话描述自己拿到的词语,每个人的描述禁止重复,话中不能出现所持词语。每轮描述完毕,所有在场的人投票选出怀疑是卧底的那个人,得票数最多的人出局。卧底出局则游戏结束,若卧底未出局,游戏继续。现在游戏开始。')
42
- elif req.status == STATUS_DISTRIBUTION: # 分配单词
 
 
 
 
43
  self.memory.set_variable("word", req.word)
44
  self.memory.append_history(
45
- '主持人: 你好,{},你分配到的单词是:{}'.format(self.memory.load_variable("name"), req.word))
46
- elif req.status == STATUS_ROUND: # 发言环节
47
  if req.name:
48
- # 其他玩家发言
49
  self.memory.append_history(req.name + ': ' + req.message)
50
  else:
51
- # 主持人发言
52
- self.memory.append_history('主持人: 现在进入第{}轮。'.format(str(req.round)))
53
- self.memory.append_history('主持人: 每个玩家描述自己分配到的单词。')
54
- elif req.status == STATUS_VOTE: # 投票环节
55
  self.memory.append_history(req.name + ': ' + req.message)
56
- elif req.status == STATUS_VOTE_RESULT: # 投票环节
57
  if req.name:
58
- self.memory.append_history('主持人: 投票结果是:{}'.format(req.name))
59
  else:
60
- self.memory.append_history('主持人: 无人出局。')
61
  elif req.status == STATUS_RESULT:
62
  self.memory.append_history(req.message)
63
  else:
@@ -77,8 +81,8 @@ class SpyAgent(BasicAgent):
77
  return AgentResp(success=True, result=result, errMsg=None)
78
 
79
  elif req.status == STATUS_VOTE:
80
- self.memory.append_history('主持人: 到了投票的时候了。每个人,请指向你认为可能是卧底的人。')
81
- choices = [name for name in req.message.split(",") if name != self.memory.load_variable("name")] # 排除自己
82
  self.memory.set_variable("choices", choices)
83
  prompt = format_prompt(VOTE_PROMPT, {"name": self.memory.load_variable("name"),
84
  "choices": choices,
 
12
 
13
  def get_aliyun_response(prompt, model_name="qwen-turbo"):
14
  client = OpenAI(
15
+ api_key=os.getenv('API_KEY'), # Replace with your own API
16
+ base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
17
  )
18
  completion = client.chat.completions.create(
19
  model=model_name,
 
34
 
35
  def perceive(self, req=AgentReq):
36
  logger.info("spy perceive: {}".format(req))
37
+ if req.status == STATUS_START: # Start a new game
38
  self.memory.clear()
39
  self.memory.set_variable("name", req.message)
40
  self.memory.append_history(
41
+ f"Host: Ladies and gentlemen, welcome to the game of 'Who is the Spy?' We have a group of 6 players, among whom one is a spy. Each person will receive a card. 5 of these cards will have the same word, while the spy will receive a different word."
42
+ f"Once you have your word, take some time to think about how to cleverly describe it without revealing it. Each person will use one sentence to describe their word in each round, and no one can repeat descriptions. The word itself cannot be mentioned."
43
+ f"After each round of descriptions, everyone present votes to identify the person they suspect is the spy. The person with the most votes is eliminated. If the spy is eliminated, the game ends; if not, the game continues."
44
+ f"You need to judge whether you are the spy based on the context. If you are the spy, you should try to confuse others and avoid being voted out. If you are not the spy, you should ensure that the spy remains undetected while providing hints to teammates."
45
+ )
46
+ elif req.status == STATUS_DISTRIBUTION: # Assign words
47
  self.memory.set_variable("word", req.word)
48
  self.memory.append_history(
49
+ 'Host: Hello,{}. The word assigned to you is {}'.format(self.memory.load_variable("name"), req.word))
50
+ elif req.status == STATUS_ROUND: # Speech
51
  if req.name:
52
+ # from other players
53
  self.memory.append_history(req.name + ': ' + req.message)
54
  else:
55
+ # from the host
56
+ self.memory.append_history('Host: Now entering round {}.'.format(str(req.round)))
57
+ self.memory.append_history('Host: Each player describes the word they have been assigned.')
58
+ elif req.status == STATUS_VOTE: # Vote
59
  self.memory.append_history(req.name + ': ' + req.message)
60
+ elif req.status == STATUS_VOTE_RESULT:
61
  if req.name:
62
+ self.memory.append_history('Host: The voting results are: {}.'.format(req.name))
63
  else:
64
+ self.memory.append_history('Host: No one is out.')
65
  elif req.status == STATUS_RESULT:
66
  self.memory.append_history(req.message)
67
  else:
 
81
  return AgentResp(success=True, result=result, errMsg=None)
82
 
83
  elif req.status == STATUS_VOTE:
84
+ self.memory.append_history("Host: It's time for voting.")
85
+ choices = [name for name in req.message.split(",") if name != self.memory.load_variable("name")] # Exclude self
86
  self.memory.set_variable("choices", choices)
87
  prompt = format_prompt(VOTE_PROMPT, {"name": self.memory.load_variable("name"),
88
  "choices": choices,
prompts.py CHANGED
@@ -1,10 +1,9 @@
1
  DESC_PROMPT = """{history}
2
- 你是{name},你的词汇为{word}
3
- 根据游戏规则和此前的对话,请直接输出你的发言,不需要输出你的名字(注意,你的描述应该言简意赅,并且严格模仿真实人类的描述语法/标点使用,
4
- 这是几个具体的描述例子:1. 也可以向下 2. 喜欢蛇 3. 吃火锅必备):
5
  """
6
 
7
  VOTE_PROMPT = """{history}
8
- 你是{name}
9
- 从列表中选择你认为是卧底的人的名字:{choices},然后直接返回名字:
10
  """
 
1
  DESC_PROMPT = """{history}
2
+ Your name is {name}. Your word is {word}.
3
+ According to the game rules and previous conversations, please directly provide your statement without including your name (Note: your description should be concise):
 
4
  """
5
 
6
  VOTE_PROMPT = """{history}
7
+ Your name is {name}.
8
+ Choose a name you think is the spy from the list {choices}, and return the name directly:
9
  """