GitLab CI commited on
Commit
b0b3162
·
1 Parent(s): f5202db

Update game build from GitLab CI

Browse files
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 get_sentiment_and_action(self, input_text: str) -> str:
36
  """Get sentiment analysis for input text."""
37
  messages = [
38
  {
39
- "role": "user",
40
- "content": f"""
41
- The following transcription is a broken transmission overheard by a baby through a baby walkie-talkie. The transmission contains **fragments** of negative parenting commands, and your task is to reconstruct the most likely intended message.
42
-
43
- Analyze the provided transcription and follow these steps:
44
-
45
- 1. **Reconstruct the most logical full command** by analyzing the given fragments and arranging them into a coherent order.
46
- 2. **Select the closest matching three-word action** from the following predefined options:
47
- ["drop it", "don't drink", "None", "stay back", "stop touching", "move away", "none"].
48
- Always choose the most contextually relevant option. If no match is appropriate, select "None."
49
- 3. Determine whether the parenting sentiment behind the command is positive or negative**, based on the following criteria:
50
- - If the statement includes the baby’s name ("Harold"), it is considered **positive parenting**.
51
- - If the statement consists only of direct commands without affectionate or encouraging words (e.g., "good boy," "better"), it is considered **negative parenting**.
52
-
53
- Your response should strictly follow this JSON format as an array of strings:
54
-
55
- ```json
56
- [action,sentiment]
57
- ```
58
-
59
- for example:
60
- ["drop it", "negative"]
61
- ["none", "positive"]
62
- Transcription fragments: "{input_text}"
 
 
 
 
 
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
- sentiment_and_action = self.get_sentiment_and_action(candidate)
 
 
 
 
100
  return {
101
- "type": "action",
102
- "sentiment": sentiment_and_action,
 
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