
    +j"Z                     ,   d dl Z d dlZd dlmZmZmZ d dl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mZ ddlmZmZ dd	lmZmZ dd
lmZmZ ddlmZmZ ddlmZ ddl m!Z!m"Z" ddl#m$Z$m%Z% ddl&m'Z'm(Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/ d dl0Z0d dl1Z1ddl	m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8 ddl3m5Z5 ddl9m:Z;m<Z= ddl9m>Z>m?Z?m@Z@mAZA daBdaC G d de5jD                  ZD G d de5jE                  ZE G d d          ZF G d d ejG                  ZH G d! d"          ZIdS )#    N)AnyOptionalUnion   )BaseApiClient)get_base_url)ReplayApiClient)AsyncBatchesBatches)AsyncCachesCaches)
AsyncChatsChats)AsyncFileSearchStoresFileSearchStores)
AsyncFilesFiles)	AsyncLive)AsyncModelsModels)AsyncOperations
Operations)AsyncTokensTokens)AsyncTuningsTunings)HttpOptionsHttpOptionsDictHttpRetryOptions)has_aiohttp)_common)AsyncGeminiNextGenAPIClientDEFAULT_MAX_RETRIESGeminiNextGenAPIClient)_interactions)AsyncInteractionsResourceInteractionsResource)WebhooksResourceAsyncWebhooksResourceAgentsResourceAsyncAgentsResourceFc                   j    e Zd ZdZdefdZdefdZdedz  fdZ	dedz  fdZ
deeef         fd	ZdS )
"AsyncGeminiNextGenAPIClientAdapter*Adapter for the Gemini NextGen API Client.
api_clientc                     || _         d S N_api_clientselfr/   s     W/home/wildlama/visual-decline/.venv/lib/python3.11/site-packages/google/genai/client.py__init__z+AsyncGeminiNextGenAPIClientAdapter.__init__7       !D    returnc                     | j         j        pdS NFr3   vertexair5   s    r6   is_vertex_aiz/AsyncGeminiNextGenAPIClientAdapter.is_vertex_ai:       $--r9   Nc                     | j         j        S r1   r3   projectr?   s    r6   get_projectz.AsyncGeminiNextGenAPIClientAdapter.get_project=       ##r9   c                     | j         j        S r1   r3   locationr?   s    r6   get_locationz/AsyncGeminiNextGenAPIClientAdapter.get_location@       $$r9   c                    K   | j         j        rd| j         j        iS | j                                          d {V }dd| i}| j         j        x}r|j        r
|j        |d<   |S Nzx-goog-api-keyAuthorizationzBearer zx-goog-user-project)r3   api_key_async_access_token_credentialsquota_project_idr5   access_tokenheaderscredss       r6   async_get_auth_headersz9AsyncGeminiNextGenAPIClientAdapter.async_get_auth_headersC   s       : 0 899)==????????L///G  --u @		 @).)?%&Nr9   )__name__
__module____qualname____doc__r   r7   boolr@   strrE   rJ   dictrW    r9   r6   r-   r-   5   s        22" " " " ".D . . . .$3: $ $ $ $%C$J % % % %
DcN 
 
 
 
 
 
r9   r-   c                   j    e Zd ZdZdefdZdefdZdedz  fdZ	dedz  fdZ
deeef         fd	ZdS )
GeminiNextGenAPIClientAdapterr.   r/   c                     || _         d S r1   r2   r4   s     r6   r7   z&GeminiNextGenAPIClientAdapter.__init__R   r8   r9   r:   c                     | j         j        pdS r<   r=   r?   s    r6   r@   z*GeminiNextGenAPIClientAdapter.is_vertex_aiU   rA   r9   Nc                     | j         j        S r1   rC   r?   s    r6   rE   z)GeminiNextGenAPIClientAdapter.get_projectX   rF   r9   c                     | j         j        S r1   rH   r?   s    r6   rJ   z*GeminiNextGenAPIClientAdapter.get_location[   rK   r9   c                     | j         j        rd| j         j        iS | j                                         }dd| i}| j         j        x}r|j        r
|j        |d<   |S rM   )r3   rO   _access_tokenrQ   rR   rS   s       r6   get_auth_headersz.GeminiNextGenAPIClientAdapter.get_auth_headers^   s     : 0 899#1133L///G  --u @		 @).)?%&Nr9   )rX   rY   rZ   r[   r   r7   r\   r@   r]   rE   rJ   r^   rh   r_   r9   r6   ra   ra   P   s        22" " " " ".D . . . .$3: $ $ $ $%C$J % % % %
S#X 
 
 
 
 
 
