
    p[itR                       d dl mZ d dlZd dlmZmZmZ d dlmZm	Z	 d dl
Z
ddlmZ ddlmZ ddlmZmZmZmZmZmZmZ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!m"Z" ddlm#Z# ddl$m%Z%m&Z&m'Z' ddl(m)Z)m*Z* erddl+m,Z, ddl-m.Z.m/Z/ g dZ0 G d de&      Z1 G d de'      Z2 G d d      Z3 G d d      Z4 G d d      Z5 G d d      Z6e1Z7e2Z8y)     )annotationsN)TYPE_CHECKINGAnyMapping)Selfoverride   )_exceptionsQuerystring)OmitHeadersTimeoutNotGiven	TransportProxiesTypesRequestOptions	not_given)is_given)cached_property)FinalRequestOptions)__version__)StreamAsyncStream)APIStatusError)DEFAULT_MAX_RETRIESSyncAPIClientAsyncAPIClient)GeminiNextGenAPIClientAdapter"AsyncGeminiNextGenAPIClientAdapter)interactions)InteractionsResourceAsyncInteractionsResource)r   r   r   r   GeminiNextGenAPIClientAsyncGeminiNextGenAPIClientClientAsyncClientc                      e Zd ZU ded<   ded<   ded<   dddeeddddd	d

	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZedd       Zedd       Z	edd       Z
eedd              Zeedd              Zeed fd              Zedd       Zed d       Zdddededddddi d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeZd"dZe	 	 	 	 	 	 	 	 d#d       Z xZS )$r$   
str | Noneapi_keystrapi_version$GeminiNextGenAPIClientAdapter | Noneclient_adapterNv1betaF
r*   r,   base_urltimeoutmax_retriesdefault_headersdefault_queryhttp_clientr.   _strict_response_validationc       
   
        |t         j                  j                  d      }|| _        |d}|| _        |t         j                  j                  d      }|d}|	| _        t        |   t        |||||||
       t        | _
        y)zConstruct a new synchronous GeminiNextGenAPIClient client instance.

        This automatically infers the `api_key` argument from the `GEMINI_API_KEY` environment variable if it is not provided.
        NGEMINI_API_KEYr/   GEMINI_NEXT_GEN_API_BASE_URL)https://generativelanguage.googleapis.comversionr1   r3   r2   r6   custom_headerscustom_queryr7   )osenvirongetr*   r,   r.   super__init__r   r   _default_stream_clsselfr*   r,   r1   r2   r3   r4   r5   r6   r.   r7   	__class__s              [/mnt/data/GridWatch/venv/lib/python3.12/site-packages/google/genai/_interactions/_client.pyrD   zGeminiNextGenAPIClient.__init__I   s    : ?jjnn%56G"K&zz~~&DEHBH,##*&(C 	 		
 $*     c                    ddl m}  ||       S )Nr	   )r"   )resources.interactionsr"   )rG   r"   s     rI   r!   z#GeminiNextGenAPIClient.interactions   s    @#D))rJ   c                    t        |       S N)%GeminiNextGenAPIClientWithRawResponserG   s    rI   with_raw_responsez(GeminiNextGenAPIClient.with_raw_response   s    4T::rJ   c                    t        |       S rN   )*GeminiNextGenAPIClientWithStreamedResponserP   s    rI   with_streaming_responsez.GeminiNextGenAPIClient.with_streaming_response       9$??rJ   c                    t        d      S Ncomma)array_formatr   rP   s    rI   qszGeminiNextGenAPIClient.qs        00rJ   c                *    | j                   }|i S d|iS Nx-goog-api-keyr*   rG   r*   s     rI   auth_headersz#GeminiNextGenAPIClient.auth_headers   "     ,,?I '**rJ   c                4    i t         |   | j                  S rN   rC   r4   _custom_headersrG   rH   s    rI   r4   z&GeminiNextGenAPIClient.default_headers   (    
g%
""
 	
