
    rh                       U d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddl	mZ dd	l	mZ dd
l	mZ ddl	mZ ddlZddlmZ de_        ej(                  Zej*                  Zej,                  Zej.                  Zdaded<   ddZddZ G d dej8                        Z G d de      Zej>                   G d dej@                               Z  ejB                         jE                  e        y)z,Colab Magics class.

Installs %%llm magics.
    )annotationsN)credentials)client)gspread_client)ipython_env)ipython_env_impl)magics_engine)post_process_utils)sheets_utils)magiczgenai-py-magiczipython_env.IPythonEnv | None_ipython_envc                 B    t         t        j                         a t         S )z;Lazily constructs and returns a global IPythonEnv instance.)r   r   IPythonEnvImpl     v/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/google/generativeai/notebook/magics.py_get_ipython_envr   4   s     '668r   c                B    t        j                  | t                      y)zSets up credentials.

    This is used for interacting Google APIs, such as Google Sheets.

    Args:
      creds: The credentials that will be used (e.g. to read from Google Sheets.)
    )credsenvN)r   	authorizer   )r   s    r   r   r   <   s     5.>.@Ar   c                  6    e Zd ZdZej
                  dd       Zy)AbstractMagicsz"Defines interface to Magics class.c                    t               )zPerform various LLM-related operations.

        Args:
          cell_line: String to pass to the MagicsEngine.
          cell_body: Contents of the cell body.
        )NotImplementedErrorself	cell_line	cell_bodys      r   llmzAbstractMagics.llmJ   s     "##r   Nr   
str | Noner   r"   )__name__
__module____qualname____doc__abcabstractmethodr    r   r   r   r   r   G   s    ,$ $r   r   c                      e Zd ZdZd ZddZy)
MagicsImplzActual class implementing the magics functionality.

    We use a separate class to ensure a single, global instance
    of the magics class.
    c                J    t        j                  t                     | _        y )N)r   )r	   MagicsEnginer   _engine)r   s    r   __init__zMagicsImpl.__init__\   s    $116F6HIr   c                R    |xs d}|xs d}| j                   j                  ||      S )Perform various LLM-related operations.

        Args:
          cell_line: String to pass to the MagicsEngine.
          cell_body: Contents of the cell body.

        Returns:
          Results from running MagicsEngine.
         )r-   execute_cellr   s      r   r    zMagicsImpl.llm_   s-     O	O	||((I>>r   Nr!   )r#   r$   r%   r&   r.   r    r   r   r   r*   r*   U   s    J?r   r*   c                      e Zd ZdZdZedd       Zej                  dd       Z	ej                  dd       Z
ej                  dd       Zy)	Magicsz|Class to register the magic with Colab.

    Objects of this class delegate all calls to a single,
    global instance.
    Nc                P    | j                   t               | _         | j                   S )z.Retrieve global instance of the Magics object.)	_instancer*   )clss    r   get_instancezMagics.get_instancey   s!     == &LCM}}r   c                L    t         j                         j                  ||      S )r0   )r   r   )r4   r8   r    r   s      r   r    z
Magics.llm   s#     ""$((9	(RRr   c                &    | j                  ||      S Nr    r   s      r   palmzMagics.palm       xx	9--r   c                &    | j                  ||      S r;   r<   r   s      r   geminizMagics.gemini   r>   r   )returnr   r!   )r#   r$   r%   r&   r6   classmethodr8   r   line_cell_magicr    r=   r@   r   r   r   r4   r4   n   sp     I  
S 
S . . . .r   r4   )rA   zipython_env.IPythonEnv)r   zcredentials.CredentialsrA   None)#r&   
__future__r   r'   google.authr   google.generativeair   genaigoogle.generativeai.notebookr   r   r   r	   r
   r   IPythonIPython.corer   
USER_AGENTSheetsInputsSheetsOutputspost_process_add_fnpost_process_replace_fnr   __annotations__r   r   ABCr   r*   magics_classr4   get_ipythonregister_magicsr   r   r   <module>rV      s    # 
 # / 7 4 9 6 ; 5   $ ((** )<< ,DD  /3+ 2B$SWW $? ?2 $.U\\ $. $.N     % %f -r   