o
    itR                     @  s|  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rddl+m,Z, ddl-m.Z.m/Z/ g dZ0G dd de&Z1G dd de'Z2G dd dZ3G dd dZ4G dd dZ5G dd dZ6e1Z7e2Z8dS )     )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

dK fddZedLddZedMd!d"Z	edNd$d%Z
eedOd'd(ZeedPd*d+ZeedQ fd-d.ZedRd2d3ZedSd6d7Zdddededddddi d8dTd?d@ZeZdUdAdBZedVdIdJZ  ZS )Wr#   
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_validationr0   str | httpx.URL | Noner1   !float | Timeout | None | NotGivenr2   intr3   Mapping[str, str] | Noner4   Mapping[str, object] | Noner5   httpx.Client | Noner6   boolreturnNonec       
      
     x   |du r
t jd}|| _|du rd}|| _|du r t jd}|du r&d}|	| _t jt|||||||
d t	| _
dS )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versionr0   r2   r1   r5   custom_headerscustom_queryr6   )osenvirongetr)   r+   r-   super__init__r   r   _default_stream_clsselfr)   r+   r0   r1   r2   r3   r4   r5   r-   r6   	__class__ Z/home/livre-enfant/venv/lib/python3.10/site-packages/google/genai/_interactions/_client.pyrL   I   ,   
zGeminiNextGenAPIClient.__init__r!   c                 C     ddl m} || S )Nr   )r!   )resources.interactionsr!   )rO   r!   rR   rR   rS   r          z#GeminiNextGenAPIClient.interactions%GeminiNextGenAPIClientWithRawResponsec                 C     t | S N)rX   rO   rR   rR   rS   with_raw_response      z(GeminiNextGenAPIClient.with_raw_response*GeminiNextGenAPIClientWithStreamedResponsec                 C  rY   rZ   )r^   r[   rR   rR   rS   with_streaming_response   r]   z.GeminiNextGenAPIClient.with_streaming_responser   c                 C  
   t ddS Ncomma)array_formatr
   r[   rR   rR   rS   qs      
zGeminiNextGenAPIClient.qsdict[str, str]c                 C     | j }|d u r	i S d|iS Nx-goog-api-keyr)   rO   r)   rR   rR   rS   auth_headers      z#GeminiNextGenAPIClient.auth_headersdict[str, str | Omit]c                      i t  j| jS rZ   rK   r3   _custom_headersr[   rP   rR   rS   r3      
   z&GeminiNextGenAPIClient.default_headersheadersr   rF   c                 C  b   | ds| dst| dtrd S | jr| drd S | ds+t| dtr-d S tdNAuthorizationri   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"rJ   
isinstancer   r)   	TypeErrorrO   rs   rF   rR   rR   rS   _validate_headers      $z(GeminiNextGenAPIClient._validate_headersoptionsr   c                 C  sZ   | j r| j  s
|S |jpi }|dp|d}|r|S | j  }|r+i |||_|S Nrv   ri   )r-   is_vertex_airs   rJ   get_auth_headersrO   r}   rs   has_authadapted_headersrR   rR   rS   _prepare_options   s   

z'GeminiNextGenAPIClient._prepare_optionsr)   r+   r0   r1   r5   r2   r3   set_default_headersr4   set_default_queryr-   _extra_kwargsint | NotGivenr   r   r   Mapping[str, Any]r   c                C     |dur|durt d|	dur|
durt d| j}|dur&i ||}n|dur,|}| j}|	dur:i ||	}n|
dur@|
}|pD| j}| jd|pL| j|pP| j|pT| jt|t	r\| j
n||t|rd|n| j||| jpl|d	|S z~
        Create a new client instance re-using the same options given to the current client with optional overriding.
        NzPThe `default_headers` and `set_default_headers` arguments are mutually exclusivezLThe `default_query` and `set_default_query` arguments are mutually exclusive)	r)   r+   r0   r1   r5   r2   r3   r4   r-   rR   
