Maharshi Gor commited on
Commit
ea7575f
·
1 Parent(s): b5b12d3

Error handling for Anthropic models

Browse files
shared/workflows CHANGED
@@ -1 +1 @@
1
- Subproject commit 3b211faf9bd3aa769a00f9ac40f6f377e77517c8
 
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 evaluate_prediction
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
- import traceback
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(f"Error evaluating bonus: {e.args}")
308
- logger.exception(f"Error evaluating bonus: {e.args}")
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 evaluate_prediction
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
- import traceback
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
- import traceback
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=styled_error(f"Error: {str(e)}")),
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
- def evaluate_prediction(prediction: str, clean_answers: list[str] | str) -> int:
7
- """Evaluate the buzz of a prediction against the clean answers."""
8
- if isinstance(clean_answers, str):
9
- print("clean_answers is a string")
10
- clean_answers = [clean_answers]
11
- pred = prediction.lower().strip()
12
- if not pred:
13
- return 0
14
- for answer in clean_answers:
15
- answer = answer.strip().lower()
16
- if answer and answer in pred:
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: