
    dh5                        S SK Jr  S SKJrJrJr  S SKrS SKJr  S SK	J
r
   " S S\
5      r " S S	\
5      r " S
 S\
5      r " S S\
5      rg)    )annotations)AnyDictOptionalN)CallbackManagerForToolRun)BaseToolc                      \ rS rSr% SrSrS\S'   SrS\S'   S\S'   S\S	'   S\S
'   SrS\S'    S     SS jjr	SS jr
Srg)CogniswitchKnowledgeRequest
   a  Tool that uses the Cogniswitch service to answer questions.

name: str = "cogniswitch_knowledge_request"
description: str = (
    "A wrapper around cogniswitch service to answer the question
    from the knowledge base."
    "Input should be a search query."
)
cogniswitch_knowledge_requeststrnamezYA wrapper around cogniswitch service to 
    answer the question from the knowledge base.descriptioncs_token	OAI_tokenapiKeyz@https://api.cogniswitch.ai:8243/cs-api/0.0.1/cs/knowledgeRequestapi_urlNc                h    U R                  U R                  U R                  XR                  5      nU$ )aH  
Use the tool to answer a query.

Args:
    query (str): Natural language query,
      that you would like to ask to your knowledge graph.
    run_manager (Optional[CallbackManagerForChainRun]):
    Manager for chain run callbacks.

Returns:
    Dict[str, Any]: Output dictionary containing
    the 'response' from the service.
)	answer_csr   r   r   )selfqueryrun_managerresponses       b/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/tools/cogniswitch/tool.py_run CogniswitchKnowledgeRequest._run   s'    $ >>$--T    c                   U(       d  [        S5      eU(       d  [        S5      eU(       d  [        S5      eU(       d  [        S5      eUUUS.nSU0n[        R                  " U R                  XVS9nUR	                  5       $ )a  
Send a query to the Cogniswitch service and retrieve the response.

Args:
    cs_token (str): Cogniswitch token.
    OAI_token (str): OpenAI token.
    apiKey (str): OAuth token.
    query (str): Query to be answered.

Returns:
    dict: Response JSON from the Cogniswitch service.
zMissing cs_tokenzMissing OpenAI tokenzMissing cogniswitch OAuth tokenzMissing input query)r   platformTokenopenAITokenr   headersdata)
ValueErrorrequestspostr   json)r   r   r   r   r   r"   r#   r   s           r   r   %CogniswitchKnowledgeRequest.answer_cs2   s~     /00344>??233 %$
 ==wJ}}r    N)r   r   r   #Optional[CallbackManagerForToolRun]returnDict[str, Any])
r   r   r   r   r   r   r   r   r,   dict)__name__
__module____qualname____firstlineno____doc__r   __annotations__r   r   r   r   __static_attributes__r)   r   r   r
   r
   
   sf     0D#/4K 4MNKUGSU
 <@ 9 
	*r   r
   c                      \ rS rSr% SrSrS\S'   SrS\S'   S\S'   S\S	'   S\S
'   SrS\S'    S     SS jjr	SS jr
Srg)CogniswitchKnowledgeStatusS   aE  Tool that uses the Cogniswitch services to get the
 status of the document or url uploaded.

name: str = "cogniswitch_knowledge_status"
description: str = (
    "A wrapper around cogniswitch services to know the status of
     the document uploaded from a url or a file. "
    "Input should be a file name or the url link"
)
cogniswitch_knowledge_statusr   r   zlA wrapper around cogniswitch services to know 
    the status of the document uploaded from a url or a file.r   r   r   r   zFhttps://api.cogniswitch.ai:8243/cs-api/0.0.1/cs/knowledgeSource/statusknowledge_status_urlNc                (    U R                  U5      nU$ )aE  
Use the tool to know the status of the document uploaded.

Args:
    document_name (str): name of the document or
    the url uploaded
    run_manager (Optional[CallbackManagerForChainRun]):
    Manager for chain run callbacks.

