Tachi67 commited on
Commit
412045a
1 Parent(s): e07bbc0

Update Controller_JarvisFlow.py

Browse files
Files changed (1) hide show
  1. Controller_JarvisFlow.py +13 -10
Controller_JarvisFlow.py CHANGED
@@ -108,13 +108,16 @@ class Controller_JarvisFlow(ChatAtomicFlow):
108
  role=self.flow_config["system_name"])
109
 
110
 
111
- api_output = super().run(input_data)["api_output"].strip()
112
- try:
113
- response = json.loads(api_output)
114
- return response
115
- except json.decoder.JSONDecodeError:
116
- 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."
117
- new_input_data = input_data.copy()
118
- new_input_data['result'] = new_goal
119
- new_api_output = super().run(new_input_data)["api_output"].strip()
120
- return json.loads(new_api_output)
 
 
 
 
108
  role=self.flow_config["system_name"])
109
 
110
 
111
+ while True:
112
+ api_output = super().run(input_data)["api_output"].strip()
113
+ try:
114
+ response = json.loads(api_output)
115
+ return response
116
+ except (json.decoder.JSONDecodeError, json.JSONDecodeError):
117
+ updated_system_message_content = self._get_message(self.system_message_prompt_template, input_data)
118
+ self._state_update_add_chat_message(content=updated_system_message_content,
119
+ role=self.flow_config["system_name"])
120
+ 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."
121
+ new_input_data = input_data.copy()
122
+ new_input_data['result'] = new_goal
123
+ input_data = new_input_data