Spaces:
Paused
Paused
from typing import Dict, Any | |
from pathlib import Path | |
def validate_model_path(model_path: Path) -> bool: | |
"""Validate that a model path exists and contains necessary files""" | |
if not model_path.exists(): | |
return False | |
required_files = ['config.json', 'pytorch_model.bin'] | |
return all((model_path / file).exists() for file in required_files) | |
def validate_generation_params(params: Dict[str, Any]) -> Dict[str, Any]: | |
"""Validate and normalize generation parameters""" | |
validated = params.copy() | |
# Ensure temperature is within bounds | |
if 'temperature' in validated: | |
validated['temperature'] = max(0.0, min(2.0, validated['temperature'])) | |
# Ensure max_new_tokens is reasonable | |
if 'max_new_tokens' in validated: | |
validated['max_new_tokens'] = max(1, min(4096, validated['max_new_tokens'])) | |
return validated |