Tachi67 commited on
Commit
54f092c
·
1 Parent(s): d102094

Update ControllerFlow_ExtLib.py

Browse files
Files changed (1) hide show
  1. ControllerFlow_ExtLib.py +13 -10
ControllerFlow_ExtLib.py CHANGED
@@ -110,13 +110,16 @@ class ControllerFlow_ExtLib(ChatAtomicFlow):
110
  self._state_update_add_chat_message(content=updated_system_message_content,
111
  role=self.flow_config["system_name"])
112
 
113
- api_output = super().run(input_data)["api_output"].strip()
114
- try:
115
- response = json.loads(api_output)
116
- return response
117
- except json.decoder.JSONDecodeError:
118
- new_goal = f"Here is your previous response {api_output}, it cannot be parsed with json.loads, please fix this issue. Provide your response only in JSON format."
119
- new_input_data = input_data.copy()
120
- new_input_data['result'] = new_goal
121
- new_api_output = super().run(new_input_data)["api_output"].strip()
122
- return json.loads(new_api_output)
 
 
 
 
110
  self._state_update_add_chat_message(content=updated_system_message_content,
111
  role=self.flow_config["system_name"])
112
 
113
+ while True:
114
+ api_output = super().run(input_data)["api_output"].strip()
115
+ try:
116
+ response = json.loads(api_output)
117
+ return response
118
+ except (json.decoder.JSONDecodeError, json.JSONDecodeError):
119
+ updated_system_message_content = self._get_message(self.system_message_prompt_template, input_data)
120
+ self._state_update_add_chat_message(content=updated_system_message_content,
121
+ role=self.flow_config["system_name"])
122
+ new_goal = "The previous respond cannot be parsed with json.loads. Next time, do not provide any comments or code blocks. Make sure your next response is purely json parsable."
123
+ new_input_data = input_data.copy()
124
+ new_input_data['result'] = new_goal
125
+ input_data = new_input_data