rJ   c                :   |j                  d      s0|j                  d      st        |j                  d      t              ry | j                  r|j                  d      ry |j                  d      st        |j                  d      t              ry t	        d      NAuthorizationr^   z"Could not resolve authentication method. Expected the api_key to be set. Or for the `x-goog-api-key` headers to be explicitly omitted"rB   
isinstancer   r*   	TypeErrorrG   headersr>   s      rI   _validate_headersz(GeminiNextGenAPIClient._validate_headers       ;;'>+=+=o+NR\]k]o]op  ^A  CG  SH<<GKK(89./:n>P>PQa>bdh3i V
 	
rJ   c                   | j                   r| j                   j                         s|S |j                  xs i }|j                  d      xs |j                  d      }|r|S | j                   j	                         }|ri |||_        |S Nrj   r^   )r.   is_vertex_airo   rB   get_auth_headersrG   optionsro   has_authadapted_headerss        rI   _prepare_optionsz'GeminiNextGenAPIClient._prepare_options   s    ""$*=*=*J*J*LN//'R;;/P7;;?O3PN-->>@!GO rJ   r*   r,   r1   r2   r6   r3   r4   set_default_headersr5   set_default_queryr.   _extra_kwargsc                  ||t        d      |	|
t        d      | j                  }|i ||}n||}| j                  }|	i ||	}n|
|
}|xs | j                  } | j                  d|xs | j
                  |xs | j                  |xs | j                  t        |t              r| j                  n||t        |      r|n| j                  ||| j                  xs |d	|S z~
        Create a new client instance re-using the same options given to the current client with optional overriding.
        zPThe `default_headers` and `set_default_headers` arguments are mutually exclusivezLThe `default_query` and `set_default_query` arguments are mutually exclusive)	r*   r,   r1   r2   r6   r3   r4   r5   r.    
ValueErrorre   _custom_query_clientrH   r*   r,   r1   rl   r   r2   r   r3   r.   rG   r*   r,   r1   r2   r6   r3   r4   r|   r5   r}   r.   r~   ro   paramss                  rI   copyzGeminiNextGenAPIClient.copy      & &+>+Jopp$):)Fkll&&&44O4G ,)G##$00-0F*&F!1T\\t~~ 
+t||#7t'7'7.$.w$ADLLw#'/'<$BRBR# ..@.
 
 	
rJ   c                    | j                   S rN   r,   rP   s    rI   _get_api_version_path_paramz2GeminiNextGenAPIClient._get_api_version_path_param       rJ   c                  |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j
                  |||      S |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j                  |||      S |j                   d	k\  rt        j                  |||      S t        |||      S 
Ni  )responsebodyi  i  i  i  i  i  i  status_coder
   BadRequestErrorAuthenticationErrorPermissionDeniedErrorNotFoundErrorConflictErrorUnprocessableEntityErrorRateLimitErrorInternalServerErrorr   rG   err_msgr   r   s       rI   _make_status_errorz)GeminiNextGenAPIClient._make_status_error   0    3&..wPTUU3&227XTXYY3&44WxVZ[[3&,,WxdSS3&,,WxdSS3&77(Y]^^3&--gtTT3&227XTXYYgtDDrJ   )r*   r)   r,   r)   r1   str | httpx.URL | Noner2   !float | Timeout | None | NotGivenr3   intr4   Mapping[str, str] | Noner5   Mapping[str, object] | Noner6   httpx.Client | Noner.   r-   r7   boolreturnNone)r   r"   )r   rO   )r   rS   r   r   r   zdict[str, str]r   zdict[str, str | Omit]ro   r   r>   r   r   r   rw   r   r   r   )r*   r)   r,   r)   r1   r   r2   r   r6   r   r3   int | NotGivenr4   r   r|   r   r5   r   r}   r   r.   r-   r~   Mapping[str, Any]r   r   r   r+   r   r+   r   objectr   zhttpx.Responser   r   __name__
__module____qualname____annotations__r   r   rD   r   r!   rQ   rT   propertyr   rZ   ra   r4   rp   rz   r   with_optionsr   r   __classcell__rH   s   @rI   r$   r$   C   sa   88
 #"*+/5>.4859 ,0?C -2/7* 7*  	7*
 )7* 37* 7* 27* 37* )7* =7*. &*/7*0 
17*r * *
 ; ; @ @ 1  1 +  + 
  
 

 

  ( #"&+/5>+/&/488<599=?C+-1
 1
  	1

 )1
 31
 )1
 $1
 21
 61
 31
 71
 =1
 )1
 
