§
    šŠtjú8  ã                   ó
  — d dl Z d dlmZmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ  G d„ de¦  «        Z G d„ de¦  «        Z ed	d
d¬¦  «         G d„ de¦  «        ¦   «         Z ed	d
d¬¦  «         G d„ de¦  «        ¦   «         ZdS )é    N)ÚABCÚabstractmethod)ÚAnyÚDictÚListÚOptionalÚTupleÚUnion)Ú
deprecatedc                   óF   — e Zd ZdZdeeef         fd„Zdefd„Zde	fd„Z
dS )ÚNeptuneQueryExceptionz"Exception for the Neptune queries.Ú	exceptionc                 óœ   — t          |t          ¦  «        r(d|v r|d         nd| _        d|v r|d         nd| _        d S || _        d| _        d S )NÚmessageÚunknownÚdetails)Ú
isinstanceÚdictr   r   )Úselfr   s     úf/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/graphs/neptune_graph.pyÚ__init__zNeptuneQueryException.__init__   s`   € Ý�i¥Ñ&Ô&ð 	%Ø3<À	Ð3IÐ3I˜9 YÔ/Ð/ÈyˆDŒLØ3<À	Ð3IÐ3I˜9 YÔ/Ð/ÈyˆDŒLˆLˆLà$ˆDŒLØ$ˆDŒLˆLˆLó    Úreturnc                 ó   — | j         S ©N)r   ©r   s    r   Úget_messagez!NeptuneQueryException.get_message   ó
   € ØŒ|Ðr   c                 ó   — | j         S r   )r   r   s    r   Úget_detailsz!NeptuneQueryException.get_details   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   Ústrr   r   r   r   r    © r   r   r   r      st   € € € € € Ø,Ð,ð% %¨¨T¨	Ô"2ð %ð %ð %ð %ð˜Sð ð ð ð ð˜Sð ð ð ð ð ð r   r   c                   ó&  — e Zd ZdZedefd„¦   «         Zei fdededefd„¦   «         Z	ede
fd„¦   «         Zdeee         ee         f         fd„Zd	ee         dee         fd
„Zdee         de
defd„Zd	ee         de
eef         defd„Zdd„ZdS )ÚBaseNeptuneGraphz Abstract base class for Neptune.r   c                 ó   — | j         S )z)Return the schema of the Neptune database)Úschemar   s    r   Ú
get_schemazBaseNeptuneGraph.get_schema   s   € ð Œ{Ðr   ÚqueryÚparamsc                 ó   — t          ¦   «         ‚r   ©ÚNotImplementedError)r   r,   r-   s      r   r,   zBaseNeptuneGraph.query"   ó   € å!Ñ#Ô#Ð#r   c                 ó   — t          ¦   «         ‚r   r/   r   s    r   Ú_get_summaryzBaseNeptuneGraph._get_summary&   r1   r   c                 óR   — |                       ¦   «         }|d         }|d         }||fS )z<Get node and edge labels from the Neptune statistics summaryÚ
nodeLabelsÚ
edgeLabels)r3   )r   ÚsummaryÚn_labelsÚe_labelss       r   Ú_get_labelszBaseNeptuneGraph._get_labels*   s2   € à×#Ò#Ñ%Ô%ˆØ˜<Ô(ˆØ˜<Ô(ˆØ˜Ð!Ð!r   r9   c                 ó  — d}d}g }|D ]}}|                      |¬¦  «        }|                      |¦  «        }|D ]M}|                      |d         d         |d         |d         d         ¬¦  «        }	|                     |	¦  «         ŒNŒ~|S )	Nz«
        MATCH (a)-[e:`{e_label}`]->(b)
        WITH a,e,b LIMIT 3000
        RETURN DISTINCT labels(a) AS from, type(e) AS edge, labels(b) AS to
        LIMIT 10
        z(:`{a}`)-[:`{e}`]->(:`{b}`)©Úe_labelÚfromr   ÚedgeÚto)ÚaÚeÚb)Úformatr,   Úappend)
r   r9   Útriple_queryÚtriple_templateÚtriple_schemaÚlabelÚqÚdataÚdÚtriples
             r   Ú_get_tripleszBaseNeptuneGraph._get_triples1   s³   € ðˆð 8ˆØˆØð 	-ð 	-ˆEØ×#Ò#¨EÐ#Ñ2Ô2ˆAØ—:’:˜a‘=”=ˆDØð -ð -�Ø(×/Ò/Ø˜”i ”l a¨¤i°1°T´7¸1´:ð 0ñ ô �ð ×$Ò$ VÑ,Ô,Ð,Ð,ð	-ð Ðr   r8   Útypesc           
      óŽ  — d}g }|D ]½}|                      |¬¦  «        }||                      |¦  «        dœ}t          i ¦  «        }|d         D ]Q}	|	d                              ¦   «         D ]4\  }
}|                     |
|t          |¦  «        j                 f¦  «         Œ5ŒRd„ |D ¦   «         |dœ}|                     |¦  «         Œ¾|S )Nz_
        MATCH (a:`{n_label}`)
        RETURN properties(a) AS props
        LIMIT 100
        )Ún_label©rI   Ú
propertiesrS   Úpropsc                 ó   — g | ]
\  }}||d œ‘ŒS ©)ÚpropertyÚtyper&   ©Ú.0ÚkÚvs      r   ú
<listcomp>z9BaseNeptuneGraph._get_node_properties.<locals>.<listcomp>V   ó$   € ÐHÐHÐH¹d¸aÀ¨A°qÐ9Ð9ÐHÐHÐHr   )rS   Úlabels©rD   r,   ÚsetÚitemsÚaddrX   r!   rE   )r   r8   rO   Únode_properties_queryÚnode_propertiesrI   rJ   rK   ÚsÚpr[   r\   Únps                r   Ú_get_node_propertiesz%BaseNeptuneGraph._get_node_propertiesF   sþ   € ð!Ðð
 ˆØð 	'ð 	'ˆEØ%×,Ò,°UÐ,Ñ;Ô;ˆAØ"°$·*²*¸Q±-´-Ð@Ð@ˆDÝ�B‘”ˆAØ˜,Ô'ð 8ð 8�Ø˜gœJ×,Ò,Ñ.Ô.ð 8ð 8‘D�A�qØ—E’E˜1˜e¥D¨¡G¤GÔ$4Ô5Ð6Ñ7Ô7Ð7Ð7ð8ð IÐHÀaÐHÑHÔHØðð ˆBð ×"Ò" 2Ñ&Ô&Ð&Ð&àÐr   c           
      óŽ  — d}g }|D ]½}|                      |¬¦  «        }||                      |¦  «        dœ}t          i ¦  «        }|d         D ]Q}	|	d                              ¦   «         D ]4\  }
}|                     |
|t          |¦  «        j                 f¦  «         Œ5ŒR|d„ |D ¦   «         dœ}|                     |¦  «         Œ¾|S )Nzf
        MATCH ()-[e:`{e_label}`]->()
        RETURN properties(e) AS props
        LIMIT 100
        r<   rR   rS   rT   c                 ó   — g | ]
\  }}||d œ‘ŒS rV   r&   rY   s      r   r]   z9BaseNeptuneGraph._get_edge_properties.<locals>.<listcomp>n   r^   r   )rX   rS   r`   )r   r9   rO   Úedge_properties_queryÚedge_propertiesrI   rJ   rK   rf   rg   r[   r\   Úeps                r   Ú_get_edge_propertiesz%BaseNeptuneGraph._get_edge_properties]   sý   € ð!Ðð
 ˆØð 	'ð 	'ˆEØ%×,Ò,°UÐ,Ñ;Ô;ˆAØ"°$·*²*¸Q±-´-Ð@Ð@ˆDÝ�B‘”ˆAØ˜,Ô'ð 8ð 8�Ø˜gœJ×,Ò,Ñ.Ô.ð 8ð 8‘D�A�qØ—E’E˜1˜e¥D¨¡G¤GÔ$4Ô5Ð6Ñ7Ô7Ð7Ð7ð8ð ØHÐHÀaÐHÑHÔHðð ˆBð ×"Ò" 2Ñ&Ô&Ð&Ð&àÐr   Nc                 óê   — dddddddœ}|                       ¦   «         \  }}|                      |¦  «        }|                      ||¦  «        }|                      ||¦  «        }d|› d	|› d
