Upload 5 files
Browse files- Dockerfile +1 -1
- README.md +1 -1
- app.py +21 -17
- 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.
|
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:
|
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'), #
|
16 |
-
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
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 |
-
'
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
self.memory.set_variable("word", req.word)
|
44 |
self.memory.append_history(
|
45 |
-
'
|
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('
|
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('
|
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 |
-
|
3 |
-
|
4 |
-
这是几个具体的描述例子:1. 也可以向下 2. 喜欢蛇 3. 吃火锅必备):
|
5 |
"""
|
6 |
|
7 |
VOTE_PROMPT = """{history}
|
8 |
-
|
9 |
-
|
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 |
"""
|