Improve clarification feedback
Browse files- app/gradio_app.py +25 -2
app/gradio_app.py
CHANGED
|
@@ -29,10 +29,30 @@ def _preview_text(preview: Any) -> str:
|
|
| 29 |
return f"{preview.message}\n\nSteps:\n{steps}\n\nParameters:\n```json\n{params}\n```"
|
| 30 |
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
def route_request(request_text: str):
|
| 33 |
session = RouterCoreSession()
|
| 34 |
router_output, validation_result, policy_decision, preview, state = session.route(request_text)
|
| 35 |
return (
|
|
|
|
| 36 |
_json(router_output),
|
| 37 |
_json(validation_result),
|
| 38 |
_json(policy_decision),
|
|
@@ -47,6 +67,7 @@ def continue_with_clarification(request_text: str, follow_up_answer: str, state:
|
|
| 47 |
follow_up_answer
|
| 48 |
)
|
| 49 |
return (
|
|
|
|
| 50 |
_json(router_output),
|
| 51 |
_json(validation_result),
|
| 52 |
_json(policy_decision),
|
|
@@ -96,6 +117,8 @@ def build_demo() -> gr.Blocks:
|
|
| 96 |
label="Examples",
|
| 97 |
)
|
| 98 |
|
|
|
|
|
|
|
| 99 |
with gr.Row():
|
| 100 |
router_json = gr.JSON(label="Router Output JSON")
|
| 101 |
validation_json = gr.JSON(label="Validation Result JSON")
|
|
@@ -106,12 +129,12 @@ def build_demo() -> gr.Blocks:
|
|
| 106 |
route_button.click(
|
| 107 |
route_request,
|
| 108 |
inputs=[request_box],
|
| 109 |
-
outputs=[router_json, validation_json, policy_json, preview_markdown, state],
|
| 110 |
)
|
| 111 |
continue_button.click(
|
| 112 |
continue_with_clarification,
|
| 113 |
inputs=[request_box, follow_up_box, state],
|
| 114 |
-
outputs=[router_json, validation_json, policy_json, preview_markdown, state],
|
| 115 |
)
|
| 116 |
|
| 117 |
return demo
|
|
|
|
| 29 |
return f"{preview.message}\n\nSteps:\n{steps}\n\nParameters:\n```json\n{params}\n```"
|
| 30 |
|
| 31 |
|
| 32 |
+
def _decision_summary(policy_decision: Any, validation_result: Any, state: SessionState) -> str:
|
| 33 |
+
lines = [
|
| 34 |
+
f"**Decision:** `{policy_decision.status}`",
|
| 35 |
+
f"**Workflow:** `{policy_decision.workflow or 'none'}`",
|
| 36 |
+
f"**Attempt:** `{state.attempt_count}`",
|
| 37 |
+
]
|
| 38 |
+
if validation_result.missing_fields:
|
| 39 |
+
missing = ", ".join(f"`{field}`" for field in validation_result.missing_fields)
|
| 40 |
+
lines.append(f"**Still needed:** {missing}")
|
| 41 |
+
if policy_decision.clarifying_question:
|
| 42 |
+
lines.append(f"**Clarifying question:** {policy_decision.clarifying_question}")
|
| 43 |
+
if policy_decision.reasons:
|
| 44 |
+
lines.append("**Reason:** " + "; ".join(policy_decision.reasons))
|
| 45 |
+
if state.accumulated_context:
|
| 46 |
+
context = " | ".join(state.accumulated_context)
|
| 47 |
+
lines.append(f"**Accumulated context:** {context}")
|
| 48 |
+
return "\n\n".join(lines)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
def route_request(request_text: str):
|
| 52 |
session = RouterCoreSession()
|
| 53 |
router_output, validation_result, policy_decision, preview, state = session.route(request_text)
|
| 54 |
return (
|
| 55 |
+
_decision_summary(policy_decision, validation_result, state),
|
| 56 |
_json(router_output),
|
| 57 |
_json(validation_result),
|
| 58 |
_json(policy_decision),
|
|
|
|
| 67 |
follow_up_answer
|
| 68 |
)
|
| 69 |
return (
|
| 70 |
+
_decision_summary(policy_decision, validation_result, state),
|
| 71 |
_json(router_output),
|
| 72 |
_json(validation_result),
|
| 73 |
_json(policy_decision),
|
|
|
|
| 117 |
label="Examples",
|
| 118 |
)
|
| 119 |
|
| 120 |
+
decision_summary = gr.Markdown(label="Decision Summary")
|
| 121 |
+
|
| 122 |
with gr.Row():
|
| 123 |
router_json = gr.JSON(label="Router Output JSON")
|
| 124 |
validation_json = gr.JSON(label="Validation Result JSON")
|
|
|
|
| 129 |
route_button.click(
|
| 130 |
route_request,
|
| 131 |
inputs=[request_box],
|
| 132 |
+
outputs=[decision_summary, router_json, validation_json, policy_json, preview_markdown, state],
|
| 133 |
)
|
| 134 |
continue_button.click(
|
| 135 |
continue_with_clarification,
|
| 136 |
inputs=[request_box, follow_up_box, state],
|
| 137 |
+
outputs=[decision_summary, router_json, validation_json, policy_json, preview_markdown, state],
|
| 138 |
)
|
| 139 |
|
| 140 |
return demo
|