r9   ra   c                      e Zd ZdZdefdZedefd            Zede	fd            Z
edefd            Zedefd            Zedefd	            Zedefd
            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Z ede!fd            Z"ede#fd            Z$ddZ%ddZ&de'de'ddfdZ(ddZ)dS )AsyncClientz7Client for making asynchronous (non-blocking) requests.r/   c                    || _         t          | j                   | _        t          | j                   | _        t          | j                   | _        t          | j                   | _        t          | j                   | _
        t          | j                   | _        t          | j                   | _        t          | j                   | _        t#          | j                   | _        d | _        d S r1   )r3   r   _modelsr   _tuningsr   _cachesr
   _batchesr   _filesr   _file_search_storesr   _liver   _tokensr   _operations_nextgen_client_instancer4   s     r6   r7   zAsyncClient.__init__n   s    !Dt/00DL !122DMt/00DL !122DMT-..DK4T5EFFD4+,,DJt/00DL&t'788DKOD!!!r9   r:   c                    | j         | j         S | j        j        }|j        rt	          j        dt          d           |j        }|?|j        |j	        |j
        |j        |j        t	          j        dt          d           | j        j        }| j        j        j        pi }d|v }t          r|st	          j        dt          d           ||j        |j        }n
t"          dz   }t%          |j        | j        j        |j        |j        ||j        r
|j        dz  nd |t1          | j                  	          | _         | j         }| j        j        r)d
|_        | j        j        |_        | j        j        |_        | j         S )N>extra_body properties are not supported in `.interactions` yet   category
stacklevel?Granular retry options are not supported in `.interactions` yet	transportzCAsync interactions client cannot use aiohttp, fallingback to httpx.r     base_urlrO   api_versiondefault_headershttp_clienttimeoutmax_retriesclient_adapterT)ru   r3   _http_options
extra_bodywarningswarnUserWarningretry_optionsinitial_delay	max_delayexp_basejitterhttp_status_codes_async_httpx_clientasync_client_argsr    attemptsr#   r"   r   rO   r   rU   r   r-   r>   
_is_vertexrD   _vertex_projectrI   _vertex_location)r5   	http_opts
retry_optsr   r   has_custom_transportr   clients           r6   _nextgen_clientzAsyncClient._nextgen_client|   s   $0** .I m
J    (J ,+*('3m
K    	,  (6HNB&*;; / m
O    *"5"A'kk'!+k$?# ()!),5,=G	!D((49$:JKK
% 
% 
%D! *F  :f#/7f $ 0 9f((r9   c                 d    t           sda t          j        dt          d           | j        j        S )NTEInteractions usage is experimental and may change in future versions.r   ry   !_interactions_experimental_warnedr   r   r   r   interactionsr?   s    r6   r   zAsyncClient.interactions   sB     - *.'m
Q   
 ,,r9   c                     | j         j        S r1   r   webhooksr?   s    r6   r   zAsyncClient.webhooks       ((r9   c                 d    t           sda t          j        dt          d           | j        j        S )NT?Agents usage is experimental and may change in future versions.r   ry   _agent_experimental_warnedr   r   r   r   agentsr?   s    r6   r   zAsyncClient.agents   sB     & #' m
K   
 &&r9   c                 4    t          | d          o| j        d uS Nru   hasattrru   r?   s    r6   _has_nextgen_clientzAsyncClient._has_nextgen_client   '     	011 	2%T1r9   c                     | j         S r1   rl   r?   s    r6   modelszAsyncClient.models   
    <r9   c                     | j         S r1   rm   r?   s    r6   tuningszAsyncClient.tunings   
    =r9   c                     | j         S r1   rn   r?   s    r6   cacheszAsyncClient.caches   r   r9   c                     | j         S r1   rq   r?   s    r6   file_search_storeszAsyncClient.file_search_stores       ##r9   c                     | j         S r1   ro   r?   s    r6   batcheszAsyncClient.batches   r   r9   c                 ,    t          | j                  S N)modules)r   r   r?   s    r6   chatszAsyncClient.chats   s    dk****r9   c                     | j         S r1   rp   r?   s    r6   fileszAsyncClient.files   
    ;r9   c                     | j         S r1   )rr   r?   s    r6   livezAsyncClient.live   s
    :r9   c                     | j         S r1   rs   r?   s    r6   auth_tokenszAsyncClient.auth_tokens  r   r9   c                     | j         S r1   rt   r?   s    r6   
operationszAsyncClient.operations      r9   Nc                    K   | j                                          d{V  | j        r!| j                                         d{V  dS dS )a  Closes the async client explicitly.

    However, it doesn't close the sync client, which can be closed using the
    Client.close() method or using the context manager.

    Usage:
    .. code-block:: python

      from google.genai import Client

      async_client = Client(
          vertexai=True, project='my-project-id', location='us-central1'
      ).aio
      response_1 = await async_client.models.generate_content(
          model='gemini-2.0-flash',
          contents='Hello World',
      )
      response_2 = await async_client.models.generate_content(
          model='gemini-2.0-flash',
          contents='Hello World',
      )
      # Close the client to release resources.
      await async_client.aclose()
    N)r3   acloser   r   closer?   s    r6   r   zAsyncClient.aclose
  sq      2 

!
!
#
######## ) &&((((((((((() )r9   c                 
   K   | S r1   r_   r?   s    r6   
__aenter__zAsyncClient.__aenter__(  s      Kr9   argskwargsc                 B   K   ~~|                                   d {V  d S r1   )r   r5   r   r   s      r6   	__aexit__zAsyncClient.__aexit__+  s1      f
++--r9   c                     	 t          j                                        |                                            d S # t          $ r Y d S w xY wr1   )asyncioget_running_loopcreate_taskr   	Exceptionr?   s    r6   __del__zAsyncClient.__del__/  sT      ,,T[[]];;;;;   
dds   8< 
A
	A
r:   N)r:   rj   )*rX   rY   rZ   r[   r   r7   propertyr"   r    AsyncNextGenInteractionsResourcer   r)   r   r+   r   r\   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r_   r9   r6   rj   rj   k   s       ??P P P P P @): @) @) @) 8@)D 	-< 	- 	- 	- 8	- )- ) ) ) 8) 	') 	' 	' 	' 8	' 4    8 k    8 |    8 k    8 $"7 $ $ $ 8$ |    8 +Z + + + 8+ Z    8 I    8 ;    8 /    8) ) ) )<   3 # $         r9   rj   c                       e Zd ZU dZ ej        d           Zee         e	d<    ej        d           Z
ee         e	d<    ej        d           Zee         e	d<   d	S )
DebugConfigzGConfiguration options that change client network behavior when testing.c                  ,    t          j        dd           S )NGOOGLE_GENAI_CLIENT_MODEosgetenvr_   r9   r6   <lambda>zDebugConfig.<lambda>:  s    bi(BDII r9   )default_factoryclient_modec                  ,    t          j        dd           S )NGOOGLE_GENAI_REPLAYS_DIRECTORYr   r_   r9   r6   r   zDebugConfig.<lambda>>  s    bi(H$OO r9   replays_directoryc                  ,    t          j        dd           S )NGOOGLE_GENAI_REPLAY_IDr   r_   r9   r6   r   zDebugConfig.<lambda>B  s    bi(@$GG r9   	replay_idN)rX   rY   rZ   r[   pydanticFieldr   r   r]   __annotations__r   r   r_   r9   r6   r   r   6  s         OO-x~II     +x}    &4X^OO& & &Xc]    ,X^GG  )Xc]     r9   r   c                      e Zd ZdZddddddddddee         dee         dee         deej        j	        j
                 dee         d	ee         d
