Spaces:
Sleeping
Sleeping
force json format in updated user state
Browse files- chatbot_simulator.py +12 -5
chatbot_simulator.py
CHANGED
@@ -136,11 +136,18 @@ Example Output Format:
|
|
136 |
# Parse and update the user state
|
137 |
updated_state = json_repair.loads(updated_state)
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
try:
|
146 |
if updated_state['task_completed'].lower() == 'true':
|
|
|
136 |
# Parse and update the user state
|
137 |
updated_state = json_repair.loads(updated_state)
|
138 |
|
139 |
+
while not isinstance(updated_state, dict):
|
140 |
+
transform_prompt = f""""
|
141 |
+
Transform {updated_state} to a properly formate JSON file.
|
142 |
+
Example Output Format:
|
143 |
+
{{
|
144 |
+
'current_page': 'Home',
|
145 |
+
'last_page': 'Home',
|
146 |
+
'task_completed': 'False',
|
147 |
+
}}
|
148 |
+
"""
|
149 |
+
updated_state = self._get_openai_response({'role': 'system', 'content': transform_prompt})
|
150 |
+
updated_state = json_repair.loads(updated_state)
|
151 |
|
152 |
try:
|
153 |
if updated_state['task_completed'].lower() == 'true':
|