Ë
    µŒjÃ5  ã                  óœ   — d dl mZ d dlmZmZmZ d dlZd dlmZ d dl	m
Z
  G d„ de
«      Z G d„ d	e
«      Z G d
„ de
«      Z G d„ de
«      Zy)é    )Úannotations)ÚAnyÚDictÚOptionalN)ÚCallbackManagerForToolRun)ÚBaseToolc                  óx   — e Zd ZU dZdZded<   dZded<   ded<   ded<   ded	<   d
Zded<   	 d	 	 	 	 	 dd„Zdd„Z	y)ÚCogniswitchKnowledgeRequesta!  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                ój   — | j                  | j                  | j                  || j                  «      }|S )a˜  
        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       út/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/tools/cogniswitch/tool.pyÚ_runz CogniswitchKnowledgeRequest._run   s)   € ð$ —>‘> $§-¡-°·±ÀÈÏÉÓTˆØˆó    c                óâ   — |st        d«      ‚|st        d«      ‚|st        d«      ‚|st        d«      ‚|||dœ}d|i}t        j                  | j                  ||¬«      }|j	                  «       S )ac  
        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   z%CogniswitchKnowledgeRequest.answer_cs2   s€   € ñ ÜÐ/Ó0Ð0ÙÜÐ3Ó4Ð4ÙÜÐ>Ó?Ð?ÙÜÐ2Ó3Ð3ð Ø%Ø$ñ
ˆð ˜ÐˆÜ—=‘= §¡°wÀTÔ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__Ú__doc__r   Ú__annotations__r   r   r   r   © r   r   r
   r
   
   sf   … ñð 0€Dˆ#Ó/ð4€K�ó 4àƒMØƒNØƒKØU€GˆSÓUð
 <@ðàðð 9ðð 
ó	ô*r   r
   c                  óx   — e Zd ZU dZdZded<   dZded<   ded<   ded<   ded	<   d
Zded<   	 d	 	 	 	 	 dd„Zdd„Z	y)ÚCogniswitchKnowledgeStatusae  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                ó(   — | j                  |«      }|S )a•  
        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   zCogniswitchKnowledgeStatus._runi   s   € ð$ ×(Ñ(¨Ó7ˆØˆr   c                ó*  — || j                   dœ}| j                  | j                  | j                   dœ}t        j                  | j
                  ||¬«      }|j                  dk(  �r!|j                  «       }t        |d   «      }|j	                  d«      }|dk(  rd|d<   n6|d	k(  rd
|d<   n+|dk(  rd|d<   n |dk(  rd|d<   n|dk(  rd|d<   n
|dk(  rd|d<   d|j                  «       v r|j                  d«       d|j                  «       v r|j                  d«       d|j                  «       v r|j                  d«       d|j                  «       v r|j                  d«       d|j                  «       v r|j                  d«       |S d|j                  iS )a  
        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#   Úgetr4   Ústatus_coder%   r*   ÚkeysÚpop)r   r7   r;   r    r   Úsource_infoÚsource_datar>   s           r   r6   z+CogniswitchKnowledgeStatus.knowledge_status~   s™  € ð +¸T¿]¹]ÑKˆà—k‘kØŸ>™>Ø!Ÿ]™]ñ
ˆô
 —<‘<Ø×%Ñ%ØØô
ˆð
 ×Ñ 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&   )r7   r   r   r'   r(   r)   )r7   r   r(   r*   )
r+   r,   r-   r.   r   r/   r   r4   r   r6   r0   r   r   r2   r2   S   sm   … ñ	ð /€Dˆ#Ó.ðA€K�ó AàƒMØƒNØƒKàPð ˜#ó ð <@ðàðð 9ðð 
ó	ô*4r   r2   c                  ó–   — e Zd ZU dZdZded<   dZded<   ded<   ded<   ded	<   d
Zded<   	 	 	 	 d	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 	 dd„Z	y)ÚCogniswitchKnowledgeSourceFilea…  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                ó:   — |sddiS | j                  |||¬«      }|S )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.
        rO   úNo input provided)Úfiler7   Údocument_description©Ú
