Spaces:
Runtime error
Runtime error
Greg Thompson
commited on
Commit
•
c6f9773
1
Parent(s):
67c73c6
Update fsm manager to handle multiple cases
Browse files
mathtext_fastapi/conversation_manager.py
CHANGED
@@ -116,6 +116,25 @@ def manage_math_quiz_fsm(user_message, contact_uuid, type):
|
|
116 |
contact_uuid
|
117 |
).execute()
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
if fsm_check.data == []:
|
120 |
if type == 'addition':
|
121 |
math_quiz_state_machine = MathQuizFSM()
|
@@ -128,7 +147,22 @@ def manage_math_quiz_fsm(user_message, contact_uuid, type):
|
|
128 |
'contact_uuid': contact_uuid,
|
129 |
f'{type}': dump_encoded
|
130 |
}).execute()
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
undump_encoded = base64.b64decode(
|
133 |
fsm_check.data[0][type].encode('utf-8')
|
134 |
)
|
@@ -217,24 +251,24 @@ def return_next_conversational_state(context_data, user_message, contact_uuid):
|
|
217 |
# Used in FSM
|
218 |
# messages = manage_math_quiz_fsm(user_message, contact_uuid)
|
219 |
|
220 |
-
message_package, context_result = use_quiz_module_approach(user_message, context_data)
|
|
|
221 |
|
222 |
if user_message == 'exit':
|
223 |
state_label = 'exit'
|
224 |
else:
|
225 |
state_label = 'addition-question-sequence'
|
226 |
# Used in FSM
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
message_package['state'] = state_label
|
238 |
|
239 |
elif context_data['state'] == 'subtraction-question-sequence' or \
|
240 |
user_message == 'subtract':
|
@@ -323,9 +357,6 @@ def manage_conversation_response(data_json):
|
|
323 |
contact_uuid
|
324 |
)
|
325 |
|
326 |
-
print("MESSAGE PACKAGE")
|
327 |
-
print(message_package)
|
328 |
-
|
329 |
headers = {
|
330 |
'Authorization': f"Bearer {os.environ.get('TURN_AUTHENTICATION_TOKEN')}",
|
331 |
'Content-Type': 'application/json'
|
|
|
116 |
contact_uuid
|
117 |
).execute()
|
118 |
|
119 |
+
# This doesn't allow for when one FSM is present and the other is empty
|
120 |
+
"""
|
121 |
+
1
|
122 |
+
data=[] count=None
|
123 |
+
|
124 |
+
2
|
125 |
+
data=[{'id': 29, 'contact_uuid': 'j43hk26-2hjl-43jk-hnk2-k4ljl46j0ds09', 'addition3': None, 'subtraction': None, 'addition':
|
126 |
+
|
127 |
+
- but problem is there is no subtraction , but it's assuming there's a subtration
|
128 |
+
|
129 |
+
|
130 |
+
Cases
|
131 |
+
- make a completely new record
|
132 |
+
- update an existing record with an existing FSM
|
133 |
+
- update an existing record without an existing FSM
|
134 |
+
"""
|
135 |
+
|
136 |
+
|
137 |
+
# Make a completely new entry
|
138 |
if fsm_check.data == []:
|
139 |
if type == 'addition':
|
140 |
math_quiz_state_machine = MathQuizFSM()
|
|
|
147 |
'contact_uuid': contact_uuid,
|
148 |
f'{type}': dump_encoded
|
149 |
}).execute()
|
150 |
+
# Update an existing record with a new state machine
|
151 |
+
elif not fsm_check.data[0][type]:
|
152 |
+
if type == 'addition':
|
153 |
+
math_quiz_state_machine = MathQuizFSM()
|
154 |
+
else:
|
155 |
+
math_quiz_state_machine = MathSubtractionFSM()
|
156 |
+
messages = [math_quiz_state_machine.response_text]
|
157 |
+
dump_encoded = pickle_and_encode_state_machine(math_quiz_state_machine)
|
158 |
+
|
159 |
+
SUPA.table('state_machines').update({
|
160 |
+
f'{type}': dump_encoded
|
161 |
+
}).eq(
|
162 |
+
"contact_uuid", contact_uuid
|
163 |
+
).execute()
|
164 |
+
# Update an existing record with an existing state machine
|
165 |
+
elif fsm_check.data[0][type]:
|
166 |
undump_encoded = base64.b64decode(
|
167 |
fsm_check.data[0][type].encode('utf-8')
|
168 |
)
|
|
|
251 |
# Used in FSM
|
252 |
# messages = manage_math_quiz_fsm(user_message, contact_uuid)
|
253 |
|
254 |
+
# message_package, context_result = use_quiz_module_approach(user_message, context_data)
|
255 |
+
messages = manage_math_quiz_fsm(user_message, contact_uuid, 'addition')
|
256 |
|
257 |
if user_message == 'exit':
|
258 |
state_label = 'exit'
|
259 |
else:
|
260 |
state_label = 'addition-question-sequence'
|
261 |
# Used in FSM
|
262 |
+
input_prompt = messages.pop()
|
263 |
+
message_package = {
|
264 |
+
'messages': messages,
|
265 |
+
'input_prompt': input_prompt,
|
266 |
+
'state': state_label
|
267 |
+
}
|
268 |
|
269 |
+
# Used in quiz w/ hints
|
270 |
+
# context_data = context_result
|
271 |
+
# message_package['state'] = state_label
|
|
|
272 |
|
273 |
elif context_data['state'] == 'subtraction-question-sequence' or \
|
274 |
user_message == 'subtract':
|
|
|
357 |
contact_uuid
|
358 |
)
|
359 |
|
|
|
|
|
|
|
360 |
headers = {
|
361 |
'Authorization': f"Bearer {os.environ.get('TURN_AUTHENTICATION_TOKEN')}",
|
362 |
'Content-Type': 'application/json'
|