o
    iU                     @  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 dd	lmZ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%m&Z& erddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z;m<Z< ddl=m>Z>m?Z? g dZ@G dd de%ZAG dd de&ZBG dd dZCG dd dZDG dd  d ZEG d!d" d"ZFeAZGeBZHdS )#    )annotationsN)TYPE_CHECKINGAnyMapping)Selfoverride   )_exceptionsQuerystring)OmitTimeoutNotGiven	TransportProxiesTypesRequestOptions	not_given)is_givenget_async_library)cached_property)__version__)StreamAsyncStream)	GroqErrorAPIStatusError)DEFAULT_MAX_RETRIESSyncAPIClientAsyncAPIClient)chataudiofilesmodelsbatches
embeddings)Files
AsyncFiles)ModelsAsyncModels)BatchesAsyncBatches)Chat	AsyncChat)
EmbeddingsAsyncEmbeddings)Audio
AsyncAudio)r   r   r   r   Groq	AsyncGroqClientAsyncClientc                        e Zd ZU ded< ddeeddddddK fddZedLddZedMddZ	edNd d!Z
edOd#d$ZedPd&d'ZedQd)d*ZedRd,d-ZedSd/d0ZeedTd2d3ZeedUd5d6ZeedV fd8d9Zddededdddi d:
dWdAdBZeZedXdIdJZ  ZS )Yr0   strapi_keyNFr6   base_urltimeoutmax_retriesdefault_headersdefault_queryhttp_client_strict_response_validation
str | Noner8   str | httpx.URL | Noner9   !float | Timeout | None | NotGivenr:   intr;   Mapping[str, str] | Noner<   Mapping[str, object] | Noner=   httpx.Client | Noner>   boolreturnNonec          	   
     j   |du r
t jd}|du rtd|| _|du rt jd}|du r%d}t jt|||||||d dS )zConstruct a new synchronous Groq client instance.

        This automatically infers the `api_key` argument from the `GROQ_API_KEY` environment variable if it is not provided.
        NGROQ_API_KEYThe api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variableGROQ_BASE_URLhttps://api.groq.comversionr8   r:   r9   r=   Zcustom_headersZcustom_queryr>   osenvirongetr   r6   super__init__r   	selfr6   r8   r9   r:   r;   r<   r=   r>   	__class__ F/home/kim/smarthome/.venv/lib/python3.10/site-packages/groq/_client.pyrU   1   *   
