
     `i<Y                       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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!m"Z" ddlm#Z# ddl$m%Z%m&Z&m'Z' er,ddl(m)Z)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8 g dZ9 G d de&          Z: G d de'          Z; G d d          Z< G d d          Z= G d d          Z> G d d           Z?e:Z@e;ZAdS )!    )annotationsN)TYPE_CHECKINGAnyMapping)Selfoverride   )
_constants_exceptionsQuerystring)OmitHeadersTimeoutNotGiven	TransportProxiesTypesRequestOptions	not_given)is_givenget_async_library)cached_property)__version__)StreamAsyncStream)APIStatusError)DEFAULT_MAX_RETRIESSyncAPIClientAsyncAPIClient)betamodelsmessagescompletions)ModelsAsyncModels)Beta	AsyncBeta)CompletionsAsyncCompletions)MessagesAsyncMessages)r   r   r   r   	AnthropicAsyncAnthropicClientAsyncClientc                      e Zd ZU ded<   ded<   ej        Zej        Zdddeeddddd	d@ fdZ	e
dAd            Ze
dBd            Ze
dCd            Ze
dDd            Ze
dEd!            Ze
dFd#            ZeedGd%                        ZeedHd'                        ZedHd(            ZedHd)            ZeedI fd+                        ZedJd/            Zdddededdddi d0dKd7ZeZedLd?            Z xZS )Mr,   
str | Noneapi_key
auth_tokenNF	r2   r3   base_urltimeoutmax_retriesdefault_headersdefault_queryhttp_client_strict_response_validationr5   str | httpx.URL | Noner6   !float | Timeout | None | NotGivenr7   intr8   Mapping[str, str] | Noner9   Mapping[str, object] | Noner:   httpx.Client | Noner;   boolreturnNonec       	   
     f   |t           j                            d          }|| _        |t           j                            d          }|| _        |t           j                            d          }|d}t                                          t          |||||||	           t          | _	        dS )a#  Construct a new synchronous Anthropic client instance.

        This automatically infers the following arguments from their corresponding environment variables if they are not provided:
        - `api_key` from `ANTHROPIC_API_KEY`
        - `auth_token` from `ANTHROPIC_AUTH_TOKEN`
        NANTHROPIC_API_KEYANTHROPIC_AUTH_TOKENANTHROPIC_BASE_URLhttps://api.anthropic.comversionr5   r7   r6   r:   custom_headerscustom_queryr;   )
osenvirongetr2   r3   super__init__r   r   _default_stream_clsselfr2   r3   r5   r6   r7   r8   r9   r:   r;   	__class__s             e/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/anthropic/_client.pyrR   zAnthropic.__init__>   s    < ?jnn%899G(>??J$z~~&:;;H3H##*&(C 	 		
 		
 		
 $*       r(   c                $    ddl m}  ||           S )Nr	   )r(   )resources.completionsr(   )rU   r(   s     rW   r#   zAnthropic.completionsv   s$    666666{4   rX   r*   c                $    ddl m}  ||           S )Nr	   )r*   )resources.messagesr*   )rU   r*   s     rW   r"   zAnthropic.messages|   s"    000000x~~rX   r$   c                $    ddl m}  ||           S )Nr	   )r$   )resources.modelsr$   )rU   r$   s     rW   r!   zAnthropic.models   s"    ,,,,,,vd||rX   r&   c                $    ddl m}  ||           S )Nr	   )r&   )resources.betar&   )rU   r&   s     rW   r    zAnthropic.beta   s"    ((((((tDzzrX   AnthropicWithRawResponsec                     t          |           S N)ra   rU   s    rW   with_raw_responsezAnthropic.with_raw_response   s    '---rX   AnthropicWithStreamedResponsec                     t          |           S rc   )rf   rd   s    rW   with_streaming_responsez!Anthropic.with_streaming_response       ,T222rX   r   c                "    t          d          S Ncomma)array_formatr   rd   s    rW   qszAnthropic.qs        0000rX   dict[str, str]c                "    i | j         | j        S rc   _api_key_auth_bearer_authrd   s    rW   auth_headerszAnthropic.auth_headers        ;$$:(9::rX   c                     | j         }|i S d|iS N	X-Api-Keyr2   rU   r2   s     rW   rs   zAnthropic._api_key_auth       ,?IW%%rX   c                &    | j         }|i S dd| iS NAuthorizationzBearer r3   rU   r3   s     rW   rt   zAnthropic._bearer_auth   (    _
I!7:!7!788rX   dict[str, str | Omit]c                F    i t                      j        ddd| j        S )Nfalse
2023-06-01zX-Stainless-Asynczanthropic-version)rQ   r8   _custom_headersrU   rV   s    rW   r8   zAnthropic.default_headers   s>    
gg%
!(!-
 
 
 "	
 	
rX   headersr   rL   c                t   |                     d          s|                     d          rd S |                     d          s(t          |                     d          t                    rd S |                     d          s(t          |                     d          t                    rd S t          d          Nr   ry   z"Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the `X-Api-Key` or `Authorization` headers to be explicitly omitted"rP   
isinstancer   	TypeErrorrU   r   rL   s      rW   _validate_headerszAnthropic._validate_headers       ;;'' 	7;;{+C+C 	F;;{## 	z.2D2D[2Q2QSW'X'X 	F;;'' 	:n6H6H6Y6Y[_+`+` 	F |
 
 	
rX   r2   r3   r5   r6   r:   r7   r8   set_default_headersr9   set_default_query_extra_kwargsint | NotGivenr   r   r   Mapping[str, Any]r   c               j   ||t          d          |	|
t          d          | j        }|i ||}n||}| j        }|	i ||	}n|
|
}|p| j        } | j        d|p| j        |p| j        |p| j        t          |t                    r| 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)r2   r3   r5   r6   r:   r7   r8   r9    
ValueErrorr   _custom_query_clientrV   r2   r3   r5   r   r   r6   r   r7   rU   r2   r3   r5   r6   r:   r7   r8   r   r9   r   r   r   paramss                 rW   copyzAnthropic.copy      $ &+>+Joppp$):)Fklll&&44O4GG ,)G#$00-0FF*&F!1T\t~ 

+t|!4T_.$.w$A$ANDLLw#'/'<'<R$BR# 

 

 

 

 
	
rX   err_msgstrbodyobjectresponsehttpx.Responser   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 |j         d
k    rt          j
        |||          S |j         dk    rt          j        |||          S t          |||          S )N  r   r           i      i    )status_coder   BadRequestErrorAuthenticationErrorPermissionDeniedErrorNotFoundErrorConflictErrorRequestTooLargeErrorUnprocessableEntityErrorRateLimitErrorOverloadedErrorInternalServerErrorr   rU   r   r   r   s       rW   _make_status_errorzAnthropic._make_status_error   s    3&&.wPTUUUU3&&27XTXYYYY3&&4WxVZ[[[[3&&,WxdSSSS3&&,WxdSSSS3&&3GhUYZZZZ3&&7(Y]^^^^3&&-gtTTTT3&&.wPTUUUU3&&27XTXYYYYgtDDDDrX   )r2   r1   r3   r1   r5   r<   r6   r=   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   rC   rD   )rC   r(   )rC   r*   )rC   r$   )rC   r&   )rC   ra   )rC   rf   rC   r   rC   rp   rC   r   r   r   rL   r   rC   rD   )r2   r1   r3   r1   r5   r<   r6   r=   r:   rA   r7   r   r8   r?   r   r?   r9   r@   r   r@   r   r   rC   r   r   r   r   r   r   r   rC   r   __name__
__module____qualname____annotations__r
   HUMAN_PROMPT	AI_PROMPTr   r   rR   r   r#   r"   r!   r    re   rh   propertyr   rn   ru   rs   rt   r8   r   r   with_optionsr   __classcell__rV   s   @rW   r,   r,   5   s         *L$I
 #!%+/5>.4859 ,0 -2-6* 6* 6* 6* 6* 6* 6* 6*p ! ! ! _!
    _
    _
    _
 . . . _. 3 3 3 _3 1 1 1 X X1 ; ; ; X X; & & & X& 9 9 9 X9 
 
 
 
 
 X X
 
 
 
 X
$ #!%+/5>+/&/488<599=+-/
 /
 /
 /
 /
 /
f L$E $E $E X$E $E $E $E $ErX   r,   c                      e Zd ZU ded<   ded<   ej        Zej        Zdddeeddddd	d@ fdZ	e
dAd            Ze
dBd            Ze
dCd            Ze
dDd            Ze
dEd!            Ze
dFd#            ZeedGd%                        ZeedHd'                        ZedHd(            ZedHd)            ZeedI fd+                        ZedJd/            Zdddededdddi d0dKd7ZeZedLd?            Z xZS )Mr-   r1   r2   r3   NFr4   r5   r<   r6   r=   r7   r>   r8   r?   r9   r@   r:   httpx.AsyncClient | Noner;   rB   rC   rD   c       	   
     f   |t           j                            d          }|| _        |t           j                            d          }|| _        |t           j                            d          }|d}t                                          t          |||||||	           t          | _	        dS )a"  Construct a new async AsyncAnthropic client instance.

        This automatically infers the following arguments from their corresponding environment variables if they are not provided:
        - `api_key` from `ANTHROPIC_API_KEY`
        - `auth_token` from `ANTHROPIC_AUTH_TOKEN`
        NrF   rG   rH   rI   rJ   )
rN   rO   rP   r2   r3   rQ   rR   r   r   rS   rT   s             rW   rR   zAsyncAnthropic.__init__.  s    < ?jnn%899G(>??J$z~~&:;;H3H##*&(C 	 		
 		
 		
 $/   rX   r)   c                $    ddl m}  ||           S )Nr	   )r)   )rZ   r)   )rU   r)   s     rW   r#   zAsyncAnthropic.completionsf  s%    ;;;;;;%%%rX   r+   c                $    ddl m}  ||           S )Nr	   )r+   )r\   r+   )rU   r+   s     rW   r"   zAsyncAnthropic.messagesl  s$    555555}T"""rX   r%   c                $    ddl m}  ||           S )Nr	   )r%   )r^   r%   )rU   r%   s     rW   r!   zAsyncAnthropic.modelsr  s$    111111{4   rX   r'   c                $    ddl m}  ||           S )Nr	   )r'   )r`   r'   )rU   r'   s     rW   r    zAsyncAnthropic.betax  s"    ------yrX   AsyncAnthropicWithRawResponsec                     t          |           S rc   )r   rd   s    rW   re   z AsyncAnthropic.with_raw_response~  ri   rX   "AsyncAnthropicWithStreamedResponsec                     t          |           S rc   )r   rd   s    rW   rh   z&AsyncAnthropic.with_streaming_response  s    1$777rX   r   c                "    t          d          S rk   r   rd   s    rW   rn   zAsyncAnthropic.qs  ro   rX   rp   c                "    i | j         | j        S rc   rr   rd   s    rW   ru   zAsyncAnthropic.auth_headers  rv   rX   c                     | j         }|i S d|iS rx   rz   r{   s     rW   rs   zAsyncAnthropic._api_key_auth  r|   rX   c                &    | j         }|i S dd| iS r~   r   r   s     rW   rt   zAsyncAnthropic._bearer_auth  r   rX   r   c                d    i t                      j        dt                       dd| j        S )Nzasync:r   r   )rQ   r8   r   r   r   s    rW   r8   zAsyncAnthropic.default_headers  sM    
