§
    šŠtjÃ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dS )é    )Úannotations)ÚAnyÚDictÚOptionalN)ÚCallbackManagerForToolRun)ÚBaseToolc                  óp   — 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	dS )Ú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_urlNÚqueryÚrun_managerú#Optional[CallbackManagerForToolRun]ÚreturnúDict[str, Any]c                óT   — |                       | 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   )Úselfr   r   Úresponses       úh/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/tools/cogniswitch/tool.pyÚ_runz CogniswitchKnowledgeRequest._run   s&   € ð$ —>’> $¤-°´ÀÈÌÑTÔTˆØˆó    Údictc                óþ   — |st          d¦  «        ‚|st          d¦  «        ‚|st          d¦  «        ‚|st          d¦  «        ‚|||dœ}d|i}t          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ª   € ð ð 	1ÝÐ/Ñ0Ô0Ð0Øð 	5ÝÐ3Ñ4Ô4Ð4Øð 	@ÝÐ>Ñ?Ô?Ð?Øð 	4ÝÐ2Ñ3Ô3Ð3ð Ø%Ø$ð
ð 
ˆð ˜ÐˆÝ”= ¤°wÀTÐJÑJÔJˆØ�}Š}‰ŒÐr   ©N)r   r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r   r   © r   r   r
   r
   
   s­   € € € € € € ðð ð 0€DÐ/Ð/Ð/Ñ/ð4€Kð 4ð 4ð 4ñ 4à€M€M�MØ€N€N�NØ€K€K�KØU€GÐUÐUÐUÑUð
 <@ðð ð ð ð ð*ð ð ð ð ð r   r
   c                  óp   — 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	dS )Ú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_urlNÚdocument_namer   r   r   r   c                ó0   — |                       |¦  «        }|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   r5   r   r   s       r   r   zCogniswitchKnowledgeStatus._runi   s   € ð$ ×(Ò(¨Ñ7Ô7ˆØˆr   r   c                ó^  — || j         dœ}| j        | j        | j         dœ}t          j        | j        ||¬¦  «        }|j        dk    �r^|                     ¦   «         }t          |d         ¦  «        }|                     d¦  «        }|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<   n|dk    rd|d<   d| 	                    ¦   «         v r| 
                    d¦  «         d| 	                    ¦   «         v r| 
                    d¦  «         d| 	                    ¦   «         v r| 
                    d¦  «         d| 	                    ¦   «         v r| 
                    d¦  «         d| 	                    ¦   «         v r| 
                    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   r5   r;   r$   r   Úsource_infoÚsource_datar>   s           r   r7   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Ð4Ð4Ø—’ Ñ0Ô0Ð0Ø$¨×(8Ò(8Ñ(:Ô(:Ð:Ð:Ø—’Ð 5Ñ6Ô6Ð6Ø˜[×-Ò-Ñ/Ô/Ð/Ð/Ø—’ 
Ñ+Ô+Ð+Ø˜{×/Ò/Ñ1Ô1Ð1Ð1Ø—’ Ñ-Ô-Ð-ØÐð ˜8Ô/ðð r   r*   )r5   r   r   r   r   r   )r5   r   r   r   )
r+   r,   r-   r.   r   r/   r   r4   r   r7   r0   r   r   r2   r2   S   s½   € € € € € € ð	ð 	ð /€DÐ.Ð.Ð.Ñ.ðA€Kð Að Að Añ Aà€M€M�MØ€N€N�NØ€K€K�KàPð ð ð ð ñ ð <@ðð ð ð ð ð*4ð 4ð 4ð 4ð 4ð 4r   r2   c                  óv   — 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	dS )Ú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_fileNÚfileúOptional[str]r5   Údocument_descriptionr   r   r   r   c                óB   — |sddiS |                       |||¬¦  «        }|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)rZ   r5   r\   ©Ú
store_data)r   rZ   r5   r\   r   r   s         r   r   z#CogniswitchKnowledgeSourceFile._runÍ   sF   € ð0 ð 
	àÐ.ðð ð —’ØØ+Ø%9ð 'ñ ô ˆHð
 ˆOr   r   c                óî   — | j         | j        | j        dœ}|sd}|sd}|�dt          |d¦  «        i}||dœ}t	          j        | j        |||¬¦  «        }|j        dk    r|                     ¦   «         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:   Ú NrZ   Úrb)ÚdocumentNameÚdocumentDescription)r$   r%   Úfilesr<   rO   úBad Request)	r   r   r   Úopenr'   r(   rY   rQ   r)   )r   rZ   r5   r\   r$   rf   r%   r   s           r   r`   z)CogniswitchKnowledgeSourceFile.store_datañ   sº   € ð. ”kØœ>Ø!œ]ð