1
j L  EE 	E
 !E 
E ErJ   r$   c                      e Zd ZU ded<   ded<   ded<   dddeeddddd	d

	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZedd       Zedd       Z	edd       Z
eedd              Zeedd              Zeed fd              Zedd       Zed d       Zdddededddddi d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeZd"dZe	 	 	 	 	 	 	 	 d#d       Z xZS )$r%   r)   r*   r+   r,   )AsyncGeminiNextGenAPIClientAdapter | Noner.   Nr/   Fr0   c       
   
        |t         j                  j                  d      }|| _        |d}|| _        |t         j                  j                  d      }|d}|	| _        t        |   t        |||||||
       t        | _
        y)zConstruct a new async AsyncGeminiNextGenAPIClient client instance.

        This automatically infers the `api_key` argument from the `GEMINI_API_KEY` environment variable if it is not provided.
        Nr9   r/   r:   r;   r<   )r@   rA   rB   r*   r,   r.   rC   rD   r   r   rE   rF   s              rI   rD   z$AsyncGeminiNextGenAPIClient.__init__&  s    : ?jjnn%56G"K&zz~~&DEHBH,##*&(C 	 		
 $/ rJ   c                    ddl m}  ||       S )Nr	   )r#   )rL   r#   )rG   r#   s     rI   r!   z(AsyncGeminiNextGenAPIClient.interactions_  s    E(..rJ   c                    t        |       S rN   )*AsyncGeminiNextGenAPIClientWithRawResponserP   s    rI   rQ   z-AsyncGeminiNextGenAPIClient.with_raw_responsee  rU   rJ   c                    t        |       S rN   )/AsyncGeminiNextGenAPIClientWithStreamedResponserP   s    rI   rT   z3AsyncGeminiNextGenAPIClient.with_streaming_responsei  s    >tDDrJ   c                    t        d      S rW   r   rP   s    rI   rZ   zAsyncGeminiNextGenAPIClient.qsm  r[   rJ   c                *    | j                   }|i S d|iS r]   r_   r`   s     rI   ra   z(AsyncGeminiNextGenAPIClient.auth_headersr  rb   rJ   c                4    i t         |   | j                  S rN   rd   rf   s    rI   r4   z+AsyncGeminiNextGenAPIClient.default_headersz  rg   rJ   c                :   |j                  d      s0|j                  d      st        |j                  d      t              ry | j                  r|j                  d      ry |j                  d      st        |j                  d      t              ry t	        d      ri   rk   rn   s      rI   rp   z-AsyncGeminiNextGenAPIClient._validate_headers  rq   rJ   c                0  K   | j                   r| j                   j                         s|S |j                  xs i }|j                  d      xs |j                  d      }|r|S | j                   j	                          d {   }|ri |||_        |S 7 wrs   )r.   rt   ro   rB   async_get_auth_headersrv   s        rI   rz   z,AsyncGeminiNextGenAPIClient._prepare_options  s     ""$*=*=*J*J*LN//'R;;/P7;;?O3PN $ 3 3 J J LL!GO  Ms   A>B BBr{   c                  ||t        d      |	|
t        d      | j                  }|i ||}n||}| j                  }|	i ||	}n|
|
}|xs | j                  } | j                  d|xs | j
                  |xs | j                  |xs | j                  t        |t              r| j                  n||t        |      r|n| j                  ||| j                  xs |d	|S r   r   r   s                  rI   r   z AsyncGeminiNextGenAPIClient.copy  r   rJ   c                    | j                   S rN   r   rP   s    rI   r   z7AsyncGeminiNextGenAPIClient._get_api_version_path_param  r   rJ   c                  |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j
                  |||      S |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j                  |||      S |j                   dk(  rt        j                  |||      S |j                   d	k\  rt        j                  |||      S t        |||      S r   r   r   s       rI   r   z.AsyncGeminiNextGenAPIClient._make_status_error  r   rJ   )r*   r)   r,   r)   r1   r   r2   r   r3   r   r4   r   r5   r   r6   httpx.AsyncClient | Noner.   r   r7   r   r   r   )r   r#   )r   r   )r   r   r   r   r   r   r   )r*   r)   r,   r)   r1   r   r2   r   r6   r   r3   r   r4   r   r|   r   r5   r   r}   r   r.   r   r~   r   r   r   r   r   r   r   s   @rI   r%   r%      se   ==
 #"*+/5>.4859 15DH -2/7/ 7/  	7/
 )7/ 37/ 7/ 27/ 37/ .7/ B7/. &*/7/0 