zGroq.__init__r*   c                 C     ddl m} || S )Nr   )r*   )resources.chatr*   )rW   r*   rZ   rZ   r[   r   d      z	Groq.chatr,   c                 C  r]   )Nr   )r,   )resources.embeddingsr,   )rW   r,   rZ   rZ   r[   r#   j   r_   zGroq.embeddingsr.   c                 C  r]   )Nr   )r.   )resources.audior.   )rW   r.   rZ   rZ   r[   r   p   r_   z
Groq.audior&   c                 C  r]   )Nr   )r&   )resources.modelsr&   )rW   r&   rZ   rZ   r[   r!   v   r_   zGroq.modelsr(   c                 C  r]   )Nr   )r(   )resources.batchesr(   )rW   r(   rZ   rZ   r[   r"   |   r_   zGroq.batchesr$   c                 C  r]   )Nr   )r$   )resources.filesr$   )rW   r$   rZ   rZ   r[   r       r_   z
Groq.filesGroqWithRawResponsec                 C     t | S N)re   rW   rZ   rZ   r[   with_raw_response      zGroq.with_raw_responseGroqWithStreamedResponsec                 C  rf   rg   )rk   rh   rZ   rZ   r[   with_streaming_response   rj   zGroq.with_streaming_responser   c                 C  
   t ddS Ncomma)Zarray_formatr
   rh   rZ   rZ   r[   qs      
zGroq.qsdict[str, str]c                 C     | j }dd| iS NAuthorizationzBearer r6   rW   r6   rZ   rZ   r[   auth_headers      zGroq.auth_headersdict[str, str | Omit]c                   s   i t  jddi| jS )NX-Stainless-Asyncfalse)rT   r;   _custom_headersrh   rX   rZ   r[   r;      s   zGroq.default_headers
r6   r8   r9   r=   r:   r;   set_default_headersr<   set_default_query_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t|trX| j	n||t
|r`|n| j||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)r6   r8   r9   r=   r:   r;   r<   rZ   
ValueErrorr}   Z_custom_query_clientrY   r6   r8   
isinstancer   r9   r   r:   rW   r6   r8   r9   r=   r:   r;   r   r<   r   r   headersparamsrZ   rZ   r[   copy   4   
z	Groq.copy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   rW   r   r   r   rZ   rZ   r[   _make_status_error   "   







zGroq._make_status_error)r6   r?   r8   r@   r9   rA   r:   rB   r;   rC   r<   rD   r=   rE   r>   rF   rG   rH   )rG   r*   )rG   r,   )rG   r.   )rG   r&   )rG   r(   )rG   r$   )rG   re   )rG   rk   rG   r   rG   rr   rG   rz   )r6   r?   r8   r@   r9   rA   r=   rE   r:   r   r;   rC   r   rC   r<   rD   r   rD   r   r   rG   r   r   r5   r   r   r   r   rG   r   __name__
__module____qualname____annotations__r   r   rU   r   r   r#   r   r!   r"   r    ri   rl   propertyr   rp   rx   r;   r   Zwith_optionsr   __classcell__rZ   rZ   rX   r[   r0   -   d   
 	3
1r0   c                      r4   )Yr1   r5   r6   NFr7   r?   r8   r@   r9   rA   r:   rB   r;   rC   r<   rD   r=   httpx.AsyncClient | Noner>   rF   rG   rH   c          	   
     rI   )zConstruct a new async AsyncGroq client instance.

        This automatically infers the `api_key` argument from the `GROQ_API_KEY` environment variable if it is not provided.
        NrJ   rK   rL   rM   rN   rP   rV   rX   rZ   r[   rU      r\   zAsyncGroq.__init__r+   c                 C  r]   )Nr   )r+   )r^   r+   )rW   r+   rZ   rZ   r[   r   0  r_   zAsyncGroq.chatr-   c                 C  r]   )Nr   )r-   )r`   r-   )rW   r-   rZ   rZ   r[   r#   6  r_   zAsyncGroq.embeddingsr/   c                 C  r]   )Nr   )r/   )ra   r/   )rW   r/   rZ   rZ   r[   r   <  r_   zAsyncGroq.audior'   c                 C  r]   )Nr   )r'   )rb   r'   )rW   r'   rZ   rZ   r[   r!   B  r_   zAsyncGroq.modelsr)   c                 C  r]   )Nr   )r)   )rc   r)   )rW   r)   rZ   rZ   r[   r"   H  r_   zAsyncGroq.batchesr%   c                 C  r]   )Nr   )r%   )rd   r%   )rW   r%   rZ   rZ   r[   r    N  r_   zAsyncGroq.filesAsyncGroqWithRawResponsec                 C  rf   rg   )r   rh   rZ   rZ   r[   ri   T  rj   zAsyncGroq.with_raw_responseAsyncGroqWithStreamedResponsec                 C  rf   rg   )r   rh   rZ   rZ   r[   rl   X  rj   z!AsyncGroq.with_streaming_responser   c                 C  rm   rn   r
   rh   rZ   rZ   r[   rp   \  rq   zAsyncGroq.qsrr   c                 C  rs   rt   rv   rw   rZ   rZ   r[   rx   a  ry   zAsyncGroq.auth_headersrz   c                   s"   i t  jddt  i| jS )Nr{   zasync:)rT   r;   r   r}   rh   rX   rZ   r[   r;   g  s   zAsyncGroq.default_headersr~   r   r   r   r   r   r   c       
      
   C  r   r   r   r   rZ   rZ   r[   r   p  r   zAsyncGroq.copyr   r   r   r   r   r   c                C  r   r   r   r   rZ   rZ   r[   r     r   zAsyncGroq._make_status_error)r6   r?   r8   r@   r9   rA   r:   rB   r;   rC   r<   rD   r=   r   r>   rF   rG   rH   )rG   r+   )rG   r-   )rG   r/   )rG   r'   )rG   r)   )rG   r%   )rG   r   )rG   r   r   r   r   )r6   r?   r8   r@   r9   rA   r=   r   r:   r   r;   rC   r   rC   r<   rD   r   rD   r   r   rG   r   r   r   rZ   rZ   rX   r[   r1      r   r1   c                   @  t   e Zd ZU ded< dddZedd	d
