Skip to content

Commit

Permalink
chore: added synthetic generation error handling (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebender37 authored Mar 3, 2025
1 parent a1004dc commit fc6ddab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
14 changes: 13 additions & 1 deletion commons/dataset/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
wait_exponential,
)

from commons.exceptions import SyntheticGenerationError
from dojo.protocol import SyntheticQA

SYNTHETIC_API_BASE_URL = os.getenv("SYNTHETIC_API_URL")
Expand Down Expand Up @@ -77,8 +78,18 @@ async def get_qa(cls) -> SyntheticQA | None:
async with cls._session.get(path) as response:
response.raise_for_status()
response_json = await response.json()
if response_json["success"] is False:
raise SyntheticGenerationError(
message=response_json.get(
"error", "No error details provided"
),
)
if "body" not in response_json:
raise ValueError("Invalid response from the server.")
raise SyntheticGenerationError(
"Invalid response from the server. "
"No body found in the response."
)

synthetic_qa = _map_synthetic_response(response_json["body"])
logger.info("Synthetic QA generated and parsed successfully")
return synthetic_qa
Expand All @@ -88,5 +99,6 @@ async def get_qa(cls) -> SyntheticQA | None:
)
traceback.print_exc()
raise

except Exception:
raise
8 changes: 8 additions & 0 deletions commons/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,11 @@ class SetWeightsFailed(Exception):
def __init__(self, message):
self.message = message
super().__init__(self.message)


class SyntheticGenerationError(Exception):
"""Raised when synthetic QA generation fails"""

def __init__(self, message: str):
self.message = message
super().__init__(self.message)
8 changes: 7 additions & 1 deletion neurons/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
InvalidMinerResponse,
NoNewExpiredTasksYet,
SetWeightsFailed,
SyntheticGenerationError,
)
from commons.obfuscation.obfuscation_utils import obfuscate_html_and_js
from commons.objects import ObjectManager
Expand Down Expand Up @@ -868,7 +869,12 @@ async def _generate_synthetic_request(

return synapse, data.ground_truth, obfuscated_model_to_model

except (RetryError, ValueError, aiohttp.ClientError) as e:
except (
RetryError,
ValueError,
aiohttp.ClientError,
SyntheticGenerationError,
) as e:
logger.error(
f"Failed to generate synthetic request: {type(e).__name__}: {str(e)}"
)
Expand Down

0 comments on commit fc6ddab

Please sign in to comment.