|› d�| _        dS )zA
        Refreshes the Neptune graph schema information.
        ÚSTRINGÚDOUBLEÚINTEGERÚLISTÚMAPÚBOOLEAN)r%   ÚfloatÚintÚlistr   Úboolz4
        Node properties are the following:
        z<
        Relationship properties are the following:
        z6
        The relationships are the following:
        z	
        N)r:   rN   ri   ro   r*   )r   rO   r8   r9   rH   re   rm   s          r   Ú_refresh_schemaz BaseNeptuneGraph._refresh_schemat   s´   € ð ØØØØØð
ð 
ˆð "×-Ò-Ñ/Ô/Ñˆ�(Ø×)Ò)¨(Ñ3Ô3ˆØ×3Ò3°H¸eÑDÔDˆØ×3Ò3°H¸eÑDÔDˆðà	ðð ð 
ð	ð ð 
ðð ð ˆŒˆˆr   )r   N)r!   r"   r#   r$   rW   r%   r+   r   r   r,   r   r3   r	   r   r:   rN   ri   r   ro   r{   r&   r   r   r(   r(      sq  € € € € € Ø*Ð*àð˜Cð ð ð ñ „Xðð Ø/1ð $ð $˜3ð $¨ð $°dð $ð $ð $ñ „^ð$ð ð$˜dð $ð $ð $ñ „^ð$ð"˜U 4¨¤9¨d°3¬iÐ#7Ô8ð "ð "ð "ð "ð T¨#¤Yð °4¸´9ð ð ð ð ð*¨T°#¬Yð ¸tð Èð ð ð ð ð.¨T°#¬Yð ¸tÀCÈÀH¼~ð ÐRVð ð ð ð ð.ð ð ð ð ð r   r(   z0.3.15z1.0z#langchain_aws.NeptuneAnalyticsGraph)ÚsinceÚremovalÚalternative_importc                   ó‚   — e Zd ZdZ	 	 	 ddededee         dee         ddf
d„Zi fd	ed
ede	eef         fd„Z
de	fd„ZdS )ÚNeptuneAnalyticsGraphaY  Neptune Analytics wrapper for graph operations.

    Parameters:
        client: optional boto3 Neptune client
        credentials_profile_name: optional AWS profile name
        region_name: optional AWS region, e.g., us-west-2
        graph_identifier: the graph identifier for a Neptune Analytics graph

    Example:
        .. code-block:: python

        graph = NeptuneAnalyticsGraph(
            graph_identifier='<my-graph-id>'
        )

    *Security note*: Make sure that the database connection uses credentials
        that are narrowly-scoped to only include necessary permissions.
        Failure to do so may result in data corruption or loss, since the calling
        code may attempt commands that would result in deletion, mutation
        of data if appropriately prompted or reading sensitive data if such
        data is present in the database.
        The best way to guard against such negative outcomes is to (as appropriate)
        limit the permissions granted to the credentials used with this tool.

        See https://python.langchain.com/docs/security for more information.
    NÚgraph_identifierÚclientÚcredentials_profile_nameÚregion_namer   c                 óP  — 	 |�|| _         nqddl}|�|                     |¬¦  «        }n|                     ¦   «         }|| _        |r|                      d|¬¦  «        | _         n|                      d¦  «        | _         nb# t          $ r t	          d¦  «        ‚t
          $ r=}t          |¦  «        j        dk    rt	          d¦  «        |‚t          d	¦  «        |‚d}~ww xY w	 |  	                    ¦   «          dS # t
          $ r$}t          d
