Spaces:
Sleeping
Sleeping
update invalid input check
Browse files- chatbot_simulator.py +7 -6
chatbot_simulator.py
CHANGED
@@ -243,7 +243,8 @@ class ChatbotSimulation:
|
|
243 |
match = re.match(pattern, user_input)
|
244 |
|
245 |
if not match:
|
246 |
-
return [False,
|
|
|
247 |
|
248 |
# Extract parsed components
|
249 |
action_type = match.group("action_type").lower()
|
@@ -253,14 +254,14 @@ class ChatbotSimulation:
|
|
253 |
# Validate button number and action type
|
254 |
if button_name not in valid_buttons:
|
255 |
return [False,
|
256 |
-
"Invalid Button number! Recall: Each button is in the format: `number. button name: action_type
|
257 |
if action_type != valid_buttons[button_name]:
|
258 |
return [False,
|
259 |
"Invalid action type! Recall: Each button is in the format: `number. button name: action_type`"] # Action type must match the button's specified type
|
260 |
-
if action_type == "
|
261 |
return [False,
|
262 |
-
"Missing Query for action type '
|
263 |
-
if action_type != "
|
264 |
return [False,
|
265 |
-
"Non-`
|
266 |
return [True, 'Pass']
|
|
|
243 |
match = re.match(pattern, user_input)
|
244 |
|
245 |
if not match:
|
246 |
+
return [False,
|
247 |
+
"Your input doesn't match the format: action_type(button number), OR if text_box, use text_box(button number, query), eg. noop(12). No indent before input and No extra input before or after action_type(button number)!"]
|
248 |
|
249 |
# Extract parsed components
|
250 |
action_type = match.group("action_type").lower()
|
|
|
254 |
# Validate button number and action type
|
255 |
if button_name not in valid_buttons:
|
256 |
return [False,
|
257 |
+
"Invalid Button number! Recall: Each button is in the format: `number. button name: action_type`. Correct example: link(3), text_box(2, query)"] # Button number must match exactly (case insensitive)
|
258 |
if action_type != valid_buttons[button_name]:
|
259 |
return [False,
|
260 |
"Invalid action type! Recall: Each button is in the format: `number. button name: action_type`"] # Action type must match the button's specified type
|
261 |
+
if action_type == "text_box" and query is None:
|
262 |
return [False,
|
263 |
+
"Missing Query for action type 'text_box'! Recall: use the format: `text_box(button number, query)`"] # `text_box` action requires a query
|
264 |
+
if action_type != "text_box" and query is not None:
|
265 |
return [False,
|
266 |
+
"Non-`text_box` action_type cannot take query!"] # Non-`type` actions must not have a query
|
267 |
return [True, 'Pass']
|