o
    iR                     @  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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/m0Z0 g dZ1G dd de'Z2G dd de(Z3G dd dZ4G dd dZ5G dd dZ6G dd dZ7e2Z8e3Z9dS )     )annotationsN)TYPE_CHECKINGAnyMapping)Selfoverride   )_exceptionsQuerystring)OmitHeadersTimeoutNotGiven	TransportProxiesTypesRequestOptions	not_given)is_givenget_async_library)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_validationr1   str | httpx.URL | Noner2   !float | Timeout | None | NotGivenr3   intr4   Mapping[str, str] | Noner5   Mapping[str, object] | Noner6   httpx.Client | Noner7   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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__ V/home/ubuntu/.local/lib/python3.10/site-packages/google/genai/_interactions/_client.pyrM   I   ,   
zGeminiNextGenAPIClient.__init__r"   c                 C     ddl m} || S )Nr   )r"   )resources.interactionsr"   )rP   r"   rS   rS   rT   r!         z#GeminiNextGenAPIClient.interactions%GeminiNextGenAPIClientWithRawResponsec                 C     t | S N)rY   rP   rS   rS   rT   with_raw_response      z(GeminiNextGenAPIClient.with_raw_response*GeminiNextGenAPIClientWithStreamedResponsec                 C  rZ   r[   )r_   r\   rS   rS   rT   with_streaming_response   r^   z.GeminiNextGenAPIClient.with_streaming_responser   c                 C  
   t ddS Ncomma)array_formatr
   r\   rS   rS   rT   qs      
zGeminiNextGenAPIClient.qsdict[str, str]c                 C     | j }|d u r	i S d|iS Nx-goog-api-keyr*   rP   r*   rS   rS   rT   auth_headers      z#GeminiNextGenAPIClient.auth_headersdict[str, str | Omit]c                   s   i t  jddi| jS )NX-Stainless-Asyncfalse)rL   r4   _custom_headersr\   rQ   rS   rT   r4      s   z&GeminiNextGenAPIClient.default_headersheadersr   rG   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Authorizationrj   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"rK   
isinstancer   r*   	TypeErrorrP   rs   rG   rS   rS   rT   _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   rj   )r.   is_vertex_airs   rK   get_auth_headersrP   r}   rs   has_authadapted_headersrS   rS   rT   _prepare_options   s   

z'GeminiNextGenAPIClient._prepare_optionsr*   r,   r1   r2   r6   r3   r4   set_default_headersr5   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,   r1   r2   r6   r3   r4   r5   r.   rS   
ValueErrorrr   _custom_query_clientrR   r*   r,   r1   rx   r   r2   r   r3   r.   rP   r*   r,   r1   r2   r6   r3   r4   r   r5   r   r.   r   rs   paramsrS   rS   rT   copy   8   

zGeminiNextGenAPIClient.copyc                 C     | j S r[   r,   r\   rS   rS   rT   _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   rP   r   r   r   rS   rS   rT   _make_status_error   "   







z)GeminiNextGenAPIClient._make_status_error)r*   r)   r,   r)   r1   r8   r2   r9   r3   r:   r4   r;   r5   r<   r6   r=   r.   r-   r7   r>   r?   r@   )r?   r"   )r?   rY   )r?   r_   r?   r   r?   rg   r?   ro   rs   r   rG   r   r?   r@   r}   r   r?   r   )r*   r)   r,   r)   r1   r8   r2   r9   r6   r=   r3   r   r4   r;   r   r;   r5   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   rM   r   r!   r]   r`   propertyr   re   rm   r4   r{   r   r   with_optionsr   r   __classcell__rS   rS   rQ   rT   r$   C   f   
 	95
