Spaces:
Running
on
A10G
Running
on
A10G
GitLab CI
commited on
Commit
·
b0b3162
1
Parent(s):
f5202db
Update game build from GitLab CI
Browse files- server/ActionProcessor.py +55 -29
- server/static/godot/index.pck +0 -0
server/ActionProcessor.py
CHANGED
@@ -19,6 +19,18 @@ logger = logging.getLogger(__name__)
|
|
19 |
|
20 |
|
21 |
class ActionProcessor(Thread):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def __init__(
|
23 |
self,
|
24 |
text_queue: "Queue[str]",
|
@@ -32,36 +44,45 @@ class ActionProcessor(Thread):
|
|
32 |
self.mistral_client = Mistral(api_key=mistral_api_key)
|
33 |
self.daemon = True # Thread will exit when main program exits
|
34 |
|
35 |
-
def
|
36 |
"""Get sentiment analysis for input text."""
|
37 |
messages = [
|
38 |
{
|
39 |
-
"role": "
|
40 |
-
"content":
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
63 |
""",
|
64 |
-
}
|
|
|
|
|
|
|
|
|
65 |
]
|
66 |
|
67 |
response = self.mistral_client.chat.complete(
|
@@ -96,10 +117,15 @@ class ActionProcessor(Thread):
|
|
96 |
candidate = self.text_buffers[1]
|
97 |
|
98 |
if len(self.text_buffers[0]) < len(candidate) >= len(self.text_buffers[2]):
|
99 |
-
|
|
|
|
|
|
|
|
|
100 |
return {
|
101 |
-
"
|
102 |
-
"sentiment":
|
|
|
103 |
"time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
104 |
}
|
105 |
|
|
|
19 |
|
20 |
|
21 |
class ActionProcessor(Thread):
|
22 |
+
valid_action: List[str] = [
|
23 |
+
"DropBleach",
|
24 |
+
"DropSyringe",
|
25 |
+
"DropFork",
|
26 |
+
"GoToLivingRoom",
|
27 |
+
"GoToKitchen",
|
28 |
+
"GoToBedroom",
|
29 |
+
"StopCrying",
|
30 |
+
"Come",
|
31 |
+
"None",
|
32 |
+
]
|
33 |
+
|
34 |
def __init__(
|
35 |
self,
|
36 |
text_queue: "Queue[str]",
|
|
|
44 |
self.mistral_client = Mistral(api_key=mistral_api_key)
|
45 |
self.daemon = True # Thread will exit when main program exits
|
46 |
|
47 |
+
def get_action_and_sentiment(self, input_text: str) -> str:
|
48 |
"""Get sentiment analysis for input text."""
|
49 |
messages = [
|
50 |
{
|
51 |
+
"role": "system",
|
52 |
+
"content": """
|
53 |
+
You are an AI Agent in a video game. You're listening to a parent giving their baby instructions, translate them into game functions. The following game functions are:
|
54 |
+
|
55 |
+
- DropBleach: Ask the baby to drop the bleach (or 'Javel').
|
56 |
+
- DropSyringe: Ask the baby to drop the syringe.
|
57 |
+
- DropFork: Ask the baby to drop the fork.
|
58 |
+
- GoToLivingRoom: Ask the baby to go to the living room.
|
59 |
+
- GoToKitchen: Ask the baby to go to the kitchen.
|
60 |
+
- GoToBedroom: Ask the baby to go to the bedroom.
|
61 |
+
- StopCrying: Ask the baby to stop crying.
|
62 |
+
- Come: Ask the baby to come towards the camera, or follow the sound of the voice.
|
63 |
+
- None: The baby does not need to take any action.
|
64 |
+
|
65 |
+
You must also determine whether the parenting sentiment behind the command is positive or negative, based on the following criteria:
|
66 |
+
- If the statement includes the baby’s name ("Harold"), it is considered positive parenting.
|
67 |
+
- If the statement consists only of direct commands without affectionate or encouraging words (e.g., "good boy," "better"), it is considered negative parenting.
|
68 |
+
Your response should strictly follow this JSON format as an array of strings:
|
69 |
+
|
70 |
+
```json
|
71 |
+
[action,sentiment]
|
72 |
+
```
|
73 |
+
|
74 |
+
for example:
|
75 |
+
Input: "Don't put the fork in the socket!"
|
76 |
+
Output: ["DropFork", "negative"]
|
77 |
+
|
78 |
+
Input: "Harold, please don't drink the bleach!"
|
79 |
+
Output: ["DropBleach", "positive"]
|
80 |
""",
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"role": "user",
|
84 |
+
"content": f"Transcription fragments: {input_text}",
|
85 |
+
},
|
86 |
]
|
87 |
|
88 |
response = self.mistral_client.chat.complete(
|
|
|
117 |
candidate = self.text_buffers[1]
|
118 |
|
119 |
if len(self.text_buffers[0]) < len(candidate) >= len(self.text_buffers[2]):
|
120 |
+
action_and_sentiment = self.get_action_and_sentiment(candidate)
|
121 |
+
action, sentiment = action_and_sentiment.split(",")
|
122 |
+
|
123 |
+
if action not in self.valid_action:
|
124 |
+
action = "None"
|
125 |
return {
|
126 |
+
"action": action,
|
127 |
+
"sentiment": sentiment,
|
128 |
+
"voice": candidate,
|
129 |
"time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
130 |
}
|
131 |
|
server/static/godot/index.pck
CHANGED
Binary files a/server/static/godot/index.pck and b/server/static/godot/index.pck differ
|
|