17/r / /
 @ @ E E 1  1 +  + 
  
 

 

  ( #"&+/5>04&/488<599=DH+-1
 1
  	1

 )1
 31
 .1
 $1
 21
 61
 31
 71
 B1
 )1
 
1
j L  EE 	E
 !E 
E ErJ   r%   c                  2    e Zd ZU ded<   ddZedd       Zy)rO   r$   r   c                    || _         y rN   r   rG   clients     rI   rD   z.GeminiNextGenAPIClientWithRawResponse.__init__   	    rJ   c                F    ddl m}  || j                  j                        S )Nr	   )#InteractionsResourceWithRawResponse)rL   r   r   r!   )rG   r   s     rI   r!   z2GeminiNextGenAPIClientWithRawResponse.interactions  s    O24<<3L3LMMrJ   Nr   r$   r   r   )r   z0interactions.InteractionsResourceWithRawResponser   r   r   r   rD   r   r!   r   rJ   rI   rO   rO     s#    ## N NrJ   rO   c                  2    e Zd ZU ded<   ddZedd       Zy)r   r%   r   c                    || _         y rN   r   r   s     rI   rD   z3AsyncGeminiNextGenAPIClientWithRawResponse.__init__  r   rJ   c                F    ddl m}  || j                  j                        S )Nr	   )(AsyncInteractionsResourceWithRawResponse)rL   r   r   r!   )rG   r   s     rI   r!   z7AsyncGeminiNextGenAPIClientWithRawResponse.interactions  s    T78Q8QRRrJ   Nr   r%   r   r   )r   z5interactions.AsyncInteractionsResourceWithRawResponser   r   rJ   rI   r   r   
  s#    (( S SrJ   r   c                  2    e Zd ZU ded<   ddZedd       Zy)rS   r$   r   c                    || _         y rN   r   r   s     rI   rD   z3GeminiNextGenAPIClientWithStreamedResponse.__init__  r   rJ   c                F    ddl m}  || j                  j                        S )Nr	   ))InteractionsResourceWithStreamingResponse)rL   r   r   r!   )rG   r   s     rI   r!   z7GeminiNextGenAPIClientWithStreamedResponse.interactions  s    U89R9RSSrJ   Nr   )r   z6interactions.InteractionsResourceWithStreamingResponser   r   rJ   rI   rS   rS     s#    ## T TrJ   rS   c                  2    e Zd ZU ded<   ddZedd       Zy)r   r%   r   c                    || _         y rN   r   r   s     rI   rD   z8AsyncGeminiNextGenAPIClientWithStreamedResponse.__init__'  r   rJ   c                F    ddl m}  || j                  j                        S )Nr	   ).AsyncInteractionsResourceWithStreamingResponse)rL   r   r   r!   )rG   r   s     rI   r!   z<AsyncGeminiNextGenAPIClientWithStreamedResponse.interactions*  s    Z=dll>W>WXXrJ   Nr   )r   z;interactions.AsyncInteractionsResourceWithStreamingResponser   r   rJ   rI   r   r   $  s#    (( Y YrJ   r   )9
__future__r   r@   typingr   r   r   typing_extensionsr   r   httpx r
   _qsr   _typesr   r   r   r   r   r   r   r   _utilsr   _compatr   _modelsr   _versionr   
_streamingr   r   r   _base_clientr   r   r   _client_adapterr   r    	resourcesr!   rL   r"   r#   __all__r$   r%   rO   r   rS   r   r&   r'   r   rJ   rI   <module>r      s   $ # 	 . . ,   	 	 	  $ ( ! D ' 
 _'W	ZE] ZEzZE. ZEz
N 
N
S 
S
T 
T
Y 
Y 
 )rJ   