Tachi67 commited on
Commit
6fb6abc
·
1 Parent(s): b6d6570

Update CodeWriterCtrlFlow.py

Browse files
Files changed (1) hide show
  1. CodeWriterCtrlFlow.py +13 -10
CodeWriterCtrlFlow.py CHANGED
@@ -80,13 +80,16 @@ class CodeWriterCtrlFlow(ChatAtomicFlow):
80
  self._state_update_add_chat_message(content=updated_system_message_content,
81
  role=self.flow_config["system_name"])
82
 
83
- api_output = super().run(input_data)["api_output"].strip()
84
- try:
85
- response = json.loads(api_output)
86
- return response
87
- except json.decoder.JSONDecodeError:
88
- 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."
89
- new_input_data = input_data.copy()
90
- new_input_data['goal'] = new_goal
91
- new_api_output = super().run(new_input_data)["api_output"].strip()
92
- return json.loads(new_api_output)
 
 
 
 
80
  self._state_update_add_chat_message(content=updated_system_message_content,
81
  role=self.flow_config["system_name"])
82
 
83
+ while True:
84
+ api_output = super().run(input_data)["api_output"].strip()
85
+ try:
86
+ response = json.loads(api_output)
87
+ return response
88
+ except (json.decoder.JSONDecodeError, json.JSONDecodeError):
89
+ updated_system_message_content = self._get_message(self.system_message_prompt_template, input_data)
90
+ self._state_update_add_chat_message(content=updated_system_message_content,
91
+ role=self.flow_config["system_name"])
92
+ 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."
93
+ new_input_data = input_data.copy()
94
+ new_input_data['feedback'] = new_goal
95
+ input_data = new_input_data