store_data)r   r\   r7   r]   r   r   s         r   r   z#CogniswitchKnowledgeSourceFile._runÍ   s<   € ñ0 àÐ.ðð ð —‘ØØ+Ø%9ð 'ó ˆHð
 ˆOr   c                ó  — | j                   | j                  | j                  dœ}|sd}|sd}|�dt        |d«      i}||dœ}t	        j
                  | j                  ||¬«      }|j                  dk(  r|j                  «       S dd	iS )
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.
        r:   Ú r\   Úrb)ÚdocumentNameÚdocumentDescription)r    r!   Úfilesr<   rO   úBad Request)	r   r   r   Úopenr#   r$   rY   rQ   r%   )r   r\   r7   r]   r    re   r!   r   s           r   r_   z)CogniswitchKnowledgeSourceFile.store_datañ   s¢   € ð. —k‘kØŸ>™>Ø!Ÿ]™]ñ
ˆñ ØˆMÙ#Ø#%Ð àÐØœT $¨Ó-Ð.ˆEð *Ø#7ñ
ˆô —=‘=Ø×%Ñ%ØØØô	
ˆð ×Ñ 3Ò&Ø—=‘=“?Ð"à˜}Ð-Ð-r   ©NNNN)
r\   úOptional[str]r7   ri   r]   ri   r   r'   r(   r)   )r\   ri   r7   ri   r]   ri   r(   r*   )
r+   r,   r-   r.   r   r/   r   rY   r   r_   r0   r   r   rW   rW   µ   s°   … ñð 4€Dˆ#Ó3ð€K�ó ð
 ƒMØƒNØƒKàNð ˜#ó ð #Ø'+Ø.2Ø;?ð"àð"ð %ð"ð ,ð	"ð
 9ð"ð 
ó"ðH1.àð1.ð %ð1.ð ,ð	1.ð
 
ô1.r   rW   c                  ó–   — e Zd ZU dZdZded<   dZded<   ded<   ded<   ded	<   d
Zded<   	 	 	 	 d	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 	 dd„Z	y)ÚCogniswitchKnowledgeSourceURLax  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                ó:   — |sddiS | j                  |||¬«      }|S )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.
        rO   r[   )Úurlr7   r]   r^   )r   ro   r7   r]   r   r   s         r   r   z"CogniswitchKnowledgeSourceURL._run<  s<   € ñ0 àÐ.ðð ð —?‘?ØØ'Ø!5ð #ó 
ˆð
 ˆr   c                óø   — | j                   | j                  | j                  dœ}|sd}|sd}|sddiS d|i}t        j                  | j
                  ||¬«      }|j                  dk(  r|j                  «       S ddiS )	aE  
        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.
        r:   ra   rO   r[   ro   r   r<   rf   )r   r   r   r#   r$   rm   rQ   r%   )r   ro   r7   r]   r    r!   r   s          r   r_   z(CogniswitchKnowledgeSourceURL.store_data_  s•   € ð* —k‘kØŸ>™>Ø!Ÿ]™]ñ
ˆñ ØˆMÙ#Ø#%Ð ÙàÐ.ðð ð ˜3�<ˆDÜ—}‘}Ø×(Ñ(ØØôˆHð
 ×Ñ 3Ò&Ø—=‘=“?Ð"à˜}Ð-Ð-r   rh   )
ro   ri   r7   ri   r]   ri   r   r'   r(   r)   )ro   ri   r7   ri   r]   ri   r(   r*   )
r+   r,   r-   r.   r   r/   r   rm   r   r_   r0   r   r   rk   rk   %  s²   … ñð 3€Dˆ#Ó2ðH€K�ó Hð ƒMØƒNØƒKàMð ˜ó ð "Ø'+Ø.2Ø;?ð!àð!ð %ð!ð ,ð	!ð
 9ð!ð 
ó!ðF,.àð,.ð %ð,.ð ,ð	,.ð
 
ô,.r   rk   )Ú
__future__r   Útypingr   r   r   r#   Úlangchain_core.callbacksr   Úlangchain_core.toolsr   r
   r2   rW   rk   r0   r   r   Ú<module>ru      sR   ðÝ "ç &Ñ &ã Ý >Ý )ôF (ô FôR_ ô _ôDm. Xô m.ô`f. Hõ f.r   