ee         deeeef                  fdZe	 	 	 	 	 	 	 d%dee         dee         deej        j	        j
                 dee         d	ee         d
ee         dee         defd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Z ede!fd            Z"ede#fd            Z$ede%fd            Z&ede'fd            Z(ede)fd            Z*ede+fd            Z,ede-fd            Z.ede/fd            Z0edefd            Z1d&dZ2d'd Z3d!e4d"e4ddfd#Z5d&d$Z6dS )(Clienta   Client for making synchronous requests.

  Use this client to make a request to the Gemini Developer API or Gemini
  Enterprise Agent Platform (previously Vertex AI API) and then wait for the
  response.

  To initialize the client, provide the required arguments either directly
  or by using environment variables. Gemini API users and Vertex AI users in
  `api_key="your-api-key"` or by defining `GOOGLE_API_KEY="your-api-key"` as an
  environment variable

  Gemini Enterprise Agent Platform API users can provide inputs argument as
  `enterprise=True,
  project="your-project-id", location="us-central1"` or by defining
  `GOOGLE_GENAI_USE_ENTERPRISE=true`, `GOOGLE_CLOUD_PROJECT` and
  `GOOGLE_CLOUD_LOCATION` environment variables.

  Attributes:
    api_key: The `API key <https://ai.google.dev/gemini-api/docs/api-key>`_ to
      use for authentication. Applies to the Gemini Developer API only.
    enterprise (bool): Indicates whether the client should use the Gemini
      Enterprise Agent Platform endpoints (previously Vertex AI API).
      Defaults to False (uses Gemini Developer API endpoints). When
      `enterprise` and `vertexai` are both set, and they have conflicting
      values, a `ValueError` will be raised.
    vertexai (bool): Legacy flag for `enterprise`.
    credentials: The credentials to use for authentication when calling the
      Gemini Enterprise Agent Platform APIs. Credentials can be obtained from
      environment variables and default credentials. For more information, see
      `Set up Application Default Credentials
      <https://cloud.google.com/docs/authentication/provide-credentials-adc>`_.
      Applies to the Vertex AI API only.
    project: The `Google Cloud project ID
      <https://cloud.google.com/vertex-ai/docs/start/cloud-environment>`_ to use
      for quota. Can be obtained from environment variables (for example,
      ``GOOGLE_CLOUD_PROJECT``). Applies to the Vertex AI API only.
      Find your `Google Cloud project ID
      <https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects>`_.
    location: The `location
      <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations>`_
      to send API requests to (for example, ``us-central1``). Can be obtained
      from environment variables. Applies to the Vertex AI API only.
    debug_config: Config settings that control network behavior of the client.
      This is typically used when running test code.
    http_options: Http options to use for the client. These options will be
      applied to all requests made by the client. Example usage: `client =
      genai.Client(http_options=types.HttpOptions(api_version='v1'))`.

  Usage for the Gemini Developer API:

  .. code-block:: python

    from google import genai

    client = genai.Client(api_key='my-api-key')

  Usage for the Gemini Enterprise Agent Platform API:

  .. code-block:: python

    from google import genai

    client = genai.Client(
        enterprise=True, project='my-project-id', location='us-central1'
    )
  N)
