o
    Zh                     @  s  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dZd ddZG dd dejZG dd deZejG dd dej Z e! "e  dS )!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_envreturnipython_env.IPythonEnvc                   C  s   t du rt a t S )z;Lazily constructs and returns a global IPythonEnv instance.N)r   r   ZIPythonEnvImpl r   r   Z/var/www/html/lang_env/lib/python3.10/site-packages/google/generativeai/notebook/magics.py_get_ipython_env4   s   r   credscredentials.CredentialsNonec                 C  s   t j| t d dS )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.)
    )r   envN)r   	authorizer   )r   r   r   r   r   <   s   r   c                   @  s    e Zd ZdZejdddZdS )	AbstractMagicsz"Defines interface to Magics class.	cell_line
str | None	cell_bodyc                 C  s   t  )zPerform various LLM-related operations.

        Args:
          cell_line: String to pass to the MagicsEngine.
          cell_body: Contents of the cell body.
        )NotImplementedErrorselfr   r   r   r   r   llmJ   s   zAbstractMagics.llmNr   r   r   r   )__name__
__module____qualname____doc__abcabstractmethodr   r   r   r   r   r   G   s    r   c                   @  s"   e Zd ZdZdd Zd
ddZd	S )
MagicsImplzActual class implementing the magics functionality.

    We use a separate class to ensure a single, global instance
    of the magics class.
    c                 C  s   t jt d| _d S )N)r   )r   ZMagicsEnginer   _engine)r   r   r   r   __init__\   s   zMagicsImpl.__init__r   r   r   c                 C  s   |pd}|pd}| 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'   Zexecute_cellr   r   r   r   r   _   s   
zMagicsImpl.llmNr   )r    r!   r"   r#   r(   r   r   r   r   r   r&   U   s    r&   c                   @  sR   e Zd ZdZdZedddZejdd
dZ	ejdddZ
ejdddZdS )Magicsz|Class to register the magic with Colab.

    Objects of this class delegate all calls to a single,
    global instance.
    Nr   r   c                 C  s   | j du r	t | _ | j S )z.Retrieve global instance of the Magics object.N)	_instancer&   )clsr   r   r   get_instancey   s   
zMagics.get_instancer   r   r   c                 C  s   t  j||dS )r)   )r   r   )r+   r.   r   r   r   r   r   r      s   z
Magics.llmc                 C     |  ||S Nr   r   r   r   r   palm      zMagics.palmc                 C  r/   r0   r1   r   r   r   r   gemini   r3   zMagics.gemini)r   r   r   )r    r!   r"   r#   r,   classmethodr.   r   Zline_cell_magicr   r2   r4   r   r   r   r   r+   n   s    r+   )r   r   )r   r   r   r   )#r#   
__future__r   r$   Zgoogle.authr   Zgoogle.generativeair   ZgenaiZgoogle.generativeai.notebookr   r   r   r   r	   r
   ZIPythonZIPython.corer   Z
USER_AGENTZSheetsInputsZSheetsOutputsZpost_process_add_fnZpost_process_replace_fnr   __annotations__r   r   ABCr   r&   Zmagics_classr+   get_ipythonZregister_magicsr   r   r   r   <module>   s4   

'