gg%
!?*;*=*=!?!?!-
 
 
 "	
 	
rX   r   r   rL   c                t   |                     d          s|                     d          rd S |                     d          s(t          |                     d          t                    rd S |                     d          s(t          |                     d          t                    rd S t          d          r   r   r   s      rW   r   z AsyncAnthropic._validate_headers  r   rX   r   r   r   r   r   r   r   c               j   ||t          d          |	|
t          d          | j        }|i ||}n||}| j        }|	i ||	}n|
|
}|p| j        } | j        d|p| j        |p| j        |p| j        t          |t                    r| j
        n||t          |          r|n| j        ||d|S r   r   r   s                 rW   r   zAsyncAnthropic.copy  r   rX   r   r   r   r   r   r   r   c               F   |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 )
Nr   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   s       rW   r   z!AsyncAnthropic._make_status_error  sN    3&&.wPTUUUU3&&27XTXYYYY3&&4WxVZ[[[[3&&,WxdSSSS3&&,WxdSSSS3&&7(Y]^^^^3&&-gtTTTT3&&27XTXYYYYgtDDDDrX   )r2   r1   r3   r1   r5   r<   r6   r=   r7   r>   r8   r?   r9   r@   r:   r   r;   rB   rC   rD   )rC   r)   )rC   r+   )rC   r%   )rC   r'   )rC   r   )rC   r   r   r   r   r   )r2   r1   r3   r1   r5   r<   r6   r=   r:   r   r7   r   r8   r?   r   r?   r9   r@   r   r@   r   r   rC   r   r   r   r   s   @rW   r-   r-   %  s         *L$I
 #!%+/5>.4859 15 -2-6/ 6/ 6/ 6/ 6/ 6/ 6/ 6/p & & & _&
 # # # _#
 ! ! ! _!
    _
 3 3 3 _3 8 8 8 _8 1 1 1 X X1 ; ; ; X X; & & & X& 9 9 9 X9 
 
 
 
 
 X X
 
 
 
 X