enterpriser>   rO   credentialsrD   rI   debug_confighttp_optionsr   r>   rO   r   rD   rI   r   r   c          	      (   |pt                      | _        ||||k    rt          d          ||n|}	t          |t                    rt          di |}t          |	pd|          }
|
r|r|
|_        nt          |
          }|                     |	||||| j        |          | _	        t          | j	                  | _        t          | j	                  | _        t          | j	                  | _        t!          | j	                  | _        t%          | j	                  | _        t)          | j	                  | _        t-          | j	                  | _        t1          | j	                  | _        t5          | j	                  | _        d| _        dS )a@  Initializes the client.

    Args:
       enterprise (bool): Indicates whether the client should use the Gemini
         Enterprise Agent Platform endpoints (previously Vertex AI API).
         Defaults to False (uses Gemini Developer API endpoints). When
         `enterprise` and `vertexai` are both set, and they have conflicting
         values, a `ValueError` will be raised.
       vertexai (bool): Legacy flag for `enterprise`.
       api_key (str): The `API key
         <https://ai.google.dev/gemini-api/docs/api-key>`_ to use for
         authentication. Applies to the Gemini Developer API only.
       credentials (google.auth.credentials.Credentials): The credentials to use
         for authentication when calling the Vertex AI APIs. Credentials can be
         obtained from environment variables and default credentials. For more
         information, see `Set up Application Default Credentials
         <https://cloud.google.com/docs/authentication/provide-credentials-adc>`_.
         Applies to the Vertex AI API only.
       project (str): The `Google Cloud project ID
         <https://cloud.google.com/vertex-ai/docs/start/cloud-environment>`_ to
         use for quota. Can be obtained from environment variables (for example,
         ``GOOGLE_CLOUD_PROJECT``). Applies to the Vertex AI API only.
       location (str): The `location
         <https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations>`_
         to send API requests to (for example, ``us-central1``). Can be obtained
         from environment variables. Applies to the Vertex AI API only.
       debug_config (DebugConfig): Config settings that control network behavior
         of the client. This is typically used when running test code.
       http_options (Union[HttpOptions, HttpOptionsDict]): Http options to use
         for the client.
    NzXenterprise and vertexai flags have conflicting values, please set enterprise value only.F)r   r>   rO   r   rD   rI   r   r   r_   )r   _debug_config
