-
Notifications
You must be signed in to change notification settings - Fork 35
fix: Add retry configuration and warning for GEval score=None bug #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,9 @@ | |
|
|
||
| import litellm | ||
| from deepeval.models import LiteLLMModel | ||
| from tenacity import stop_after_attempt | ||
|
|
||
| from lightspeed_evaluation.core.constants import DEFAULT_LLM_RETRIES | ||
| from lightspeed_evaluation.core.llm.litellm_patch import setup_litellm_ssl | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
@@ -46,15 +48,46 @@ def __init__(self, model_name: str, llm_params: dict[str, Any]): | |
| # LiteLLMModel stores **kwargs in self.kwargs and merges them into | ||
| # every litellm.completion() call | ||
| # Note: Forbidden keys are rejected at LLMParametersConfig load time | ||
|
|
||
| # Override DeepEval's hardcoded retry logic with user configuration | ||
| # DeepEval uses @retry decorators that capture MAX_RETRIES at import time | ||
| # We must patch the retry decorators after import but before instantiation | ||
| num_retries = self.llm_params.get("num_retries", DEFAULT_LLM_RETRIES) | ||
|
|
||
| self._patch_deepeval_retries(num_retries) | ||
|
|
||
| self.llm_model = LiteLLMModel( | ||
| model=self.model_name, | ||
| timeout=self.llm_params.get("timeout"), | ||
| num_retries=self.llm_params.get("num_retries"), | ||
| **self.llm_params.get("parameters", {}), | ||
| ) | ||
|
|
||
| print(f"✅ DeepEval LLM Manager: {self.model_name}") | ||
|
|
||
| def _patch_deepeval_retries(self, max_retries: int) -> None: | ||
| """Monkey-patch DeepEval's retry decorators to use configured max_retries. | ||
|
|
||
| DeepEval's @retry decorators capture MAX_RETRIES at import time. | ||
| We patch the 'stop' attribute on each retry decorator to use our value. | ||
| """ | ||
| # Patch the stop condition on all retry-decorated methods | ||
| for method_name in [ | ||
| "generate", | ||
| "a_generate", | ||
| "generate_raw_response", | ||
| "a_generate_raw_response", | ||
| "generate_samples", | ||
| ]: | ||
| method = getattr(LiteLLMModel, method_name) | ||
| method.retry.stop = stop_after_attempt( # pylint: disable=no-member | ||
|
Comment on lines
+81
to
+82
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't like this but I can't figure out a better solution :-(
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| max_retries | ||
|
xmican10 marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| logger.info( | ||
| "Patched DeepEval retry logic: max_retries=%d", | ||
| max_retries, | ||
| ) | ||
|
|
||
| def setup_ssl_verify(self) -> None: | ||
| """Setup SSL verification based on LLM parameters. | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.