
    qi                        U d Z ddlmZ i ddddddddddd	dd
dddddddddddddddddddddi ddddddddddd dd!d"d#d"d$d"d%d"d&d"d'd"d(d"d)d"d*d"d+d"d,d"d"d"d"d-d-d-d.d.d.d/d/d0Zeeef   ed1<   d2d3d4d5d6d7d8d9d:d;d<d=d>Zeeef   ed?<   d@edAefdBZdCedAefdDZ	dEedAe
fdFZdEedAefdGZyH)IzR
Intent Detection Module

Keyword-based intent classification for ERP/CRM domain.
    )Optionalerp_inquiryERP	erp_clouderp_demozerp_on premiseerp_featurestraffic_erpcrm_inquiryCRMcrm_features	crm_leadspricingPricingpricing_inquiryschedule_call
Schedulingdate_requestclosingClosinggoodbyefarewell	thank_youintroductionIntroductiongreetinginitialclarificationClarificationclarification_neededneeds_clarificationgeneralGeneralgeneral_requestgeneral_discussiongeneral_concerngeneral_inquiryinfo_requestservice_informationfeature_detailsdata_package_infoimplementation_detailssoftware_name
Escalation	TechnicalUnknown)solution_powerimplementationdemo_requestcontactcontact_agenthuman_agentconnectivity_issueaccount_access_issuesystem_issuenoneunknown
INTENT_MAPz#6366f1z#8b5cf6z#f59e0bz#10b981z#ec4899z#3b82f6z#f97316z#64748bz#ef4444z#06b6d4z#a3a3a3z#475569)r   r   r   r   r   r   r   r"   r-   r.   Otherr/   GROUP_COLORSrawreturnc                     | r| j                         syt        j                  | j                         j                         d      S )z
    Normalize raw LLM intent to display group.

    Args:
        raw: Raw intent string from LLM

    Returns:
        Normalized group name (e.g., "ERP", "CRM", "Unknown")
    r/   r<   )stripr;   getlower)r>   s    ,/home/sas/my/fyp/ringai/ringai/llm/intent.pynormalize_intentrE   a   s2     ciik>>#))+++-w77    textc                 &   | xs dj                         t        fddD              ryt        fddD              ryt        fddD              ry	t        fd
dD              ryt        fddD              ryt        fddD              ryt        fddD              ryt        fddD              ryt        fddD              ryt        fddD              ryt        fdd D              ry!t        fd"d#D              ry$y%)&z
    Guess intent from user utterance using keyword matching.

    This provides a fallback when LLM is unavailable.

    Args:
        text: User utterance text

    Returns:
        Guessed intent string
     c              3   &   K   | ]  }|v  
 y wN .0kts     rD   	<genexpr>zguess_intent.<locals>.<genexpr>   s     
za16
z   )byer   zgood byezsee youz
talk laterzgotta goz
have to goz	that's itr   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
%a16
%rR   )thankc              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
:a16
:rR   )erpzenterprise resourcer   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
<a16
<rR   )crmzcustomer relationshipr
   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>        
Ya16
YrR   )leadopportunitypipeline
conversionprospectr   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
\a16
\rR   )pricer   costzhow muchsubscriptionplanr   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   r[   rR   )r1   deploysetupinstall	integrater1   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
@a16
@rR   )demotrialtestzshow mer2   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
Xa16
XrR   )wifizwi-fiinternetslowspeed
connectionr6   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
Wa16
WrR   )portalloginaccountpasswordzcannot accessr7   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
Pa16
PrR   )serversystemdownerrorznot loadingr8   c              3   &   K   | ]  }|v  
 y wrK   rL   rM   s     rD   rQ   zguess_intent.<locals>.<genexpr>   s     
Aa16
ArR   )zname iscallinghellohir   r:   )rC   any)rG   rP   s    @rD   guess_intentr   p   s     
A 
zy
zz 
%9
%% 
:9
::

<;
<<

YX
YY

\[
\\ 

YX
YY

@?
@@ 
XW
XX#

WV
WW%

PO
PP 
A@
AArF   intentc                 
    | dv S )z
    Check if intent signals end of conversation.

    Args:
        intent: Intent string

    Returns:
        True if intent is terminal (closing, escalation)
    )r   r   r   r   rL   )r   s    rD   is_terminal_intentr      s     DDDrF   c                 R    t        |       }t        j                  |t        d         S )z
    Get color for intent visualization.

    Args:
        intent: Intent string (raw or normalized)

    Returns:
        Hex color code
    r<   )rE   r=   rB   )r   
normalizeds     rD   get_intent_colorr      s&     "&)JJW(=>>rF   N)__doc__typingr   r;   dictstr__annotations__r=   rE   r   boolr   r   rL   rF   rD   <module>r      s   C5C C 	C
 eC EC 5C 5C EC C yC  y!C& \'C( L)C. y/C0 y1C2 	3C4 5C: N;C< =C> ~?CD _ECF OGCH ?ICN yOCP yQCR )SCT yUCV yWCX IYCZ 9[C\ y]C^ _C` iaCb YcCd   ! &' EC
DcN CN  d38n  8# 8# 87s 7s 7t
Es 
Et 
E?S ?S ?rF   