ValueError
isinstancer^   r   r   r   _get_api_clientr3   rj   _aior   rl   r   rm   r   rn   r   rq   r   ro   r   rp   r   rs   r   rt   ru   )r5   r   r>   rO   r   rD   rI   r   r   resolved_vertexair   s              r6   r7   zClient.__init__  s   X &6D("6:;Q;Q$  
 '1&<

(,%% 1 00<00l-6EEH 6	 6 ("H555++"'! ,  D D,--DI$*++DLD,--DM$*++DL/0@AADD,--DM())DK$*++DL!$"233DFJD!!!r9   r:   c                     |r0|j         dv r't          |j         |j        |j        | |||||	  	        S t	          | |||||          S )N)recordreplayauto)	moder   r   r>   rO   r   rD   rI   r   )r>   rO   r   rD   rI   r   )r   r	   r   r   r   r  s          r6   r  zClient._get_api_client  s      0 5  
 ' *(:!#
 
 
 
 !   r9   c                    | j         | j         S | j        j        }|j        rt	          j        dt          d           |j        }|?|j        |j	        |j
        |j        |j        t	          j        dt          d           ||j        |j        }n
t          dz   }t          |j        | j        j        |j        |j        | j        j        |j        r
|j        dz  nd |t-          | j                            | _         | j         }| j        j        r)d|_        | j        j        |_        | j        j        |_        | j         S )	Nrw   rx   ry   r|   r   r~   r   T)ru   r3   r   r   r   r   r   r   r   r   r   r   r   r   r#   r$   r   rO   r   rU   _httpx_clientr   ra   r>   r   rD   r   rI   r   )r5   r   r   r   r   s        r6   r   zClient._nextgen_client  sx   $0** .I m
J    (J ,+*('3m
K    *"5"A'kk'!+k$:# ()!)$2,5,=G	!D((44T5EFF
% 
% 
%D! *F  :f#/7f $ 0 9f((r9   c                 d    t           sda t          j        dt          d           | j        j        S )NTr      ry   r   r?   s    r6   r   zClient.interactions8  sB     - *.'mO   
 ,,r9   c                     | j         j        S r1   r   r?   s    r6   r   zClient.webhooksD  r   r9   c                 d    t           sda t          j        dt          d           | j        j        S )NTr   r  ry   r   r?   s    r6   r   zClient.agentsH  sB     & #' mI   
 &&r9   c                 4    t          | d          o| j        d uS r   r   r?   s    r6   r   zClient._has_nextgen_clientT  r   r9   c                 ,    t          | j                  S r   )r   r   r?   s    r6   r   zClient.chats[  s    %%%%r9   c                     | j         S r1   )r  r?   s    r6   aioz
