o
    j6h                     @  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   r/var/www/html/chefvision.cloud.itp360.com/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 )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   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   

'