Spaces:
Sleeping
Sleeping
File size: 1,343 Bytes
79d4fd5 d8bc2e2 79d4fd5 | 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 40 41 42 43 44 | import logging
from typing import Optional, Dict, Any, List
from dataclasses import dataclass, field
from enum import Enum
logger = logging.getLogger(__name__)
class IntentType(Enum):
DOCUMENT_QUERY = "document_query"
DATABASE_QUERY = "database_query"
HYBRID_QUERY = "hybrid_query"
CONVERSATIONAL = "conversational"
AMBIGUOUS = "ambiguous"
CRM_REFERRAL = "crm_referral"
@dataclass
class ClassificationResult:
# Result of intent classification
intent: IntentType
confidence: float
reasoning: str
suggested_tables: List[str] = field(default_factory=list)
requires_clarification: bool = False
classification_time_ms: float = 0.0
def is_database_related(self) -> bool:
return self.intent in (IntentType.DATABASE_QUERY, IntentType.HYBRID_QUERY)
def is_document_related(self) -> bool:
return self.intent in (IntentType.DOCUMENT_QUERY, IntentType.HYBRID_QUERY)
def to_dict(self) -> Dict[str, Any]:
return {
"intent": self.intent.value,
"confidence": self.confidence,
"reasoning": self.reasoning,
"suggested_tables": self.suggested_tables,
"requires_clarification": self.requires_clarification,
"classification_time_ms": round(self.classification_time_ms, 2),
}
|