o
    ß­j  ã                   @  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   ÚIPythonEnvImpl© r   r   ú`/var/www/html/CropPilot/venv/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 )z¼Sets 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 ƒ ‚)z¨Perform 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 )Ú
MagicsImplz’Actual 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   Ú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)   Ú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.   r1   r   r   r   r   r   r   €   s   z
Magics.llmc                 C  ó   |   ||¡S ©N©r   r   r   r   r   Úpalm�   ó   zMagics.palmc                 C  r2   r3   r4   r   r   r   r   Úgemini‘   r6   zMagics.gemini)r   r   r    )r!   r"   r#   r$   r/   Úclassmethodr1   r   Úline_cell_magicr   r5   r7   r   r   r   r   r.   n   s    r.   )r   r   )r   r   r   r   )#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_classr.   Úget_ipythonÚregister_magicsr   r   r   r   Ú<module>   s4   

'