Maharshi Gor
commited on
Commit
·
ea7575f
1
Parent(s):
b5b12d3
Error handling for Anthropic models
Browse files- shared/workflows +1 -1
- src/components/quizbowl/bonus.py +6 -6
- src/components/quizbowl/tossup.py +7 -8
- src/components/quizbowl/utils.py +12 -13
shared/workflows
CHANGED
@@ -1 +1 @@
|
|
1 |
-
Subproject commit
|
|
|
1 |
+
Subproject commit 873b0e6bc80052921fa2061ef9fbcd4e1c4f057e
|
src/components/quizbowl/bonus.py
CHANGED
@@ -13,12 +13,13 @@ from components.model_pipeline.model_pipeline import PipelineInterface, Pipeline
|
|
13 |
from components.typed_dicts import PipelineStateDict
|
14 |
from display.formatting import styled_error
|
15 |
from shared.workflows import factory
|
|
|
16 |
from shared.workflows.qb_agents import QuizBowlBonusAgent
|
17 |
from submission import submit
|
18 |
|
19 |
from . import populate, validation
|
20 |
from .plotting import create_bonus_confidence_plot, create_bonus_html
|
21 |
-
from .utils import
|
22 |
from .validation import UserInputWorkflowValidator
|
23 |
|
24 |
|
@@ -252,9 +253,8 @@ class BonusInterface:
|
|
252 |
gr.update(visible=False),
|
253 |
)
|
254 |
except Exception as e:
|
255 |
-
|
256 |
-
|
257 |
-
error_msg = f"Error: {str(e)}\n{traceback.format_exc()}"
|
258 |
return (
|
259 |
gr.skip(),
|
260 |
gr.skip(),
|
@@ -304,8 +304,8 @@ class BonusInterface:
|
|
304 |
gr.update(visible=False),
|
305 |
)
|
306 |
except Exception as e:
|
307 |
-
error_msg = styled_error(
|
308 |
-
logger.exception(f"Error evaluating
|
309 |
return gr.skip(), gr.skip(), gr.update(visible=True, value=error_msg)
|
310 |
|
311 |
def submit_model(
|
|
|
13 |
from components.typed_dicts import PipelineStateDict
|
14 |
from display.formatting import styled_error
|
15 |
from shared.workflows import factory
|
16 |
+
from shared.workflows.metrics import evaluate_prediction
|
17 |
from shared.workflows.qb_agents import QuizBowlBonusAgent
|
18 |
from submission import submit
|
19 |
|
20 |
from . import populate, validation
|
21 |
from .plotting import create_bonus_confidence_plot, create_bonus_html
|
22 |
+
from .utils import create_error_message
|
23 |
from .validation import UserInputWorkflowValidator
|
24 |
|
25 |
|
|
|
253 |
gr.update(visible=False),
|
254 |
)
|
255 |
except Exception as e:
|
256 |
+
error_msg = styled_error(create_error_message(e))
|
257 |
+
logger.exception(f"Error running tossup: {e}")
|
|
|
258 |
return (
|
259 |
gr.skip(),
|
260 |
gr.skip(),
|
|
|
304 |
gr.update(visible=False),
|
305 |
)
|
306 |
except Exception as e:
|
307 |
+
error_msg = styled_error(create_error_message(e))
|
308 |
+
logger.exception(f"Error evaluating tossups: {e}")
|
309 |
return gr.skip(), gr.skip(), gr.update(visible=True, value=error_msg)
|
310 |
|
311 |
def submit_model(
|
src/components/quizbowl/tossup.py
CHANGED
@@ -13,6 +13,7 @@ from components.model_pipeline.tossup_pipeline import TossupPipelineInterface, T
|
|
13 |
from components.typed_dicts import TossupInterfaceDefaults, TossupPipelineStateDict
|
14 |
from display.formatting import styled_error
|
15 |
from shared.workflows import factory
|
|
|
16 |
from shared.workflows.qb_agents import QuizBowlTossupAgent, TossupResult
|
17 |
from submission import submit
|
18 |
|
@@ -24,7 +25,7 @@ from .plotting import (
|
|
24 |
create_tossup_html,
|
25 |
prepare_tossup_results_df,
|
26 |
)
|
27 |
-
from .utils import
|
28 |
from .validation import UserInputWorkflowValidator
|
29 |
|
30 |
# TODO: Error handling on run tossup and evaluate tossup and show correct messages
|
@@ -313,9 +314,8 @@ class TossupInterface:
|
|
313 |
gr.update(visible=False),
|
314 |
)
|
315 |
except Exception as e:
|
316 |
-
|
317 |
-
|
318 |
-
error_msg = styled_error(f"Error: {str(e)}\n{traceback.format_exc()}")
|
319 |
return (
|
320 |
gr.skip(),
|
321 |
gr.skip(),
|
@@ -346,14 +346,13 @@ class TossupInterface:
|
|
346 |
gr.update(visible=False),
|
347 |
)
|
348 |
except Exception as e:
|
349 |
-
|
350 |
-
|
351 |
-
logger.exception(f"Error evaluating tossups: {e.args}")
|
352 |
return (
|
353 |
gr.skip(),
|
354 |
gr.update(visible=False),
|
355 |
gr.update(visible=False),
|
356 |
-
gr.update(visible=True, value=
|
357 |
)
|
358 |
|
359 |
def submit_model(
|
|
|
13 |
from components.typed_dicts import TossupInterfaceDefaults, TossupPipelineStateDict
|
14 |
from display.formatting import styled_error
|
15 |
from shared.workflows import factory
|
16 |
+
from shared.workflows.metrics import evaluate_prediction
|
17 |
from shared.workflows.qb_agents import QuizBowlTossupAgent, TossupResult
|
18 |
from submission import submit
|
19 |
|
|
|
25 |
create_tossup_html,
|
26 |
prepare_tossup_results_df,
|
27 |
)
|
28 |
+
from .utils import create_error_message
|
29 |
from .validation import UserInputWorkflowValidator
|
30 |
|
31 |
# TODO: Error handling on run tossup and evaluate tossup and show correct messages
|
|
|
314 |
gr.update(visible=False),
|
315 |
)
|
316 |
except Exception as e:
|
317 |
+
error_msg = styled_error(create_error_message(e))
|
318 |
+
logger.exception(f"Error running tossup: {e}")
|
|
|
319 |
return (
|
320 |
gr.skip(),
|
321 |
gr.skip(),
|
|
|
346 |
gr.update(visible=False),
|
347 |
)
|
348 |
except Exception as e:
|
349 |
+
error_msg = styled_error(create_error_message(e))
|
350 |
+
logger.exception(f"Error evaluating tossups: {e}")
|
|
|
351 |
return (
|
352 |
gr.skip(),
|
353 |
gr.update(visible=False),
|
354 |
gr.update(visible=False),
|
355 |
+
gr.update(visible=True, value=error_msg),
|
356 |
)
|
357 |
|
358 |
def submit_model(
|
src/components/quizbowl/utils.py
CHANGED
@@ -2,20 +2,19 @@ from typing import Any, Dict, List
|
|
2 |
|
3 |
import pandas as pd
|
4 |
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
return 1
|
18 |
-
return 0
|
19 |
|
20 |
|
21 |
def _create_confidence_plot_data(results: List[Dict], top_k_mode: bool = False) -> pd.DataFrame:
|
|
|
2 |
|
3 |
import pandas as pd
|
4 |
|
5 |
+
from shared.workflows.errors import ProviderAPIError, WorkflowExecutionError
|
6 |
|
7 |
+
|
8 |
+
def create_error_message(e: Exception) -> str:
|
9 |
+
"""Create an error message for a given exception."""
|
10 |
+
if isinstance(e, ProviderAPIError):
|
11 |
+
return f"Our {e.provider} models are currently experiencing issues. Please try again later. \n\nIf the problem persists, please contact support."
|
12 |
+
elif isinstance(e, WorkflowExecutionError):
|
13 |
+
return f"Workflow execution failed: {e}. Please try again later. \n\nIf the problem persists, please contact support."
|
14 |
+
elif isinstance(e, ValueError):
|
15 |
+
return f"Invalid input -- {e}. Please try again. \n\nIf the problem persists, please contact support."
|
16 |
+
else:
|
17 |
+
return "An unexpected error occurred. Please contact support."
|
|
|
|
|
18 |
|
19 |
|
20 |
def _create_confidence_plot_data(results: List[Dict], top_k_mode: bool = False) -> pd.DataFrame:
|