Muhammed Essam commited on
Commit
75fbdf4
·
1 Parent(s): 8ef276c

add missing file models.py

Browse files
Files changed (1) hide show
  1. models.py +91 -0
models.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # models.py
2
+ from pydantic import BaseModel, Field
3
+ from typing import List, Optional
4
+ from enum import Enum
5
+
6
+
7
+ class ExtractRequest(BaseModel):
8
+ """Request model for department extraction"""
9
+ query: str = Field(..., min_length=1, description="User query text")
10
+
11
+
12
+ class ExtractedInfo(BaseModel):
13
+ """Response model for division extraction using embeddings"""
14
+ division: str = Field(..., description="Division name")
15
+ department: Optional[str] = Field(default=None, description="Parent department name")
16
+ confidence: float = Field(default=0.0, ge=0.0, le=1.0, description="Confidence score (0-1)")
17
+
18
+ class Config:
19
+ populate_by_name = True
20
+
21
+
22
+ class RoutingAction(str, Enum):
23
+ """Actions based on confidence level"""
24
+ DIRECT = "direct" # High confidence - route directly
25
+ SUGGEST = "suggest" # Medium confidence - suggest with alternatives
26
+ CLARIFY = "clarify" # Low confidence - ask for clarification
27
+ ESCALATE = "escalate" # Very low - escalate to operator
28
+
29
+
30
+ class ExtractedInfoList(BaseModel):
31
+ """Enhanced response model with confidence-based routing and name extraction"""
32
+ matches: List[ExtractedInfo] = Field(..., description="List of possible matches ordered by confidence")
33
+ action: RoutingAction = Field(default=RoutingAction.DIRECT, description="Recommended routing action")
34
+ message: str = Field(default="", description="User-facing message based on confidence")
35
+ show_alternatives: bool = Field(default=False, description="Whether to show alternative divisions")
36
+ confidence_level: str = Field(default="high", description="Confidence level: high, medium, low, very_low")
37
+ names: List[str] = Field(default_factory=list, description="Extracted person names from the query")
38
+ has_names: bool = Field(default=False, description="Whether any names were found in the query")
39
+
40
+
41
+ class VoiceQueryInfo(BaseModel):
42
+ """Information about the voice query processing"""
43
+ query: str = Field(..., description="Processed text query (in English)")
44
+ original_text: str = Field(..., description="Original transcribed text")
45
+ language: str = Field(..., description="Detected language code (e.g., 'en', 'ar')")
46
+ language_name: str = Field(..., description="Full language name (e.g., 'English', 'Arabic')")
47
+ was_translated: bool = Field(..., description="Whether the text was translated to English")
48
+ audio_duration: float = Field(..., description="Audio duration in seconds")
49
+
50
+
51
+ class VoiceExtractResponse(BaseModel):
52
+ """Response model for voice query extraction"""
53
+ voice_info: VoiceQueryInfo = Field(..., description="Voice processing information")
54
+ extraction_result: ExtractedInfoList = Field(..., description="Division and name extraction results")
55
+
56
+
57
+ # Contact Search Models
58
+ class ContactInfo(BaseModel):
59
+ """Individual contact information"""
60
+ id: int = Field(..., description="Contact ID")
61
+ first_name_ar: str = Field(..., description="First name in Arabic")
62
+ last_name_ar: str = Field(..., description="Last name in Arabic")
63
+ full_name_ar: str = Field(..., description="Full name in Arabic")
64
+ first_name_en: str = Field(..., description="First name in English")
65
+ last_name_en: str = Field(..., description="Last name in English")
66
+ full_name_en: str = Field(..., description="Full name in English")
67
+ title_en: str = Field(..., description="Job title in English")
68
+ title_ar: str = Field(..., description="Job title in Arabic")
69
+ division: str = Field(..., description="Division name")
70
+ department: str = Field(..., description="Department name")
71
+ department_id: str = Field(..., description="Department ID")
72
+ email: str = Field(..., description="Email address")
73
+ extension: str = Field(..., description="Phone extension")
74
+ phone: str = Field(..., description="Full phone number")
75
+ confidence: float = Field(..., ge=0.0, le=1.0, description="Match confidence score (0-1)")
76
+ match_reason: str = Field(..., description="Reason for match (exact_name_match, fuzzy_name_match, division_match, name_and_division_match)")
77
+
78
+
79
+ class ContactSearchResponse(BaseModel):
80
+ """Response model for contact search"""
81
+ query: str = Field(..., description="Original search query")
82
+ total_matches: int = Field(..., description="Total number of matches found")
83
+ contacts: List[ContactInfo] = Field(..., description="List of matched contacts sorted by confidence")
84
+ extracted_names: List[str] = Field(default_factory=list, description="Names extracted from query")
85
+ matched_divisions: List[str] = Field(default_factory=list, description="Divisions matched from query")
86
+
87
+
88
+ class VoiceContactSearchResponse(BaseModel):
89
+ """Response model for voice-based contact search"""
90
+ voice_info: VoiceQueryInfo = Field(..., description="Voice processing information")
91
+ search_result: ContactSearchResponse = Field(..., description="Contact search results")