$ #!%+/5>04&/488<599=+-/
 /
 /
 /
 /
 /
f LE E E XE E E E ErX   r-   c                      e Zd ZU ded<   ddZedd            Zedd
            Zedd            Zedd            Z	dS )ra   r,   r   clientrC   rD   c                    || _         d S rc   r   rU   r   s     rW   rR   z!AnthropicWithRawResponse.__init__      rX   &completions.CompletionsWithRawResponsec                8    ddl m}  || j        j                  S )Nr	   )CompletionsWithRawResponse)rZ   r   r   r#   )rU   r   s     rW   r#   z$AnthropicWithRawResponse.completions  s*    EEEEEE))$,*BCCCrX    messages.MessagesWithRawResponsec                8    ddl m}  || j        j                  S )Nr	   )MessagesWithRawResponse)r\   r   r   r"   )rU   r   s     rW   r"   z!AnthropicWithRawResponse.messages  s*    ??????&&t|'<===rX   models.ModelsWithRawResponsec                8    ddl m}  || j        j                  S )Nr	   )ModelsWithRawResponse)r^   r   r   r!   )rU   r   s     rW   r!   zAnthropicWithRawResponse.models!  s*    ;;;;;;$$T\%8999rX   beta.BetaWithRawResponsec                8    ddl m}  || j        j                  S )Nr	   )BetaWithRawResponse)r`   r   r   r    )rU   r   s     rW   r    zAnthropicWithRawResponse.beta'  s*    777777""4<#4555rX   Nr   r,   rC   rD   )rC   r   )rC   r   )rC   r   )rC   r   
