File size: 977 Bytes
77b0c9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import Dict, Any
import logging

def validate_input(data: Dict[str, Any]) -> str:
    """
    Validate the input data for sentiment analysis.
    
    Args:
        data: Dictionary containing the input data
        
    Returns:
        Validated text string
        
    Raises:
        ValueError: If validation fails
    """
    if not isinstance(data, dict):
        raise ValueError("Input must be a JSON object")
        
    if 'text' not in data:
        raise ValueError("Missing 'text' field in input")
        
    text = data.get('text')
    
    if not isinstance(text, str):
        raise ValueError("Text must be a string")
        
    if not text.strip():
        raise ValueError("Text cannot be empty")
        
    return text.strip()

def setup_logging() -> None:
    """Configure logging for the application."""
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    )