ð 
ˆð ð 	ØˆMØ#ð 	&Ø#%Ð àÐØ�T $¨Ñ-Ô-Ð.ˆEð *Ø#7ð
ð 
ˆõ ”=ØÔ%ØØØð	
ñ 
ô 
ˆð Ô 3Ò&Ð&Ø—=’=‘?”?Ð"à˜}Ð-Ð-r   ©NNNN)
rZ   r[   r5   r[   r\   r[   r   r   r   r   )rZ   r[   r5   r[   r\   r[   r   r   )
r+   r,   r-   r.   r   r/   r   rY   r   r`   r0   r   r   rW   rW   µ   sÃ   € € € € € € ðð ð 4€DÐ3Ð3Ð3Ñ3ð€Kð ð ð ñ ð
 €M€M�MØ€N€N�NØ€K€K�KàNð ð ð ð ñ ð #Ø'+Ø.2Ø;?ð"ð "ð "ð "ð "ðH1.ð 1.ð 1.ð 1.ð 1.ð 1.r   rW   c                  óv   — 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	dS )Ú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_urlNÚurlr[   r5   r\   r   r   r   r   c                óB   — |sddiS |                       |||¬¦  «        }|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^   )rn   r5   r\   r_   )r   rn   r5   r\   r   r   s         r   r   z"CogniswitchKnowledgeSourceURL._run<  sF   € ð0 ð 	àÐ.ðð ð —?’?ØØ'Ø!5ð #ñ 
ô 
ˆð
 ˆr   r   c                óÎ   — | j         | j        | j        dœ}|sd}|sd}|sddiS d|i}t          j        | j        ||¬¦  «        }|j        dk    r|                     ¦   «         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:   rb   rO   r^   rn   r#   r<   rg   )r   r   r   r'   r(   rm   rQ   r)   )r   rn   r5   r\   r$   r%   r   s          r   r`   z(CogniswitchKnowledgeSourceURL.store_data_  sª   € ð* ”kØœ>Ø!œ]ð
ð 
ˆð ð 	ØˆMØ#ð 	&Ø#%Ð Øð 
	àÐ.ðð ð ˜3�<ˆDÝ”}ØÔ(ØØðñ ô ˆHð
 Ô 3Ò&Ð&Ø—=’=‘?”?Ð"à˜}Ð-Ð-r   ri   )
rn   r[   r5   r[   r\   r[   r   r   r   r   )rn   r[   r5   r[   r\   r[   r   r   )
r+   r,   r-   r.   r   r/   r   rm   r   r`   r0   r   r   rk   rk   %  sÈ   € € € € € € ðð ð 3€DÐ2Ð2Ð2Ñ2ðH€Kð Hð Hð Hñ Hð €M€M�MØ€N€N�NØ€K€K�KàMð ð ð ð ñ ð "Ø'+Ø.2Ø;?ð!ð !ð !ð !ð !ðF,.ð ,.ð ,.ð ,.ð ,.ð ,.r   rk   )Ú
__future__r   Útypingr   r   r   r'   Úlangchain_core.callbacksr   Úlangchain_core.toolsr   r
   r2   rW   rk   r0   r   r   ú<module>ru      s9  ðØ "Ð "Ð "Ð "Ð "Ð "à &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à €€€Ø >Ð >Ð >Ð >Ð >Ð >Ø )Ð )Ð )Ð )Ð )Ð )ðFð Fð Fð Fð F (ñ Fô Fð FðR_ð _ð _ð _ð _ ñ _ô _ð _ðDm.ð m.ð m.ð m.ð m. Xñ m.ô m.ð m.ð`f.ð f.ð f.ð f.ð f. Hñ f.ô f.ð f.ð f.ð f.r   