t          |¦  «        dœ¦  «        ‚d}~ww xY w)z6Create a new Neptune Analytics graph wrapper instance.Nr   ©Úprofile_namezneptune-graph)r„   úRCould not import boto3 python package. Please install it with `pip install boto3`.ÚUnknownServiceErrorzgNeptuneGraph requires a boto3 version 1.34.40 or greater.Please install it with `pip install -U boto3`.ú‚Could not load credentials to authenticate with AWS client. Please check that credentials in the specified profile name are valid.ú)Could not get schema for Neptune database©r   Údetail)r‚   Úboto3ÚSessionr�   ÚImportErrorÚ	ExceptionrX   r!   Ú
ValueErrorr{   r   r%   )r   r�   r‚   rƒ   r„   rŽ   ÚsessionrB   s           r   r   zNeptuneAnalyticsGraph.__init__±   s�  € ð%	ØÐ!Ø$�”�à���à+Ð7Ø#ŸmšmÐ9Q˜mÑRÔR�G�Gð $Ÿmšm™oœo�Gà(8�Ô%àð BØ")§.¢.Ø'°[ð #1ñ #ô #�D”K�Kð #*§.¢.°Ñ"AÔ"A�D”Køøåð 	ð 	ð 	Ýð>ñô ð õ ð 	ð 	ð 	Ý�A‰wŒwÔÐ#8Ò8Ð8Ý!ðEñô ð ðõ
 !ð.ñô ð ð	øøøøð	øøøð	Ø× Ò Ñ"Ô"Ð"Ð"Ð"øÝð 	ð 	ð 	Ý'àJÝ! !™fœfðð ñô ð øøøøð	øøøs0   ‚A;A> Á>"CÂ 8CÃCÃ!C7 Ã7
