o
    YitR                     @  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_headersZ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__ \/home/kim/smarthome/.venv/lib/python3.10/site-packages/google/genai/_interactions/_client.pyrK   I   ,   
zGeminiNextGenAPIClient.__init__r!   c                 C     ddl m} || S )Nr   )r!   )resources.interactionsr!   )rN   r!   rQ   rQ   rR   r          z#GeminiNextGenAPIClient.interactions%GeminiNextGenAPIClientWithRawResponsec                 C     t | S N)rW   rN   rQ   rQ   rR   with_raw_response      z(GeminiNextGenAPIClient.with_raw_response*GeminiNextGenAPIClientWithStreamedResponsec                 C  rX   rY   )r]   rZ   rQ   rQ   rR   with_streaming_response   r\   z.GeminiNextGenAPIClient.with_streaming_responser   c                 C  
   t ddS Ncomma)Zarray_formatr
   rZ   rQ   rQ   rR   qs      
zGeminiNextGenAPIClient.qsdict[str, str]c                 C     | j }|d u r	i S d|iS Nx-goog-api-keyr)   rN   r)   rQ   rQ   rR   auth_headers      z#GeminiNextGenAPIClient.auth_headersdict[str, str | Omit]c                      i t  j| jS rY   rJ   r3   _custom_headersrZ   rO   rQ   rR   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Authorizationrg   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"rI   
isinstancer   r)   	TypeErrorrN   rq   rF   rQ   rQ   rR   _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 Nrt   rg   )r-   is_vertex_airq   rI   Zget_auth_headersrN   r{   rq   Zhas_authZadapted_headersrQ   rQ   rR   _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-   rQ   
ValueErrorro   Z_custom_query_clientrP   r)   r+   r0   rv   r   r1   r   r2   r-   rN   r)   r+   r0   r1   r5   r2   r3   r   r4   r   r-   r   rq   paramsrQ   rQ   rR   copy   8   

zGeminiNextGenAPIClient.copyc                 C     | j S rY   r+   rZ   rQ   rQ   rR   _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	   ZBadRequestErrorAuthenticationErrorZPermissionDeniedErrorZNotFoundErrorZConflictErrorZUnprocessableEntityErrorZRateLimitErrorZInternalServerErrorr   rN   r   r   r   rQ   rQ   rR   _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>   rW   )r>   r]   r>   r   r>   rd   r>   rl   rq   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   rK   r   r    r[   r^   propertyr   rb   rj   r3   ry   r   r   Zwith_optionsr   r   __classcell__rQ   rQ   rO   rR   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   )rG   rH   rI   r)   r+   r-   rJ   rK   r   r   rL   rM   rO   rQ   rR   rK   &  rS   z$AsyncGeminiNextGenAPIClient.__init__r"   c                 C  rT   )Nr   )r"   )rU   r"   )rN   r"   rQ   rQ   rR   r    _  rV   z(AsyncGeminiNextGenAPIClient.interactions*AsyncGeminiNextGenAPIClientWithRawResponsec                 C  rX   rY   )r   rZ   rQ   rQ   rR   r[   e  r\   z-AsyncGeminiNextGenAPIClient.with_raw_response/AsyncGeminiNextGenAPIClientWithStreamedResponsec                 C  rX   rY   )r   rZ   rQ   rQ   rR   r^   i  r\   z3AsyncGeminiNextGenAPIClient.with_streaming_responser   c                 C  r_   r`   r
   rZ   rQ   rQ   rR   rb   m  rc   zAsyncGeminiNextGenAPIClient.qsrd   c                 C  re   rf   rh   ri   rQ   rQ   rR   rj   r  rk   z(AsyncGeminiNextGenAPIClient.auth_headersrl   c                   rm   rY   rn   rZ   rO   rQ   rR   r3   z  rp   z+AsyncGeminiNextGenAPIClient.default_headersrq   r   rF   c                 C  rr   rs   ru   rx   rQ   rQ   rR   ry     rz   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}   rq   rI   Zasync_get_auth_headersr~   rQ   rQ   rR   r     s   
z,AsyncGeminiNextGenAPIClient._prepare_optionsr   r   r   r   r   r   r   c                C  r   r   r   r   rQ   rQ   rR   r     r   z AsyncGeminiNextGenAPIClient.copyc                 C  r   rY   r   rZ   rQ   rQ   rR   r     r   z7AsyncGeminiNextGenAPIClient._get_api_version_path_paramr   r   r   r   r   r   c                C  r   r   r   r   rQ   rQ   rR   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   rQ   rQ   rO   rR   r$      r   r$   c                   @  .   e Zd ZU ded< dddZedd	d
ZdS )rW   r#   r   clientr>   r?   c                 C  
   || _ d S rY   r   rN   r   rQ   rQ   rR   rK         
z.GeminiNextGenAPIClientWithRawResponse.__init__0interactions.InteractionsResourceWithRawResponsec                 C     ddl m} || jjS )Nr   )#InteractionsResourceWithRawResponse)rU   r   r   r    )rN   r   rQ   rQ   rR   r         z2GeminiNextGenAPIClientWithRawResponse.interactionsNr   r#   r>   r?   )r>   r   r   r   r   r   rK   r   r    rQ   rQ   rQ   rR   rW     
   
 
rW   c                   @  r   )r   r$   r   r   r>   r?   c                 C  r   rY   r   r   rQ   rQ   rR   rK     r   z3AsyncGeminiNextGenAPIClientWithRawResponse.__init__5interactions.AsyncInteractionsResourceWithRawResponsec                 C  r   )Nr   )(AsyncInteractionsResourceWithRawResponse)rU   r   r   r    )rN   r   rQ   rQ   rR   r      r   z7AsyncGeminiNextGenAPIClientWithRawResponse.interactionsNr   r$   r>   r?   )r>   r   r   rQ   rQ   rQ   rR   r   
  r   r   c                   @  r   )r]   r#   r   r   r>   r?   c                 C  r   rY   r   r   rQ   rQ   rR   rK     r   z3GeminiNextGenAPIClientWithStreamedResponse.__init__6interactions.InteractionsResourceWithStreamingResponsec                 C  r   )Nr   ))InteractionsResourceWithStreamingResponse)rU   r   r   r    )rN   r   rQ   rQ   rR   r      r   z7GeminiNextGenAPIClientWithStreamedResponse.interactionsNr   )r>   r   r   rQ   rQ   rQ   rR   r]     r   r]   c                   @  r   )r   r$   r   r   r>   r?   c                 C  r   rY   r   r   rQ   rQ   rR   rK   '  r   z8AsyncGeminiNextGenAPIClientWithStreamedResponse.__init__;interactions.AsyncInteractionsResourceWithStreamingResponsec                 C  r   )Nr   ).AsyncInteractionsResourceWithStreamingResponse)rU   r   r   r    )rN   r   rQ   rQ   rR   r    *  r   z<AsyncGeminiNextGenAPIClientWithStreamedResponse.interactionsNr   )r>   r   r   rQ   rQ   rQ   rR   r   $  r   r   )9
__future__r   rG   typingr   r   r   Ztyping_extensionsr   r   Zhttpx r	   Z_qsr   _typesr   r   r   r   r   r   r   r   Z_utilsr   _compatr   Z_modelsr   _versionr   Z
_streamingr   r   r   Z_base_clientr   r   r   Z_client_adapterr   r   	resourcesr    rU   r!   r"   __all__r#   r$   rW   r   r]   r   r%   r&   rQ   rQ   rQ   rR   <module>   s<   (
 ^ ^