IDAgents Developer commited on
Commit
a9ea169
·
1 Parent(s): 4e96d6f

Fix builder panel chatbot format conversion for Gradio 4.20.0

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1069,7 +1069,8 @@ def build_ui():
1069
  prompt = f"Please provide the following required information for empiric therapy: {', '.join(missing)}."
1070
  # Show this as an assistant message and do not call the tool
1071
  history.append({"role": "assistant", "content": prompt})
1072
- return history, histories, ""
 
1073
  # All required fields present, prepend tool input
1074
  user_text = f"[EMPIRIC_THERAPY_INPUT] {json.dumps(user_vars)}\n" + user_text
1075
  # Use the same chat handling logic, but ensure the builder_chatbot is updated and history is preserved
@@ -1100,12 +1101,14 @@ def build_ui():
1100
  else:
1101
  final_history, updated_histories, cleared_input, invocation_log = chatpanel_handle(agent_name, user_text, histories)
1102
  challenger_info = None
1103
- return final_history, updated_histories, cleared_input, invocation_log, ""
 
1104
  except Exception:
1105
  # fallback to old behavior if error
1106
  final_history, updated_histories, cleared_input, invocation_log = chatpanel_handle(agent_name, user_text, histories)
1107
  challenger_info = None
1108
- return final_history, updated_histories, cleared_input, invocation_log, ""
 
1109
  # Update histories
1110
  updated_histories = histories.copy()
1111
  updated_histories[agent_name] = final_history
@@ -1127,7 +1130,10 @@ def build_ui():
1127
  challenger_md = f"**Original Agent Answer:**\n\n{orig}\n\n**Challenger Critique:**\n\n{crit}\n\n**Final Answer Shown to User:**\n\n{final}"
1128
  else:
1129
  challenger_md = f"**Original Agent Answer:**\n\n{orig}\n\n**Final Answer Shown to User:**\n\n{final}"
1130
- return final_history, updated_histories, "", invocation_log, challenger_md
 
 
 
1131
 
1132
  # Add a Markdown for challenger debug info under the invocation log, only in the builder panel
1133
  challenger_debug_md = gr.Markdown("", visible=True)
 
1069
  prompt = f"Please provide the following required information for empiric therapy: {', '.join(missing)}."
1070
  # Show this as an assistant message and do not call the tool
1071
  history.append({"role": "assistant", "content": prompt})
1072
+ gradio_history = convert_messages_for_gradio(history)
1073
+ return gradio_history, histories, "", "", ""
1074
  # All required fields present, prepend tool input
1075
  user_text = f"[EMPIRIC_THERAPY_INPUT] {json.dumps(user_vars)}\n" + user_text
1076
  # Use the same chat handling logic, but ensure the builder_chatbot is updated and history is preserved
 
1101
  else:
1102
  final_history, updated_histories, cleared_input, invocation_log = chatpanel_handle(agent_name, user_text, histories)
1103
  challenger_info = None
1104
+ gradio_history = convert_messages_for_gradio(final_history)
1105
+ return gradio_history, updated_histories, cleared_input, invocation_log, ""
1106
  except Exception:
1107
  # fallback to old behavior if error
1108
  final_history, updated_histories, cleared_input, invocation_log = chatpanel_handle(agent_name, user_text, histories)
1109
  challenger_info = None
1110
+ gradio_history = convert_messages_for_gradio(final_history)
1111
+ return gradio_history, updated_histories, cleared_input, invocation_log, ""
1112
  # Update histories
1113
  updated_histories = histories.copy()
1114
  updated_histories[agent_name] = final_history
 
1130
  challenger_md = f"**Original Agent Answer:**\n\n{orig}\n\n**Challenger Critique:**\n\n{crit}\n\n**Final Answer Shown to User:**\n\n{final}"
1131
  else:
1132
  challenger_md = f"**Original Agent Answer:**\n\n{orig}\n\n**Final Answer Shown to User:**\n\n{final}"
1133
+
1134
+ # Convert final_history to Gradio format before returning
1135
+ gradio_history = convert_messages_for_gradio(final_history)
1136
+ return gradio_history, updated_histories, "", invocation_log, challenger_md
1137
 
1138
  # Add a Markdown for challenger debug info under the invocation log, only in the builder panel
1139
  challenger_debug_md = gr.Markdown("", visible=True)