D%ÄD Ä D%r,   r-   c                 ó6  — 	 | j                              | j        ||d¬¦  «        }t          j        |d                              ¦   «                              d¦  «        ¦  «        d         S # t          $ r$}t          dt          |¦  «        dœ¦  «        ‚d}~ww xY w)	úQuery Neptune database.ÚOPEN_CYPHER)ÚgraphIdentifierÚqueryStringÚ
parametersÚlanguageÚpayloadzUTF-8Úresultsú,An error occurred while executing the query.©r   r   N)
r‚   Úexecute_queryr�   ÚjsonÚloadsÚreadÚdecoder‘   r   r%   )r   r,   r-   ÚresprB   s        r   r,   zNeptuneAnalyticsGraph.queryë   s®   € ð	Ø”;×,Ò,Ø $Ô 5Ø!Ø!Ø&ð	 -ñ ô ˆDõ ”:˜d 9œo×2Ò2Ñ4Ô4×;Ò;¸GÑDÔDÑEÔEÀiÔPÐPøÝð 	ð 	ð 	Ý'àMÝ" 1™vœvðð ñô ð øøøøð	øøøs   ‚A'A* Á*
BÁ4BÂBc                 ó.  — 	 | j                              | j        d¬¦  «        }n1# t          $ r$}t	          dt          |¦  «        dœ¦  «        ‚d }~ww xY w	 |d         }|S # t          $ r* t	          d|j                             ¦   «         dœ¦  «        ‚w xY w)NÚdetailed)r—   Úmodez/Summary API error occurred on Neptune Analyticsrž   ÚgraphSummaryú,Summary API did not return a valid response.)r‚   Úget_graph_summaryr�   r‘   r   r%   Úcontentr£   ©r   ÚresponserB   r7   s       r   r3   z"NeptuneAnalyticsGraph._get_summaryý   sÚ   € ð
	Ø”{×4Ò4Ø $Ô 5¸Jð 5ñ ô ˆHˆHøõ ð 	ð 	ð 	Ý'à QÝ" 1™vœvðð ñô ð øøøøð	øøøð
	Ø˜~Ô.ˆGð ˆNøõ ð 	ð 	ð 	Ý'àMØ'Ô/×6Ò6Ñ8Ô8ðð ñô ð ð	øøøs    ‚!$ ¤
A®AÁAÁA  Á 4B)NNN)r!   r"   r#   r$   r%   r   r   r   r   r   r,   r3   r&   r   r   r€   r€   �   sÑ   € € € € € ðð ð< Ø26Ø%)ð8ð 8àð8ð ð8ð #+¨3¤-ð	8ð
 ˜c”]ð8ð 