ValueErrorrq   _custom_query_clientrQ   r)   r+   r0   rx   r   r1   r   r2   r-   rO   r)   r+   r0   r1   r5   r2   r3   r   r4   r   r-   r   rs   paramsrR   rR   rS   copy   8   

zGeminiNextGenAPIClient.copyc                 C     | j S rZ   r+   r[   rR   rR   rS   _get_api_version_path_param      z2GeminiNextGenAPIClient._get_api_version_path_paramerr_msgbodyobjectresponsehttpx.Responser   c                C     |j dkrtj|||dS |j dkrtj|||dS |j dkr'tj|||dS |j dkr4tj|||dS |j dkrAtj|||dS |j dkrNtj|||dS |j dkr[tj|||dS |j d	krhtj	|||dS t
|||dS 
Ni  )r   r   i  i  i  i  i  i  i  status_coder	   BadRequestErrorAuthenticationErrorPermissionDeniedErrorNotFoundErrorConflictErrorUnprocessableEntityErrorRateLimitErrorInternalServerErrorr   rO   r   r   r   rR   rR   rS   _make_status_error   "   







z)GeminiNextGenAPIClient._make_status_error)r)   r(   r+   r(   r0   r7   r1   r8   r2   r9   r3   r:   r4   r;   r5   r<   r-   r,   r6   r=   r>   r?   )r>   r!   )r>   rX   )r>   r^   r>   r   r>   rf   r>   rn   rs   r   rF   r   r>   r?   r}   r   r>   r   )r)   r(   r+   r(   r0   r7   r1   r8   r5   r<   r2   r   r3   r:   r   r:   r4   r;   r   r;   r-   r,   r   r   r>   r   r>   r*   r   r*   r   r   r   r   r>   r   __name__
__module____qualname____annotations__r   r   rL   r   r    r\   r_   propertyr   rd   rl   r3   r{   r   r   with_optionsr   r   __classcell__rR   rR   rP   rS   r#   C   f   
 	95
r#   c                      r'   )Wr$   r(   r)   r*   r+   )AsyncGeminiNextGenAPIClientAdapter | Noner-   Nr.   Fr/   r0   r7   r1   r8   r2   r9   r3   r:   r4   r;   r5   httpx.AsyncClient | Noner6   r=   r>   r?   c       
      
     r@   )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.
        NrA   r.   rB   rC   rD   )rH   rI   rJ   r)   r+   r-   rK   rL   r   r   rM   rN   rP   rR   rS   rL   &  rT   z$AsyncGeminiNextGenAPIClient.__init__r"   c                 C  rU   )Nr   )r"   )rV   r"   )rO   r"   rR   rR   rS   r    _  rW   z(AsyncGeminiNextGenAPIClient.interactions*AsyncGeminiNextGenAPIClientWithRawResponsec                 C  rY   rZ   )r   r[   rR   rR   rS   r\   e  r]   z-AsyncGeminiNextGenAPIClient.with_raw_response/AsyncGeminiNextGenAPIClientWithStreamedResponsec                 C  rY   rZ   )r   r[   rR   rR   rS   r_   i  r]   z3AsyncGeminiNextGenAPIClient.with_streaming_responser   c                 C  r`   ra   r
   r[   rR   rR   rS   rd   m  re   zAsyncGeminiNextGenAPIClient.qsrf   c                 C  rg   rh   rj   rk   rR   rR   rS   rl   r  rm   z(AsyncGeminiNextGenAPIClient.auth_headersrn   c                   ro   rZ   rp   r[   rP   rR   rS   r3   z  rr   z+AsyncGeminiNextGenAPIClient.default_headersrs   r   rF   c                 C  rt   ru   rw   rz   rR   rR   rS   r{     r|   z-AsyncGeminiNextGenAPIClient._validate_headersr}   r   c                   sb   | j r	| j  s|S |jpi }|dp|d}|r|S | j  I d H }|r/i |||_|S r~   )r-   r   rs   rJ   async_get_auth_headersr   rR   rR   rS   r     s   
z,AsyncGeminiNextGenAPIClient._prepare_optionsr   r   r   r   r   r   r   c                C  r   r   r   r   rR   rR   rS   r     r   z AsyncGeminiNextGenAPIClient.copyc                 C  r   rZ   r   r[   rR   rR   rS   r     r   z7AsyncGeminiNextGenAPIClient._get_api_version_path_paramr   r   r   r   r   r   c                C  r   r   r   r   rR   rR   rS   r     r   z.AsyncGeminiNextGenAPIClient._make_status_error)r)   r(   r+   r(   r0   r7   r1   r8   r2   r9   r3   r:   r4   r;   r5   r   r-   r   r6   r=   r>   r?   )r>   r"   )r>   r   )r>   r   r   r   r   r   r   )r)   r(   r+   r(   r0   r7   r1   r8   r5   r   r2   r   r3   r:   r   r:   r4   r;   r   r;   r-   r   r   r   r>   r   r   r   r   rR   rR   rP   rS   r$      r   r$   c                   @  .   e Zd ZU ded< dddZedd	d
ZdS )rX   r#   r   clientr>   r?   c                 C  
   || _ d S rZ   r   rO   r   rR   rR   rS   rL         
z.GeminiNextGenAPIClientWithRawResponse.__init__0interactions.InteractionsResourceWithRawResponsec                 C     ddl m} || jjS )Nr   )#InteractionsResourceWithRawResponse)rV   r   r   r    )rO   r   rR   rR   rS   r         z2GeminiNextGenAPIClientWithRawResponse.interactionsNr   r#   r>   r?   )r>   r   r   r   r   r   rL   r   r    rR   rR   rR   rS   rX     
   
 
rX   c                   @  r   )r   r$   r   r   r>   r?   c                 C  r   rZ   r   r   rR   rR   rS   rL     r   z3AsyncGeminiNextGenAPIClientWithRawResponse.__init__5interactions.AsyncInteractionsResourceWithRawResponsec                 C  r   )Nr   )(AsyncInteractionsResourceWithRawResponse)rV   r   r   r    )rO   r   rR   rR   rS   r      r   z7AsyncGeminiNextGenAPIClientWithRawResponse.interactionsNr   r$   r>   r?   )r>   r   r   rR   rR   rR   rS   r   
  r   r   c                   @  r   )r^   r#   r   r   r>   r?   c                 C  r   rZ   r   r   rR   rR   rS   rL     r   z3GeminiNextGenAPIClientWithStreamedResponse.__init__6interactions.InteractionsResourceWithStreamingResponsec                 C  r   )Nr   ))InteractionsResourceWithStreamingResponse)rV   r   r   r    )rO   r   rR   rR   rS   r      r   z7GeminiNextGenAPIClientWithStreamedResponse.interactionsNr   )r>   r   r   rR   rR   rR   rS   r^     r   r^   c                   @  r   )r   r$   r   r   r>   r?   c                 C  r   rZ   r   r   rR   rR   rS   rL   '  r   z8AsyncGeminiNextGenAPIClientWithStreamedResponse.__init__;interactions.AsyncInteractionsResourceWithStreamingResponsec                 C  r   )Nr   ).AsyncInteractionsResourceWithStreamingResponse)rV   r   r   r    )rO   r   rR   rR   rS   r    *  r   z<AsyncGeminiNextGenAPIClientWithStreamedResponse.interactionsNr   )r>   r   r   rR   rR   rR   rS   r   $  r   r   )9
__future__r   rH   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    rV   r!   r"   __all__r#   r$   rX   r   r^   r   r%   r&   rR   rR   rR   rS   <module>   s<   (
 ^ ^