Client.aio_  s
    9r9   c                     | j         S r1   r   r?   s    r6   r   zClient.modelsc  r   r9   c                     | j         S r1   r   r?   s    r6   r   zClient.tuningsg  r   r9   c                     | j         S r1   r   r?   s    r6   r   zClient.cachesk  r   r9   c                     | j         S r1   r   r?   s    r6   r   zClient.file_search_storeso  r   r9   c                     | j         S r1   r   r?   s    r6   r   zClient.batchess  r   r9   c                     | j         S r1   r   r?   s    r6   r   zClient.filesw  r   r9   c                     | j         S r1   r   r?   s    r6   r   zClient.auth_tokens{  r   r9   c                     | j         S r1   r   r?   s    r6   r   zClient.operations  r   r9   c                     | j         j        pdS )z6Returns whether the client is using the Vertex AI API.Fr=   r?   s    r6   r>   zClient.vertexai  s     $--r9   c                 |    | j                                          | j        r| j                                         dS dS )a  Closes the synchronous client explicitly.

    However, it doesn't close the async client, which can be closed using the
    Client.aio.aclose() method or using the async context manager.

    Usage:
    .. code-block:: python

      from google.genai import Client

      client = Client(
          vertexai=True, project='my-project-id', location='us-central1'
      )
      response_1 = client.models.generate_content(
          model='gemini-2.0-flash',
          contents='Hello World',
      )
      response_2 = client.models.generate_content(
          model='gemini-2.0-flash',
          contents='Hello World',
      )
      # Close the client to release resources.
      client.close()
    N)r3   r   r   r   r?   s    r6   r   zClient.close  sI    2 	 #
  """""# #r9   c                     | S r1   r_   r?   s    r6   	__enter__zClient.__enter__  s    Kr9   r   r   c                 2    ~~|                                   d S r1   )r   r   s      r6   __exit__zClient.__exit__  s    fJJLLLLLr9   c                 R    	 |                                   d S # t          $ r Y d S w xY wr1   )r   r   r?   s    r6   r   zClient.__del__  s:    
jjlllll   
dds    
&&)NNNNNNNr   )r:   r   )7rX   rY   rZ   r[   r   r\   r]   googleauthr   Credentialsr   r   r   r   r7   staticmethodr   r  r   r$   r   NextGenInteractionsResourcer   r(   r   r*   r   r   r   r   rj   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r>   r   r"  r   r$  r   r_   r9   r6   r   r   F  s       A AL $(!%#CG# $,0DHSK SK SK 4.SK 	SK
 }SK FK3?@SK }SK SK [)SK U;#?@ASK SK SK SKj !%#CG# $,0,0! !!}! FK3?@! }	!
 ! [)! [)! ! ! ! <!F 2)5 2) 2) 2) 82)h 	-7 	- 	- 	- 8	- )( ) ) ) 8) 	'n 	' 	' 	' 8	' 4    8 &U & & & 8& ;    8 f    8 w    8 f    8 $"2 $ $ $ 8$ w    8 U    8 6    8 *    8 . . . . 8.# # # #<   C 3 4         r9   r   )Jr   r   typingr   r   r   google.authr&  r   r3   r   	_base_urlr   _replay_api_clientr	   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   tokensr   r   r   r   r   typesr   r   r   r   httpxr     r!   r%   r"   r#   r$   _interactions.resourcesr&   r   r'   r*  r(   r)   r*   r+   r   r   r-   ra   rj   	BaseModelr   r   r_   r9   r6   <module>r5     sD     				 ' ' ' ' ' ' ' ' ' '      & & & & & & # # # # # # / / / / / / * * * * * * * * ' ' ' ' ' ' ' ' $ $ $ $ $ $ $ $ G G G G G G G G $ $ $ $ $ $ $ $       ' ' ' ' ' ' ' ' 3 3 3 3 3 3 3 3 ' ' ' ' ' ' ' ' * * * * * * * * A A A A A A A A A A   $ $ $ $ $ $       c c c c c c c c c c       X  X  X  X  X  X  X  X q q q q q q q q q q q q$) !"     )Y   6    M$O   6H H H H H H H HV    ($    k k k k k k k k k kr9   