Spaces:
Running
Running
Food Desert commited on
Commit ·
6a6b212
1
Parent(s): 1c6c5f0
Improve user-facing Suggested Prompt error messages
Browse files
app.py
CHANGED
|
@@ -809,12 +809,15 @@ def _build_ui_payload(
|
|
| 809 |
console_text: str,
|
| 810 |
row_defs: List[Dict[str, Any]],
|
| 811 |
selected_tags: List[str],
|
|
|
|
| 812 |
):
|
| 813 |
prompt_text, row_values_state, header_updates, checkbox_updates = _build_row_component_updates(
|
| 814 |
row_defs=row_defs,
|
| 815 |
selected_tags=selected_tags,
|
| 816 |
max_rows=display_max_rows_default,
|
| 817 |
)
|
|
|
|
|
|
|
| 818 |
selected_ui: List[str] = []
|
| 819 |
selected_ui_seen: Set[str] = set()
|
| 820 |
for vals in row_values_state:
|
|
@@ -839,6 +842,26 @@ def _build_ui_payload(
|
|
| 839 |
]
|
| 840 |
|
| 841 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 842 |
def _prepare_run_ui() -> List[Any]:
|
| 843 |
header_updates = [gr.update(value="", visible=False) for _ in range(display_max_rows_default)]
|
| 844 |
checkbox_updates = [
|
|
@@ -1545,6 +1568,7 @@ def rag_pipeline_ui(
|
|
| 1545 |
console_text="\n".join(logs),
|
| 1546 |
row_defs=[],
|
| 1547 |
selected_tags=[],
|
|
|
|
| 1548 |
)
|
| 1549 |
|
| 1550 |
prompt_in = (user_prompt or "").strip()
|
|
@@ -1553,6 +1577,7 @@ def rag_pipeline_ui(
|
|
| 1553 |
console_text="Error: empty prompt",
|
| 1554 |
row_defs=[],
|
| 1555 |
selected_tags=[],
|
|
|
|
| 1556 |
)
|
| 1557 |
|
| 1558 |
log("Input:")
|
|
@@ -1954,12 +1979,13 @@ def rag_pipeline_ui(
|
|
| 1954 |
selected_tags=active_selected_tags,
|
| 1955 |
)
|
| 1956 |
|
| 1957 |
-
except Exception as e:
|
| 1958 |
-
log(f"Error: {type(e).__name__}: {e}")
|
| 1959 |
return _build_ui_payload(
|
| 1960 |
console_text="\n".join(logs),
|
| 1961 |
row_defs=[],
|
| 1962 |
selected_tags=[],
|
|
|
|
| 1963 |
)
|
| 1964 |
|
| 1965 |
|
|
|
|
| 809 |
console_text: str,
|
| 810 |
row_defs: List[Dict[str, Any]],
|
| 811 |
selected_tags: List[str],
|
| 812 |
+
suggested_prompt_text: str | None = None,
|
| 813 |
):
|
| 814 |
prompt_text, row_values_state, header_updates, checkbox_updates = _build_row_component_updates(
|
| 815 |
row_defs=row_defs,
|
| 816 |
selected_tags=selected_tags,
|
| 817 |
max_rows=display_max_rows_default,
|
| 818 |
)
|
| 819 |
+
if suggested_prompt_text is not None:
|
| 820 |
+
prompt_text = str(suggested_prompt_text)
|
| 821 |
selected_ui: List[str] = []
|
| 822 |
selected_ui_seen: Set[str] = set()
|
| 823 |
for vals in row_values_state:
|
|
|
|
| 842 |
]
|
| 843 |
|
| 844 |
|
| 845 |
+
def _format_user_facing_error(exc: Exception) -> str:
|
| 846 |
+
msg = str(exc or "").strip()
|
| 847 |
+
msg_l = msg.lower()
|
| 848 |
+
|
| 849 |
+
if "rewrite: empty output" in msg_l:
|
| 850 |
+
return (
|
| 851 |
+
"Could not rewrite that prompt. Try simpler, neutral wording and remove sensitive phrasing, "
|
| 852 |
+
"then click Run again."
|
| 853 |
+
)
|
| 854 |
+
if "openrouter_api_key" in msg_l:
|
| 855 |
+
return "Service configuration is missing. Please contact the app owner."
|
| 856 |
+
if "timed out" in msg_l:
|
| 857 |
+
return "The model request timed out. Please try again with a shorter or simpler prompt."
|
| 858 |
+
if "index selection failed" in msg_l:
|
| 859 |
+
return "Tag selection failed for this request. Please try again."
|
| 860 |
+
if "startup preflight failed" in msg_l:
|
| 861 |
+
return "App startup checks failed. Please contact the app owner."
|
| 862 |
+
return "Something went wrong while processing the prompt. Please try again."
|
| 863 |
+
|
| 864 |
+
|
| 865 |
def _prepare_run_ui() -> List[Any]:
|
| 866 |
header_updates = [gr.update(value="", visible=False) for _ in range(display_max_rows_default)]
|
| 867 |
checkbox_updates = [
|
|
|
|
| 1568 |
console_text="\n".join(logs),
|
| 1569 |
row_defs=[],
|
| 1570 |
selected_tags=[],
|
| 1571 |
+
suggested_prompt_text="Error: startup preflight failed. Check console details.",
|
| 1572 |
)
|
| 1573 |
|
| 1574 |
prompt_in = (user_prompt or "").strip()
|
|
|
|
| 1577 |
console_text="Error: empty prompt",
|
| 1578 |
row_defs=[],
|
| 1579 |
selected_tags=[],
|
| 1580 |
+
suggested_prompt_text='Enter a prompt and click "Run".',
|
| 1581 |
)
|
| 1582 |
|
| 1583 |
log("Input:")
|
|
|
|
| 1979 |
selected_tags=active_selected_tags,
|
| 1980 |
)
|
| 1981 |
|
| 1982 |
+
except Exception as e:
|
| 1983 |
+
log(f"Error: {type(e).__name__}: {e}")
|
| 1984 |
return _build_ui_payload(
|
| 1985 |
console_text="\n".join(logs),
|
| 1986 |
row_defs=[],
|
| 1987 |
selected_tags=[],
|
| 1988 |
+
suggested_prompt_text=_format_user_facing_error(e),
|
| 1989 |
)
|
| 1990 |
|
| 1991 |
|