Returns:
    Dict[str, Any]: Output dictionary containing
    the 'response' from the service.
)knowledge_status)r   document_namer   r   s       r   r   CogniswitchKnowledgeStatus._runi   s    $ ((7r   c                F   XR                   S.nU R                  U R                  U R                   S.n[        R                  " U R
                  UUS9nUR                  S:X  Ga1  UR                  5       n[        US   5      nUR	                  S5      nUS:X  a  SUS'   O;US	:X  a  S
US'   O/US:X  a  SUS'   O#US:X  a  SUS'   OUS:X  a  SUS'   OUS:X  a  SUS'   SUR                  5       ;   a  UR                  S5        SUR                  5       ;   a  UR                  S5        SUR                  5       ;   a  UR                  S5        SUR                  5       ;   a  UR                  S5        SUR                  5       ;   a  UR                  S5        U$ SUR                  0$ )z
Use this function to know the status of the document or the URL uploaded
Args:
    document_name (str): The document name or the url that is uploaded.

Returns:
    dict: Response JSON from the Cogniswitch service.
)docNamer   r   r    r   )r"   params   statusr   SUCCESS   
PROCESSING   UPLOADED   FAILURE   UPLOAD_FAILURE   REJECTEDfilePathsavedFileNameintegrationConfigIdmetaData
docEntryIdmessage)r   r   r   r%   getr:   status_coder'   r.   keyspop)r   r=   rB   r"   r   source_infosource_datarE   s           r   r<   +CogniswitchKnowledgeStatus.knowledge_status~   s    +]]Kkk>>!]]

 <<%%

 3&"--/K{2/K __X.F{(1H%1(4H%1(2H%1(1H%1(8H%1(2H%[--//
++"2"2"440$(8(8(:: 56[--//
+{//11- 8// r   r)   r*   )r=   r   r   r+   r,   r-   )r=   r   r,   r.   )r/   r0   r1   r2   r3   r   r4   r   r:   r   r<   r5   r)   r   r   r7   r7   S   sm    	 /D#.AK AMNKP #  <@ 9 
	*4r   r7   c                      \ rS rSr% SrSrS\S'   SrS\S'   S\S'   S\S	'   S\S
'   SrS\S'       S         SS jjr	        SS jr
Srg)CogniswitchKnowledgeSourceFile   ai  Tool that uses the Cogniswitch services to store data from file.

name: str = "cogniswitch_knowledge_source_file"
description: str = (
    "This calls the CogniSwitch services to analyze & store data from a file.
    If the input looks like a file path, assign that string value to file key.
    Assign document name & description only if provided in input."
)
!cogniswitch_knowledge_source_filer   r   z
        This calls the CogniSwitch services to analyze & store data from a file. 
        If the input looks like a file path, assign that string value to file key. 
        Assign document name & description only if provided in input.
        r   r   r   r   zDhttps://api.cogniswitch.ai:8243/cs-api/0.0.1/cs/knowledgeSource/fileknowledgesource_fileNc                >    U(       d  SS0$ U R                  UUUS9nU$ )a  
Execute the tool to store the data given from a file.
This calls the CogniSwitch services to analyze & store data from a file.
If the input looks like a file path, assign that string value to file key.
Assign document name & description only if provided in input.

Args:
    file Optional[str]: The file path of your knowledge
    document_name Optional[str]: Name of your knowledge document
    document_description Optional[str]: Description of your knowledge document
    run_manager (Optional[CallbackManagerForChainRun]):
    Manager for chain run callbacks.

Returns:
    Dict[str, Any]: Output dictionary containing
    the 'response' from the service.
rV   No input provided)filer=   document_description
store_data)r   re   r=   rf   r   r   s         r   r   #CogniswitchKnowledgeSourceFile._run   s<    0 .  +%9 ' H
 Or   c                $   U R                   U R                  U R                  S.nU(       d  SnU(       d  SnUb  S[        US5      0nUUS.n[        R
                  " U R                  UUWS9nUR                  S:X  a  UR                  5       $ SS	0$ )
a\  
Store data using the Cogniswitch service.
This calls the CogniSwitch services to analyze & store data from a file.
If the input looks like a file path, assign that string value to file key.
Assign document name & description only if provided in input.

Args:
    file (Optional[str]): file path of your file.
    the current files supported by the files are
    .txt, .pdf, .docx, .doc, .html
    document_name (Optional[str]): Name of the document you are uploading.
    document_description (Optional[str]): Description of the document.

Returns:
    dict: Response JSON from the Cogniswitch service.
rA    re   rb)documentNamedocumentDescription)r"   r#   filesrC   rV   Bad Request)	r   r   r   openr%   r&   rb   rX   r'   )r   re   r=   rf   r"   ro   r#   r   s           r   rh   )CogniswitchKnowledgeSourceFile.store_data   s    . kk>>!]]
 M##% T$-.E *#7
 ==%%	
 3&==?"}--r   r)   NNNN)
re   Optional[str]r=   rt   rf   rt   r   r+   r,   r-   )re   rt   r=   rt   rf   rt   r,   r.   )r/   r0   r1   r2   r3   r   r4   r   rb   r   rh   r5   r)   r   r   r_   r_      s     4D#3K 
 MNKN #  #'+.2;?"" %" ,	"
 9" 
