
    Ng                     F    d dl mZmZmZmZ d dlmZ  G d de          ZdS )    )AnyDictListOptional)
GraphStorec                   >   e Zd ZdZdeddfdZedefd            Zedee	ef         fd            Z
de	fdZdeddfd	Zdd
eee	ef                  ddfdZdee	eee	ef                  f         fdZd Zde	dee	ef         fdZi fde	de	de	dedee	         f
dZdS )
TigerGrapha  TigerGraph wrapper for graph operations.

    *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.
    connreturnNc                 X    |                      |           |                                  dS )z/Create a new TigerGraph graph wrapper instance.N)set_connection
set_schema)selfr
   s     g/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/graphs/tigergraph_graph.py__init__zTigerGraph.__init__   s,    D!!!    c                     | j         S N)_connr   s    r   r
   zTigerGraph.conn   s
    zr   c                     | j         S r   )_schemar   s    r   schemazTigerGraph.schema   s
    |r   c                     | j         rt          | j                   S |                                  t          | j                   S r   )r   strr   r   s    r   
get_schemazTigerGraph.get_schema"   s<    < 	%t|$$$OOt|$$$r   c                    	 ddl m} n# t          $ r t          d          w xY wt          ||          sd}t	          |          |j        j        d}t          |          || _        | 	                                 d S )Nr   )TigerGraphConnectionz`Could not import pyTigerGraph python package. Please install it with `pip install pyTigerGraph`.z9**conn** parameter must inherit from TigerGraphConnectionzs**conn** parameter does not have nlqs_host parameter defined.
                     Define hostname of NLQS service.)
pyTigerGraphr   ImportError
isinstance	TypeErrorai	nlqs_hostConnectionErrorr   r   )r   r
   r   msgs       r   r   zTigerGraph.set_connection)   s    	9999999 	 	 	E  	 $ 455 	!MCC.. 7$9C!#&&&+/
s   	 #r   c                 @    ||                                  n|| _        dS )zq
        Set the schema of the TigerGraph Database.
        Auto-generates Schema if **schema** is None.
        N)generate_schemar   )r   r   s     r   r   zTigerGraph.set_schema>   s$    
 28t++---Vr   c                 8    | j                             d          S )a  
        Generates the schema of the TigerGraph Database and returns it
        User can specify a **sample_ratio** (0 to 1) to determine the
        ratio of documents/edges used (in relation to the Collection size)
        to render each Collection Schema.
        T)force)r   	getSchemar   s    r   r(   zTigerGraph.generate_schemaE   s     z##$#///r   c                 .    |                                   d S r   )r(   r   s    r   refresh_schemazTigerGraph.refresh_schemaP   s    r   queryc                 D    | j         j                            |          }|S )zQuery the TigerGraph database.)r   r#   r.   )r   r.   answers      r   r.   zTigerGraph.queryS   s    $$U++r   function_headerdescription	docstringparam_typesc                 F    | j         j                            ||||          S )zZ
        Wrapper function to register a custom GSQL query to the TigerGraph NLQS.
        )r   r#   registerCustomQuery)r   r1   r2   r3   r4   s        r   register_queryzTigerGraph.register_queryX   s)     z}00[)[
 
 	
r   r   )__name__
__module____qualname____doc__r   r   propertyr
   r   r   r   r   r   r   r   r   r(   r-   r.   dictr7    r   r   r	   r	      s        S T    
 c    X S#X    X%C % % % %3 4    *L L$sCx.!9 LT L L L L	0	c4S#X''	(	0 	0 	0 	0  3 4S>     
 

 
 	

 
 
c
 
 
 
 
 
r   r	   N)typingr   r   r   r   &langchain_community.graphs.graph_storer   r	   r>   r   r   <module>rA      sy    , , , , , , , , , , , , = = = = = =^
 ^
 ^
 ^
 ^
 ^
 ^
 ^
 ^
 ^
r   