ð8ð 8ð 8ð 8ðt 02ð ð ˜3ð ¨ð °d¸3À¸8´nð ð ð ð ð$˜dð ð ð ð ð ð r   r€   zlangchain_aws.NeptuneGraphc                   ó”   — e Zd ZdZ	 	 	 	 	 	 ddedededed	ee         d
ee         deddfd„Z	i fdede
deeef         fd„Zdefd„ZdS )ÚNeptuneGrapha  Neptune wrapper for graph operations.

    Parameters:
        host: endpoint for the database instance
        port: port number for the database instance, default is 8182
        use_https: whether to use secure connection, default is True
        client: optional boto3 Neptune client
        credentials_profile_name: optional AWS profile name
        region_name: optional AWS region, e.g., us-west-2
        sign: optional, whether to sign the request payload, default is True

    Example:
        .. code-block:: python

        graph = NeptuneGraph(
            host='<my-cluster>',
            port=8182
        )

    *Security note*: Make sure that the database connection uses credentials
        that are narrowly-scoped to only include necessary permissions.
        Failure to do so may result in data corruption or loss, since the calling
        code may attempt commands that would result in deletion, mutation
        of data if appropriately prompted or reading sensitive data if such
        data is present in the database.
        The best way to guard against such negative outcomes is to (as appropriate)
        limit the permissions granted to the credentials used with this tool.

        See https://python.langchain.com/docs/security for more information.
    éö  TNÚhostÚportÚ	use_httpsr‚   rƒ   r„   Úsignr   c                 óŒ  — 	 |�|| _         n�ddl}|�|                     |¬¦  «        }	n|                     ¦   «         }	i }
|r||
d<   |rdnd}|› d|› d|› �|
d	<   |r |	j         di |
¤Ž| _         n-ddlm} ddlm}  |	j         	 di |
¤d ||¬¦  «        i¤Ž| _         nb# t          $ r t          d¦  «        ‚t          $ r=}t          |¦  «        j
        dk    rt          d¦  «        |‚t          d¦  «        |‚d}~ww xY w	 |                      ¦   «          dS # t          $ r$}t          dt          |¦  «        dœ¦  «        ‚d}~ww xY w)z,Create a new Neptune graph wrapper instance.Nr   r†   r„   ÚhttpsÚhttpz://ú:Úendpoint_urlÚneptunedata)ÚUNSIGNED)ÚConfigÚconfig)Úsignature_versionrˆ   r‰   zgNeptuneGraph requires a boto3 version 1.28.38 or greater.Please install it with `pip install -U boto3`.rŠ   r‹   rŒ   )rº   )r‚   rŽ   r�   Úbotocorer»   Úbotocore.configr¼   r�   r‘   rX   r!   r’   r{   r   r%   )r   r±   r²   r³   r‚   rƒ   r„   r´   rŽ   r“   Úclient_paramsÚprotocolr»   r¼   rB   s                  r   r   zNeptuneGraph.__init__<  s  € ð0	ØÐ!Ø$�”�à���à+Ð7Ø#ŸmšmÐ9Q˜mÑRÔR�G�Gð $Ÿmšm™oœo�Gà "�Øð ?Ø3>�M -Ñ0à&/Ð;˜7˜7°V�à3;Ð0MÐ0MÀÐ0MÐ0MÀtÐ0MÐ0M�˜nÑ-àð 
