Spaces:
Sleeping
Sleeping
Download utils.py from Arbazkhan-cs/Mindo-APIs: direct link, hf CLI and curl.
- Browser
- Download file 860 Bytes
-
https://huggingface.co/spaces/Arbazkhan-cs/Mindo-APIs/resolve/main/utils.py
- Command line
-
hf download hf://spaces/Arbazkhan-cs/Mindo-APIs/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Arbazkhan-cs/Mindo-APIs/resolve/main/utils.py
860 Bytes
| # --- File: utils.py --- | |
| import json | |
| import re | |
| import logging | |
| from schemas import SubjectResponse, QuizResponse | |
| logger = logging.getLogger(__name__) | |
| def clean_response(response: str) -> dict: | |
| try: | |
| parsed_response = json.loads(response) | |
| validated = SubjectResponse(**parsed_response) | |
| return validated.dict() | |
| except Exception as e: | |
| logger.error(f"Failed to clean or validate LLM response: {str(e)}") | |
| raise ValueError(f"Invalid JSON output: {str(e)}") | |
| def clean_quiz_response(response: str) -> dict: | |
| try: | |
| parsed_response = json.loads(response) | |
| validated = QuizResponse(**parsed_response) | |
| return validated.dict() | |
| except Exception as e: | |
| logger.error(f"Failed to clean or validate quiz response: {str(e)}") | |
| raise ValueError(f"Invalid Quiz JSON output: {str(e)}") | |