r$   c                      r(   )Wr%   r)   r*   r+   r,   )AsyncGeminiNextGenAPIClientAdapter | Noner.   Nr/   Fr0   r1   r8   r2   r9   r3   r:   r4   r;   r5   r<   r6   httpx.AsyncClient | Noner7   r>   r?   r@   c       
      
     rA   )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.
        NrB   r/   rC   rD   rE   )rI   rJ   rK   r*   r,   r.   rL   rM   r   r   rN   rO   rQ   rS   rT   rM   '  rU   z$AsyncGeminiNextGenAPIClient.__init__r#   c                 C  rV   )Nr   )r#   )rW   r#   )rP   r#   rS   rS   rT   r!   `  rX   z(AsyncGeminiNextGenAPIClient.interactions*AsyncGeminiNextGenAPIClientWithRawResponsec                 C  rZ   r[   )r   r\   rS   rS   rT   r]   f  r^   z-AsyncGeminiNextGenAPIClient.with_raw_response/AsyncGeminiNextGenAPIClientWithStreamedResponsec                 C  rZ   r[   )r   r\   rS   rS   rT   r`   j  r^   z3AsyncGeminiNextGenAPIClient.with_streaming_responser   c                 C  ra   rb   r
   r\   rS   rS   rT   re   n  rf   zAsyncGeminiNextGenAPIClient.qsrg   c                 C  rh   ri   rk   rl   rS   rS   rT   rm   s  rn   z(AsyncGeminiNextGenAPIClient.auth_headersro   c                   s"   i t  jddt  i| jS )Nrp   zasync:)rL   r4   r   rr   r\   rQ   rS   rT   r4   {  s   z+AsyncGeminiNextGenAPIClient.default_headersrs   r   rG   c                 C  rt   ru   rw   rz   rS   rS   rT   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   rK   async_get_auth_headersr   rS   rS   rT   r     s   
z,AsyncGeminiNextGenAPIClient._prepare_optionsr   r   r   r   r   r   r   c                C  r   r   r   r   rS   rS   rT   r     r   z AsyncGeminiNextGenAPIClient.copyc                 C  r   r[   r   r\   rS   rS   rT   r     r   z7AsyncGeminiNextGenAPIClient._get_api_version_path_paramr   r   r   r   r   r   c                C  r   r   r   r   rS   rS   rT   r     r   z.AsyncGeminiNextGenAPIClient._make_status_error)r*   r)   r,   r)   r1   r8   r2   r9   r3   r:   r4   r;   r5   r<   r6   r   r.   r   r7   r>   r?   r@   )r?   r#   )r?   r   )r?   r   r   r   r   r   r   )r*   r)   r,   r)   r1   r8   r2   r9   r6   r   r3   r   r4   r;   r   r;   r5   r<   r   r<   r.   r   r   r   r?   r   r   r   r   rS   rS   rQ   rT   r%   !  r   r%   c                   @  .   e Zd ZU ded< dddZedd	d
ZdS )rY   r$   r   clientr?   r@   c                 C  
   || _ d S r[   r   rP   r   rS   rS   rT   rM        
z.GeminiNextGenAPIClientWithRawResponse.__init__0interactions.InteractionsResourceWithRawResponsec                 C     ddl m} || jjS )Nr   )#InteractionsResourceWithRawResponse)rW   r   r   r!   )rP   r   rS   rS   rT   r!        z2GeminiNextGenAPIClientWithRawResponse.interactionsNr   r$   r?   r@   )r?   r   r   r   r   r   rM   r   r!   rS   rS   rS   rT   rY     
   
 
rY   c                   @  r   )r   r%   r   r   r?   r@   c                 C  r   r[   r   r   rS   rS   rT   rM     r   z3AsyncGeminiNextGenAPIClientWithRawResponse.__init__5interactions.AsyncInteractionsResourceWithRawResponsec                 C  r   )Nr   )(AsyncInteractionsResourceWithRawResponse)rW   r   r   r!   )rP   r   rS   rS   rT   r!     r   z7AsyncGeminiNextGenAPIClientWithRawResponse.interactionsNr   r%   r?   r@   )r?   r   r   rS   rS   rS   rT   r     r   r   c                   @  r   )r_   r$   r   r   r?   r@   c                 C  r   r[   r   r   rS   rS   rT   rM     r   z3GeminiNextGenAPIClientWithStreamedResponse.__init__6interactions.InteractionsResourceWithStreamingResponsec                 C  r   )Nr   ))InteractionsResourceWithStreamingResponse)rW   r   r   r!   )rP   r   rS   rS   rT   r!     r   z7GeminiNextGenAPIClientWithStreamedResponse.interactionsNr   )r?   r   r   rS   rS   rS   rT   r_     r   r_   c                   @  r   )r   r%   r   r   r?   r@   c                 C  r   r[   r   r   rS   rS   rT   rM   )  r   z8AsyncGeminiNextGenAPIClientWithStreamedResponse.__init__;interactions.AsyncInteractionsResourceWithStreamingResponsec                 C  r   )Nr   ).AsyncInteractionsResourceWithStreamingResponse)rW   r   r   r!   )rP   r   rS   rS   rT   r!   ,  r   z<AsyncGeminiNextGenAPIClientWithStreamedResponse.interactionsNr   )r?   r   r   rS   rS   rS   rT   r   &  r   r   ):
__future__r   rI   typingr   r   r   typing_extensionsr   r   httpx r	   _qsr   _typesr   r   r   r   r   r   r   r   _utilsr   r   _compatr   _modelsr   _versionr   
_streamingr   r   r   _base_clientr   r   r   _client_adapterr   r    	resourcesr!   rW   r"   r#   __all__r$   r%   rY   r   r_   r   r&   r'   rS   rS   rS   rT   <module>   s<   (
 _ _