r   r   r   r   rR   r   r#   r"   r!   r    r   rX   rW   ra   ra     s             D D D _D
 > > > _>
 : : : _:
 6 6 6 _6 6 6rX   ra   c                      e Zd ZU ded<   ddZedd            Zedd
            Zedd            Zedd            Z	dS )r   r-   r   r   rC   rD   c                    || _         d S rc   r   r   s     rW   rR   z&AsyncAnthropicWithRawResponse.__init__1  r   rX   +completions.AsyncCompletionsWithRawResponsec                8    ddl m}  || j        j                  S )Nr	   )AsyncCompletionsWithRawResponse)rZ   r   r   r#   )rU   r   s     rW   r#   z)AsyncAnthropicWithRawResponse.completions4  s*    JJJJJJ..t|/GHHHrX   %messages.AsyncMessagesWithRawResponsec                8    ddl m}  || j        j                  S )Nr	   )AsyncMessagesWithRawResponse)r\   r   r   r"   )rU   r   s     rW   r"   z&AsyncAnthropicWithRawResponse.messages:  s*    DDDDDD++DL,ABBBrX   !models.AsyncModelsWithRawResponsec                8    ddl m}  || j        j                  S )Nr	   )AsyncModelsWithRawResponse)r^   r  r   r!   )rU   r  s     rW   r!   z$AsyncAnthropicWithRawResponse.models@  s*    @@@@@@))$,*=>>>rX   beta.AsyncBetaWithRawResponsec                8    ddl m}  || j        j                  S )Nr	   )AsyncBetaWithRawResponse)r`   r  r   r    )rU   r  s     rW   r    z"AsyncAnthropicWithRawResponse.betaF  s*    <<<<<<''(9:::rX   Nr   r-   rC   rD   )rC   r   )rC   r   )rC   r   )rC   r  r   r   rX   rW   r   r   .  s             I I I _I
 C C C _C
 ? ? ? _?
 ; ; ; _; ; ;rX   r   c                      e Zd ZU ded<   ddZedd            Zedd
            Zedd            Zedd            Z	dS )rf   r,   r   r   rC   rD   c                    || _         d S rc   r   r   s     rW   rR   z&AnthropicWithStreamedResponse.__init__P  r   rX   ,completions.CompletionsWithStreamingResponsec                8    ddl m}  || j        j                  S )Nr	   ) CompletionsWithStreamingResponse)rZ   r  r   r#   )rU   r  s     rW   r#   z)AnthropicWithStreamedResponse.completionsS  s*    KKKKKK//0HIIIrX   &messages.MessagesWithStreamingResponsec                8    ddl m}  || j        j                  S )Nr	   )MessagesWithStreamingResponse)r\   r  r   r"   )rU   r  s     rW   r"   z&AnthropicWithStreamedResponse.messagesY  s*    EEEEEE,,T\-BCCCrX   "models.ModelsWithStreamingResponsec                8    ddl m}  || j        j                  S )Nr	   )ModelsWithStreamingResponse)r^   r  r   r!   )rU   r  s     rW   r!   z$AnthropicWithStreamedResponse.models_  s*    AAAAAA**4<+>???rX   beta.BetaWithStreamingResponsec                8    ddl m}  || j        j                  S )Nr	   )BetaWithStreamingResponse)r`   r  r   r    )rU   r  s     rW   r    z"AnthropicWithStreamedResponse.betae  s*    ======(():;;;rX   Nr   )rC   r	  )rC   r  )rC   r  )rC   r  r   r   rX   rW   rf   rf   M  s             J J J _J
 D D D _D
 @ @ @ _@
 < < < _< < <rX   rf   c                      e Zd ZU ded<   ddZedd            Zedd
            Zedd            Zedd            Z	dS )r   r-   r   r   rC   rD   c                    || _         d S rc   r   r   s     rW   rR   z+AsyncAnthropicWithStreamedResponse.__init__o  r   rX   1completions.AsyncCompletionsWithStreamingResponsec                8    ddl m}  || j        j                  S )Nr	   )%AsyncCompletionsWithStreamingResponse)rZ   r  r   r#   )rU   r  s     rW   r#   z.AsyncAnthropicWithStreamedResponse.completionsr  s*    PPPPPP44T\5MNNNrX   +messages.AsyncMessagesWithStreamingResponsec                8    ddl m}  || j        j                  S )Nr	   )"AsyncMessagesWithStreamingResponse)r\   r  r   r"   )rU   r  s     rW   r"   z+AsyncAnthropicWithStreamedResponse.messagesx  s*    JJJJJJ11$,2GHHHrX   'models.AsyncModelsWithStreamingResponsec                8    ddl m}  || j        j                  S )Nr	   ) AsyncModelsWithStreamingResponse)r^   r  r   r!   )rU   r  s     rW   r!   z)AsyncAnthropicWithStreamedResponse.models~  s*    FFFFFF//0CDDDrX   #beta.AsyncBetaWithStreamingResponsec                8    ddl m}  || j        j                  S )Nr	   )AsyncBetaWithStreamingResponse)r`   r"  r   r    )rU   r"  s     rW   r    z'AsyncAnthropicWithStreamedResponse.beta  s*    BBBBBB--dl.?@@@rX   Nr  )rC   r  )rC   r  )rC   r  )rC   r   r   r   rX   rW   r   r   l  s             O O O _O
 I I I _I
 E E E _E
 A A A _A A ArX   r   )B
__future__r   rN   typingr   r   r   typing_extensionsr   r   httpx r
   r   _qsr   _typesr   r   r   r   r   r   r   r   _utilsr   r   _compatr   _versionr   
_streamingr   r   r   _base_clientr   r   r   	resourcesr    r!   r"   r#   r^   r$   r%   resources.beta.betar&   r'   rZ   r(   r)   resources.messages.messagesr*   r+   __all__r,   r-   ra   r   rf   r   r.   r/   r   rX   rW   <module>r3     sW   # " " " " " 				 . . . . . . . . . . , , , , , , , ,  % % % % % % % %      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 0 / / / / / / / $ $ $ $ $ $ ! ! ! ! ! ! D D D D D D D D ' ' ' ' ' '           E>>>>>>>>>>>>5555555544444444DDDDDDDDDDDDDDDD	 	 	mE mE mE mE mE mE mE mE`gE gE gE gE gE^ gE gE gET6 6 6 6 6 6 6 6>; ; ; ; ; ; ; ;>< < < < < < < <>A A A A A A A A> 
rX   