Commit
·
762aa3c
1
Parent(s):
14c3e34
feat: enhanced error management in the workflow and returned messages
Browse files
climateqa/engine/talk_to_data/main.py
CHANGED
|
@@ -50,7 +50,7 @@ async def ask_drias(query: str, index_state: int = 0, user_id: str | None = None
|
|
| 50 |
|
| 51 |
if "error" in final_state and final_state["error"] != "":
|
| 52 |
# No Sql query, no dataframe, no figure, no plot information, empty sql queries list, empty result dataframes list, empty figures list, empty plot information list, index state = 0, empty table list, error message
|
| 53 |
-
return None, None, None, None, [], [], [], 0, [], final_state["error"]
|
| 54 |
|
| 55 |
sql_query = sql_queries[index_state]
|
| 56 |
dataframe = result_dataframes[index_state]
|
|
@@ -112,7 +112,7 @@ async def ask_ipcc(query: str, index_state: int = 0, user_id: str | None = None)
|
|
| 112 |
|
| 113 |
if "error" in final_state and final_state["error"] != "":
|
| 114 |
# No Sql query, no dataframe, no figure, no plot information, empty sql queries list, empty result dataframes list, empty figures list, empty plot information list, index state = 0, empty table list, error message
|
| 115 |
-
return None, None, None, None, [], [], [], 0, [], final_state["error"]
|
| 116 |
|
| 117 |
sql_query = sql_queries[index_state]
|
| 118 |
dataframe = result_dataframes[index_state]
|
|
|
|
| 50 |
|
| 51 |
if "error" in final_state and final_state["error"] != "":
|
| 52 |
# No Sql query, no dataframe, no figure, no plot information, empty sql queries list, empty result dataframes list, empty figures list, empty plot information list, index state = 0, empty table list, error message
|
| 53 |
+
return None, None, None, None, [], [], [], [], 0, [], final_state["error"]
|
| 54 |
|
| 55 |
sql_query = sql_queries[index_state]
|
| 56 |
dataframe = result_dataframes[index_state]
|
|
|
|
| 112 |
|
| 113 |
if "error" in final_state and final_state["error"] != "":
|
| 114 |
# No Sql query, no dataframe, no figure, no plot information, empty sql queries list, empty result dataframes list, empty figures list, empty plot information list, index state = 0, empty table list, error message
|
| 115 |
+
return None, None, None, None, [], [], [], [], 0, [], final_state["error"]
|
| 116 |
|
| 117 |
sql_query = sql_queries[index_state]
|
| 118 |
dataframe = result_dataframes[index_state]
|
climateqa/engine/talk_to_data/workflow/ipcc.py
CHANGED
|
@@ -152,10 +152,18 @@ async def ipcc_workflow(user_input: str) -> State:
|
|
| 152 |
|
| 153 |
# Set error messages if needed
|
| 154 |
if not errors['have_relevant_table']:
|
| 155 |
-
state['error'] =
|
|
|
|
|
|
|
|
|
|
| 156 |
elif not errors['have_sql_query']:
|
| 157 |
-
state['error'] =
|
|
|
|
|
|
|
|
|
|
| 158 |
elif not errors['have_dataframe']:
|
| 159 |
-
state['error'] =
|
| 160 |
-
|
|
|
|
|
|
|
| 161 |
return state
|
|
|
|
| 152 |
|
| 153 |
# Set error messages if needed
|
| 154 |
if not errors['have_relevant_table']:
|
| 155 |
+
state['error'] = (
|
| 156 |
+
"Sorry, I couldn't find any relevant table in our database to answer your question.\n"
|
| 157 |
+
"Try asking about a different climate indicator like temperature or precipitation."
|
| 158 |
+
)
|
| 159 |
elif not errors['have_sql_query']:
|
| 160 |
+
state['error'] = (
|
| 161 |
+
"Sorry, I couldn't generate a relevant SQL query to answer your question.\n"
|
| 162 |
+
"Try rephrasing your question to focus on a specific location, a year, or a month."
|
| 163 |
+
)
|
| 164 |
elif not errors['have_dataframe']:
|
| 165 |
+
state['error'] = (
|
| 166 |
+
"Sorry, there is no data in our tables that can answer your question.\n"
|
| 167 |
+
"Try asking about a more common location, or a different year."
|
| 168 |
+
)
|
| 169 |
return state
|
front/tabs/tab_ipcc.py
CHANGED
|
@@ -68,6 +68,8 @@ def show_filter_by_scenario(table_names, index_state, dataframes):
|
|
| 68 |
return gr.update(visible=False)
|
| 69 |
|
| 70 |
def filter_by_scenario(dataframes, figures, table_names, index_state, scenario):
|
|
|
|
|
|
|
| 71 |
df = dataframes[index_state]
|
| 72 |
if not table_names[index_state].startswith("Map"):
|
| 73 |
return df, figures[index_state](df)
|
|
|
|
| 68 |
return gr.update(visible=False)
|
| 69 |
|
| 70 |
def filter_by_scenario(dataframes, figures, table_names, index_state, scenario):
|
| 71 |
+
if len(dataframes) == 0:
|
| 72 |
+
return None, None
|
| 73 |
df = dataframes[index_state]
|
| 74 |
if not table_names[index_state].startswith("Map"):
|
| 75 |
return df, figures[index_state](df)
|