ZedddZedddZedddZ	ed ddZ
ed!ddZdS )"re   r0   r   clientrG   rH   c                 C  
   || _ d S rg   r   rW   r   rZ   rZ   r[   rU        
zGroqWithRawResponse.__init__chat.ChatWithRawResponsec                 C     ddl m} || jjS )Nr   )ChatWithRawResponse)r^   r   r   r   )rW   r   rZ   rZ   r[   r        zGroqWithRawResponse.chat$embeddings.EmbeddingsWithRawResponsec                 C  r   )Nr   )EmbeddingsWithRawResponse)r`   r   r   r#   )rW   r   rZ   rZ   r[   r#     r   zGroqWithRawResponse.embeddingsaudio.AudioWithRawResponsec                 C  r   )Nr   )AudioWithRawResponse)ra   r   r   r   )rW   r   rZ   rZ   r[   r     r   zGroqWithRawResponse.audiomodels.ModelsWithRawResponsec                 C  r   )Nr   )ModelsWithRawResponse)rb   r   r   r!   )rW   r   rZ   rZ   r[   r!     r   zGroqWithRawResponse.modelsbatches.BatchesWithRawResponsec                 C  r   )Nr   )BatchesWithRawResponse)rc   r   r   r"   )rW   r   rZ   rZ   r[   r"     r   zGroqWithRawResponse.batchesfiles.FilesWithRawResponsec                 C  r   )Nr   )FilesWithRawResponse)rd   r   r   r    )rW   r   rZ   rZ   r[   r      r   zGroqWithRawResponse.filesNr   r0   rG   rH   )rG   r   )rG   r   )rG   r   )rG   r   )rG   r   )rG   r   r   r   r   r   rU   r   r   r#   r   r!   r"   r    rZ   rZ   rZ   r[   re        
 
re   c                   @  r   )"r   r1   r   r   rG   rH   c                 C  r   rg   r   r   rZ   rZ   r[   rU     r   z!AsyncGroqWithRawResponse.__init__chat.AsyncChatWithRawResponsec                 C  r   )Nr   )AsyncChatWithRawResponse)r^   r   r   r   )rW   r   rZ   rZ   r[   r     r   zAsyncGroqWithRawResponse.chat)embeddings.AsyncEmbeddingsWithRawResponsec                 C  r   )Nr   )AsyncEmbeddingsWithRawResponse)r`   r   r   r#   )rW   r   rZ   rZ   r[   r#     r   z#AsyncGroqWithRawResponse.embeddingsaudio.AsyncAudioWithRawResponsec                 C  r   )Nr   )AsyncAudioWithRawResponse)ra   r   r   r   )rW   r   rZ   rZ   r[   r     r   zAsyncGroqWithRawResponse.audio!models.AsyncModelsWithRawResponsec                 C  r   )Nr   )AsyncModelsWithRawResponse)rb   r   r   r!   )rW   r   rZ   rZ   r[   r!     r   zAsyncGroqWithRawResponse.models#batches.AsyncBatchesWithRawResponsec                 C  r   )Nr   )AsyncBatchesWithRawResponse)rc   r   r   r"   )rW   r   rZ   rZ   r[   r"     r   z AsyncGroqWithRawResponse.batchesfiles.AsyncFilesWithRawResponsec                 C  r   )Nr   )AsyncFilesWithRawResponse)rd   r   r   r    )rW   r   rZ   rZ   r[   r      r   zAsyncGroqWithRawResponse.filesNr   r1   rG   rH   )rG   r   )rG   r   )rG   r   )rG   r   )rG   r   )rG   r   r   rZ   rZ   rZ   r[   r     r   r   c                   @  r   )"rk   r0   r   r   rG   rH   c                 C  r   rg   r   r   rZ   rZ   r[   rU     r   z!GroqWithStreamedResponse.__init__chat.ChatWithStreamingResponsec                 C  r   )Nr   )ChatWithStreamingResponse)r^   r   r   r   )rW   r   rZ   rZ   r[   r   !  r   zGroqWithStreamedResponse.chat*embeddings.EmbeddingsWithStreamingResponsec                 C  r   )Nr   )EmbeddingsWithStreamingResponse)r`   r   r   r#   )rW   r   rZ   rZ   r[   r#   '  r   z#GroqWithStreamedResponse.embeddings audio.AudioWithStreamingResponsec                 C  r   )Nr   )AudioWithStreamingResponse)ra   r   r   r   )rW   r   rZ   rZ   r[   r   -  r   zGroqWithStreamedResponse.audio"models.ModelsWithStreamingResponsec                 C  r   )Nr   )ModelsWithStreamingResponse)rb   r   r   r!   )rW   r   rZ   rZ   r[   r!   3  r   zGroqWithStreamedResponse.models$batches.BatchesWithStreamingResponsec                 C  r   )Nr   )BatchesWithStreamingResponse)rc   r   r   r"   )rW   r   rZ   rZ   r[   r"   9  r   z GroqWithStreamedResponse.batches files.FilesWithStreamingResponsec                 C  r   )Nr   )FilesWithStreamingResponse)rd   r   r   r    )rW   r   rZ   rZ   r[   r    ?  r   zGroqWithStreamedResponse.filesNr   )rG   r   )rG   r   )rG   r   )rG   r   )rG   r   )rG   r   r   rZ   rZ   rZ   r[   rk     r   rk   c                   @  r   )"r   r1   r   r   rG   rH   c                 C  r   rg   r   r   rZ   rZ   r[   rU   I  r   z&AsyncGroqWithStreamedResponse.__init__#chat.AsyncChatWithStreamingResponsec                 C  r   )Nr   )AsyncChatWithStreamingResponse)r^   r   r   r   )rW   r   rZ   rZ   r[   r   L  r   z"AsyncGroqWithStreamedResponse.chat/embeddings.AsyncEmbeddingsWithStreamingResponsec                 C  r   )Nr   )$AsyncEmbeddingsWithStreamingResponse)r`   r   r   r#   )rW   r   rZ   rZ   r[   r#   R  r   z(AsyncGroqWithStreamedResponse.embeddings%audio.AsyncAudioWithStreamingResponsec                 C  r   )Nr   )AsyncAudioWithStreamingResponse)ra   r   r   r   )rW   r   rZ   rZ   r[   r   X  r   z#AsyncGroqWithStreamedResponse.audio'models.AsyncModelsWithStreamingResponsec                 C  r   )Nr   ) AsyncModelsWithStreamingResponse)rb   r   r   r!   )rW   r   rZ   rZ   r[   r!   ^  r   z$AsyncGroqWithStreamedResponse.models)batches.AsyncBatchesWithStreamingResponsec                 C  r   )Nr   )!AsyncBatchesWithStreamingResponse)rc   r   r   r"   )rW   r   rZ   rZ   r[   r"   d  r   z%AsyncGroqWithStreamedResponse.batches%files.AsyncFilesWithStreamingResponsec                 C  r   )Nr   )AsyncFilesWithStreamingResponse)rd   r   r   r    )rW   r   rZ   rZ   r[   r    j  r   z#AsyncGroqWithStreamedResponse.filesNr   )rG   r   )rG   r   )rG   r   )rG   r   )rG   r   )rG   r   r   rZ   rZ   rZ   r[   r   F  r   r   )I
__future__r   rQ   typingr   r   r   Ztyping_extensionsr   r   Zhttpx r	   Z_qsr   _typesr   r   r   r   r   r   r   Z_utilsr   r   Z_compatr   _versionr   Z
_streamingr   r   r   r   Z_base_clientr   r   r   	resourcesr   r   r    r!   r"   r#   rd   r$   r%   rb   r&   r'   rc   r(   r)   Zresources.chat.chatr*   r+   r`   r,   r-   Zresources.audio.audior.   r/   __all__r0   r1   re   r   rk   r   r2   r3   rZ   rZ   rZ   r[   <module>   sB   $	  M M++++