"H1.1. %1. ,	1.
 
1.r   r_   c                      \ rS rSr% SrSrS\S'   SrS\S'   S\S'   S\S	'   S\S
'   SrS\S'       S         SS jjr	        SS jr
Srg)CogniswitchKnowledgeSourceURLi%  a\  Tool that uses the Cogniswitch services to store data from a URL.

name: str = "cogniswitch_knowledge_source_url"
description: str = (
    "This calls the CogniSwitch services to analyze & store data from a url.
    the URL is provided in input, assign that value to the url key.
    Assign document name & description only if provided in input"
)
 cogniswitch_knowledge_source_urlr   r   z
    This calls the CogniSwitch services to analyze & store data from a url. 
        the URL is provided in input, assign that value to the url key. 
        Assign document name & description only if provided in inputr   r   r   r   zChttps://api.cogniswitch.ai:8243/cs-api/0.0.1/cs/knowledgeSource/urlknowledgesource_urlNc                >    U(       d  SS0$ U R                  UUUS9nU$ )a  
Execute the tool to store the data given from a url.
This calls the CogniSwitch services to analyze & store data from a url.
the URL is provided in input, assign that value to the url key.
Assign document name & description only if provided in input.

Args:
    url Optional[str]: The website/url link of your knowledge
    document_name Optional[str]: Name of your knowledge document
    document_description Optional[str]: Description of your knowledge document
    run_manager (Optional[CallbackManagerForChainRun]):
    Manager for chain run callbacks.

Returns:
    Dict[str, Any]: Output dictionary containing
    the 'response' from the service.
rV   rd   )urlr=   rf   rg   )r   rz   r=   rf   r   r   s         r   r   "CogniswitchKnowledgeSourceURL._run<  s<    0 .  ??'!5 # 

 r   c                   U R                   U R                  U R                  S.nU(       d  SnU(       d  SnU(       d  SS0$ SU0n[        R                  " U R
                  UUS9nUR                  S:X  a  UR                  5       $ SS0$ )	a  
Store data using the Cogniswitch service.
This calls the CogniSwitch services to analyze & store data from a url.
the URL is provided in input, assign that value to the url key.
Assign document name & description only if provided in input.

Args:
    url (Optional[str]): URL link.
    document_name (Optional[str]): Name of the document you are uploading.
    document_description (Optional[str]): Description of the document.

Returns:
    dict: Response JSON from the Cogniswitch service.
rA   rk   rV   rd   rz   r!   rC   rp   )r   r   r   r%   r&   rx   rX   r'   )r   rz   r=   rf   r"   r#   r   s          r   rh   (CogniswitchKnowledgeSourceURL.store_data_  s    * kk>>!]]
 M##% .  3<D}}((H
 3&==?"}--r   r)   rs   )
rz   rt   r=   rt   rf   rt   r   r+   r,   r-   )rz   rt   r=   rt   rf   rt   r,   r.   )r/   r0   r1   r2   r3   r   r4   r   rx   r   rh   r5   r)   r   r   rv   rv   %  s     3D#2HK H MNKM   "'+.2;?!! %! ,	!
 9! 
!F,.,. %,. ,	,.
 
,.r   rv   )
__future__r   typingr   r   r   r%   langchain_core.callbacksr   langchain_core.toolsr   r
   r7   r_   rv   r)   r   r   <module>r      sR    " & &  > )F( FR_ _Dm.X m.`f.H f.r   