File size: 867 Bytes
f35f208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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