Spaces:
Sleeping
Sleeping
| from app.config import get_settings | |
| from app.schemas.requests import ExtractionRequest, FollowSchemaRequest | |
| from app.schemas.schema_tools import validate_json_schema | |
| from app.utils.logger import setup_logger | |
| logger = setup_logger(__name__) | |
| settings = get_settings() | |
| def validate_extract_request(request: ExtractionRequest): | |
| """Validate the request to extract attributes.""" | |
| request.max_attempts = max(request.max_attempts, 1) | |
| request.max_attempts = min(request.max_attempts, 5) | |
| # Limit the number of images to 10 | |
| if len(request.img_urls) > 10: | |
| logger.warning( | |
| f"Number of images exceeds 10: {len(request.img_urls)}. Limiting to 10." | |
| ) | |
| request.img_urls = request.img_urls[:10] | |
| for url in request.img_urls: | |
| if not url.startswith("http"): | |
| raise ValueError(f"Invalid URL: {url}") | |
| # validate_json_schema(request.data_schema) | |
| if request.ai_model.lower() not in settings.SUPPORTED_MODELS: | |
| raise ValueError( | |
| f"Invalid ai_model: {request.ai_model}, only support {settings.SUPPORTED_MODELS}" | |
| ) | |
| def validate_follow_request(request: FollowSchemaRequest): | |
| """Validate the request to follow a schema.""" | |
| request.max_attempts = max(request.max_attempts, 1) | |
| request.max_attempts = min(request.max_attempts, 5) | |
| validate_json_schema(request.data_schema) | |
| if request.ai_model.lower() not in settings.SUPPORTED_MODELS: | |
| raise ValueError( | |
| f"Invalid ai_model: {request.ai_model}, only support {settings.SUPPORTED_MODELS}" | |
| ) | |