Ø"0 '¤.Ð"PÐ"PÀ-Ð"PÐ"P�D”K�Kà1Ð1Ð1Ð1Ð1Ð1Ø6Ð6Ð6Ð6Ð6Ð6à"0 '¤.Ø%ð#ð #à'ð#ð #ð  &˜v¸ÐAÑAÔAð#ð #ð #�D”Køøõ ð 	ð 	ð 	Ýð>ñô ð õ ð 	ð 	ð 	Ý�A‰wŒwÔÐ#8Ò8Ð8Ý!ðEñô ð ðõ
 !ð.ñô ð ð	øøøøð	øøøð	Ø× Ò Ñ"Ô"Ð"Ð"Ð"øÝð 	ð 	ð 	Ý'àJÝ! !™fœfðð ñô ð øøøøð	øøøs0   ‚BB Â"C;Â>8C6Ã6C;Ã?D Ä
EÄD>Ä>Er,   r-   c                 ó¨   — 	 | j                              |¬¦  «        d         S # t          $ r$}t          dt	          |¦  «        dœ¦  «        ‚d}~ww xY w)r•   )ÚopenCypherQueryrœ   r�   rž   N)r‚   Úexecute_open_cypher_queryr‘   r   r%   )r   r,   r-   rB   s       r   r,   zNeptuneGraph.query„  ss   € ð
	Ø”;×8Ò8ÈÐ8ÑOÔOØôð øõ ð 	ð 	ð 	Ý'àMÝ" 1™vœvðð ñô ð øøøøð	øøøs   ‚ # £
A­AÁAc                 ó*  — 	 | j                              ¦   «         }n1# t          $ r$}t          dt	          |¦  «        dœ¦  «        ‚d }~ww xY w	 |d         d         }|S # t          $ r* t          d|j                             ¦   «         dœ¦  «        ‚w xY w)Nz`Summary API is not available for this instance of Neptune,ensure the engine version is >=1.2.1.0rž   r›   r¨   r©   )r‚   Úget_propertygraph_summaryr‘   r   r%   r«   r£   r¬   s       r   r3   zNeptuneGraph._get_summary’  sÑ   € ð	Ø”{×<Ò<Ñ>Ô>ˆHˆHøÝð 		ð 		ð 		Ý'ðAõ  # 1™vœvðð ñô ð øøøøð		øøøð
	Ø˜yÔ)¨.Ô9ˆGð ˆNøõ ð 	ð 	ð 	Ý'àMØ'Ô/×6Ò6Ñ8Ô8ðð ñô ð ð	øøøs    ‚ œ
A
¦AÁA
ÁA Á4B)r°   TNNNT)r!   r"   r#   r$   r%   rx   rz   r   r   r   r   r   r,   r3   r&   r   r   r¯   r¯     s  € € € € € ðð ðD ØØØ26Ø%)ØðFð FàðFð ðFð ð	Fð
 ðFð #+¨3¤-ðFð ˜c”]ðFð ðFð 
ðFð Fð Fð FðP 02ð ð ˜3ð ¨ð °d¸3À¸8´nð ð ð ð ð˜dð ð ð ð ð ð r   r¯   )r    Úabcr   r   Útypingr   r   r   r   r	   r
   Úlangchain_core._api.deprecationr   r‘   r   r(   r€   r¯   r&   r   r   ú<module>rË      sŠ  ðØ €€€Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :à 6Ð 6Ð 6Ð 6Ð 6Ð 6ðð ð ð ð ˜Iñ ô ð ð$sð sð sð sð s�sñ sô sð sðl €Ø
ØØ<ðñ ô ð
ð ð ð ð Ð,ñ ô ñô ð
ðD €Ø
ØØ3ðñ ô ð
Nð Nð Nð Nð NÐ#ñ Nô Nñô ð
Nð Nð Nr   