o
    +iY                     @  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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rd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Z9G dd de&Z:G dd de'Z;G dd dZ<G dd dZ=G dd dZ>G d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	dO fddZ	e
dPddZe
dQddZe
dRd d!Ze
dSd#d$Ze
dTd&d'Ze
dUd)d*ZeedVd,d-ZeedWd/d0ZedWd1d2ZedWd3d4ZeedX fd6d7ZedYd;d<Zdddededdddi d=dZdDdEZeZed[dMdNZ  ZS )\r+   
str | Noneapi_key
auth_tokenNF	r1   r2   base_urltimeoutmax_retriesdefault_headersdefault_queryhttp_client_strict_response_validationr4   str | httpx.URL | Noner5   !float | Timeout | None | NotGivenr6   intr7   Mapping[str, str] | Noner8   Mapping[str, object] | Noner9   httpx.Client | Noner:   boolreturnNonec       	   
   
     z   |du r
t jd}|| _|du rt jd}|| _|du r$t jd}|du r*d}t jt|||||||	d 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versionr4   r6   r5   r9   custom_headerscustom_queryr:   )
osenvirongetr1   r2   super__init__r   r   _default_stream_cls
selfr1   r2   r4   r5   r6   r7   r8   r9   r:   	__class__ N/var/www/html/psymed-ai/venv/lib/python3.10/site-packages/anthropic/_client.pyrQ   >   *   
zAnthropic.__init__r'   c                 C     ddl m} || S )Nr   )r'   )resources.completionsr'   )rT   r'   rW   rW   rX   r"   v      zAnthropic.completionsr)   c                 C  rZ   )Nr   )r)   )resources.messagesr)   )rT   r)   rW   rW   rX   r!   |   r\   zAnthropic.messagesr#   c                 C  rZ   )Nr   )r#   )resources.modelsr#   )rT   r#   rW   rW   rX   r       r\   zAnthropic.modelsr%   c                 C  rZ   )Nr   )r%   )resources.betar%   )rT   r%   rW   rW   rX   r      r\   zAnthropic.betaAnthropicWithRawResponsec                 C     t | S N)r`   rT   rW   rW   rX   with_raw_response      zAnthropic.with_raw_responseAnthropicWithStreamedResponsec                 C  ra   rb   )rf   rc   rW   rW   rX   with_streaming_response   re   z!Anthropic.with_streaming_responser   c                 C  
   t ddS Ncomma)array_formatr   rc   rW   rW   rX   qs      
zAnthropic.qsdict[str, str]c                 C     i | j | jS rb   _api_key_auth_bearer_authrc   rW   rW   rX   auth_headers      zAnthropic.auth_headersc                 C     | j }|d u r	i S d|iS N	X-Api-Keyr1   rT   r1   rW   rW   rX   rq         zAnthropic._api_key_authc                 C      | j }|d u r	i S dd| iS NAuthorizationzBearer r2   rT   r2   rW   rW   rX   rr         zAnthropic._bearer_authdict[str, str | Omit]c                   s   i t  jddd| jS )Nfalse
2023-06-01zX-Stainless-Asynczanthropic-version)rP   r7   _custom_headersrc   rU   rW   rX   r7      s   zAnthropic.default_headersheadersr   rK   c                 C  p   | ds
| drd S | jr| drd S t| dtr d S | jr*| dr*d S t| dtr4d S tdNr}   rw   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"rO   r1   
isinstancer   r2   	TypeErrorrT   r   rK   rW   rW   rX   _validate_headers      zAnthropic._validate_headersr1   r2   r4   r5   r9   r6   r7   set_default_headersr8   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|pT| jt|t	r\| j
n||t|rd|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)r1   r2   r4   r5   r9   r6   r7   r8   rW   
ValueErrorr   _custom_query_clientrV   r1   r2   r4   r   r   r5   r   r6   rT   r1   r2   r4   r5   r9   r6   r7   r   r8   r   r   r   paramsrW   rW   rX   copy   6   
	zAnthropic.copyerr_msgstrbodyobjectresponsehttpx.Responser   c                C  s  |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 |j d
krutj
|||dS |j dkrtj|||dS t|||dS )N  r   r           i      i    )status_coder
   BadRequestErrorAuthenticationErrorPermissionDeniedErrorNotFoundErrorConflictErrorRequestTooLargeErrorUnprocessableEntityErrorRateLimitErrorOverloadedErrorInternalServerErrorr   rT   r   r   r   rW   rW   rX   _make_status_error  s*   









zAnthropic._make_status_error)r1   r0   r2   r0   r4   r;   r5   r<   r6   r=   r7   r>   r8   r?   r9   r@   r:   rA   rB   rC   )rB   r'   )rB   r)   )rB   r#   )rB   r%   )rB   r`   )rB   rf   rB   r   rB   rn   rB   r   r   r   rK   r   rB   rC   )r1   r0   r2   r0   r4   r;   r5   r<   r9   r@   r6   r   r7   r>   r   r>   r8   r?   r   r?   r   r   rB   r   r   r   r   r   r   r   rB   r   __name__
__module____qualname____annotations__r	   HUMAN_PROMPT	AI_PROMPTr   r   rQ   r   r"   r!   r    r   rd   rg   propertyr   rl   rs   rq   rr   r7   r   r   with_optionsr   __classcell__rW   rW   rU   rX   r+   5   r   
 	83r+   c                      r/   )\r,   r0   r1   r2   NFr3   r4   r;   r5   r<   r6   r=   r7   r>   r8   r?   r9   httpx.AsyncClient | Noner:   rA   rB   rC   c       	   
   
     rD   )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`
        NrE   rF   rG   rH   rI   )
rM   rN   rO   r1   r2   rP   rQ   r   r   rR   rS   rU   rW   rX   rQ   2  rY   zAsyncAnthropic.__init__r(   c                 C  rZ   )Nr   )r(   )r[   r(   )rT   r(   rW   rW   rX   r"   j  r\   zAsyncAnthropic.completionsr*   c                 C  rZ   )Nr   )r*   )r]   r*   )rT   r*   rW   rW   rX   r!   p  r\   zAsyncAnthropic.messagesr$   c                 C  rZ   )Nr   )r$   )r^   r$   )rT   r$   rW   rW   rX   r    v  r\   zAsyncAnthropic.modelsr&   c                 C  rZ   )Nr   )r&   )r_   r&   )rT   r&   rW   rW   rX   r   |  r\   zAsyncAnthropic.betaAsyncAnthropicWithRawResponsec                 C  ra   rb   )r   rc   rW   rW   rX   rd     re   z AsyncAnthropic.with_raw_response"AsyncAnthropicWithStreamedResponsec                 C  ra   rb   )r   rc   rW   rW   rX   rg     re   z&AsyncAnthropic.with_streaming_responser   c                 C  rh   ri   r   rc   rW   rW   rX   rl     rm   zAsyncAnthropic.qsrn   c                 C  ro   rb   rp   rc   rW   rW   rX   rs     rt   zAsyncAnthropic.auth_headersc                 C  ru   rv   rx   ry   rW   rW   rX   rq     rz   zAsyncAnthropic._api_key_authc                 C  r{   r|   r~   r   rW   rW   rX   rr     r   zAsyncAnthropic._bearer_authr   c                   s$   i t  jdt  dd| jS )Nzasync:r   r   )rP   r7   r   r   rc   rU   rW   rX   r7     s   
zAsyncAnthropic.default_headersr   r   rK   c                 C  r   r   r   r   rW   rW   rX   r     r   z AsyncAnthropic._validate_headersr   r   r   r   r   r   r   c                C  r   r   r   r   rW   rW   rX   r     r   zAsyncAnthropic.copyr   r   r   r   r   r   r   c                C  s   |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 )
Nr   r   r   r   r   r   r   r   r   )r   r
   r   r   r   r   r   r   r   r   r   r   rW   rW   rX   r     s"   







z!AsyncAnthropic._make_status_error)r1   r0   r2   r0   r4   r;   r5   r<   r6   r=   r7   r>   r8   r?   r9   r   r:   rA   rB   rC   )rB   r(   )rB   r*   )rB   r$   )rB   r&   )rB   r   )rB   r   r   r   r   r   )r1   r0   r2   r0   r4   r;   r5   r<   r9   r   r6   r   r7   r>   r   r>   r8   r?   r   r?   r   r   rB   r   r   r   rW   rW   rU   rX   r,   )  r   r,   c                   @  X   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	dS )r`   r+   r   clientrB   rC   c                 C  
   || _ d S rb   r   rT   r   rW   rW   rX   rQ        
z!AnthropicWithRawResponse.__init__&completions.CompletionsWithRawResponsec                 C     ddl m} || jjS )Nr   )CompletionsWithRawResponse)r[   r   r   r"   )rT   r   rW   rW   rX   r"        z$AnthropicWithRawResponse.completions messages.MessagesWithRawResponsec                 C  r   )Nr   )MessagesWithRawResponse)r]   r   r   r!   )rT   r   rW   rW   rX   r!   #  r   z!AnthropicWithRawResponse.messagesmodels.ModelsWithRawResponsec                 C  r   )Nr   )ModelsWithRawResponse)r^   r   r   r    )rT   r   rW   rW   rX   r    )  r   zAnthropicWithRawResponse.modelsbeta.BetaWithRawResponsec                 C  r   )Nr   )BetaWithRawResponse)r_   r   r   r   )rT   r   rW   rW   rX   r   /  r   zAnthropicWithRawResponse.betaNr   r+   rB   rC   )rB   r   )rB   r   )rB   r   )rB   r   
r   r   r   r   rQ   r   r"   r!   r    r   rW   rW   rW   rX   r`        
 
r`   c                   @  r   )r   r,   r   r   rB   rC   c                 C  r   rb   r   r   rW   rW   rX   rQ   9  r   z&AsyncAnthropicWithRawResponse.__init__+completions.AsyncCompletionsWithRawResponsec                 C  r   )Nr   )AsyncCompletionsWithRawResponse)r[   r   r   r"   )rT   r   rW   rW   rX   r"   <  r   z)AsyncAnthropicWithRawResponse.completions%messages.AsyncMessagesWithRawResponsec                 C  r   )Nr   )AsyncMessagesWithRawResponse)r]   r   r   r!   )rT   r   rW   rW   rX   r!   B  r   z&AsyncAnthropicWithRawResponse.messages!models.AsyncModelsWithRawResponsec                 C  r   )Nr   )AsyncModelsWithRawResponse)r^   r   r   r    )rT   r   rW   rW   rX   r    H  r   z$AsyncAnthropicWithRawResponse.modelsbeta.AsyncBetaWithRawResponsec                 C  r   )Nr   )AsyncBetaWithRawResponse)r_   r   r   r   )rT   r   rW   rW   rX   r   N  r   z"AsyncAnthropicWithRawResponse.betaNr   r,   rB   rC   )rB   r   )rB   r   )rB   r   )rB   r   r   rW   rW   rW   rX   r   6  r   r   c                   @  r   )rf   r+   r   r   rB   rC   c                 C  r   rb   r   r   rW   rW   rX   rQ   X  r   z&AnthropicWithStreamedResponse.__init__,completions.CompletionsWithStreamingResponsec                 C  r   )Nr   ) CompletionsWithStreamingResponse)r[   r   r   r"   )rT   r   rW   rW   rX   r"   [  r   z)AnthropicWithStreamedResponse.completions&messages.MessagesWithStreamingResponsec                 C  r   )Nr   )MessagesWithStreamingResponse)r]   r   r   r!   )rT   r   rW   rW   rX   r!   a  r   z&AnthropicWithStreamedResponse.messages"models.ModelsWithStreamingResponsec                 C  r   )Nr   )ModelsWithStreamingResponse)r^   r   r   r    )rT   r   rW   rW   rX   r    g  r   z$AnthropicWithStreamedResponse.modelsbeta.BetaWithStreamingResponsec                 C  r   )Nr   )BetaWithStreamingResponse)r_   r   r   r   )rT   r   rW   rW   rX   r   m  r   z"AnthropicWithStreamedResponse.betaNr   )rB   r   )rB   r   )rB   r   )rB   r   r   rW   rW   rW   rX   rf   U  r   rf   c                   @  r   )r   r,   r   r   rB   rC   c                 C  r   rb   r   r   rW   rW   rX   rQ   w  r   z+AsyncAnthropicWithStreamedResponse.__init__1completions.AsyncCompletionsWithStreamingResponsec                 C  r   )Nr   )%AsyncCompletionsWithStreamingResponse)r[   r   r   r"   )rT   r   rW   rW   rX   r"   z  r   z.AsyncAnthropicWithStreamedResponse.completions+messages.AsyncMessagesWithStreamingResponsec                 C  r   )Nr   )"AsyncMessagesWithStreamingResponse)r]   r   r   r!   )rT   r   rW   rW   rX   r!     r   z+AsyncAnthropicWithStreamedResponse.messages'models.AsyncModelsWithStreamingResponsec                 C  r   )Nr   ) AsyncModelsWithStreamingResponse)r^   r   r   r    )rT   r   rW   rW   rX   r      r   z)AsyncAnthropicWithStreamedResponse.models#beta.AsyncBetaWithStreamingResponsec                 C  r   )Nr   )AsyncBetaWithStreamingResponse)r_   r   r   r   )rT   r   rW   rW   rX   r     r   z'AsyncAnthropicWithStreamedResponse.betaNr   )rB   r   )rB   r   )rB   r   )rB   r   r   rW   rW   rW   rX   r   t  r   r   )B
__future__r   rM   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&   r[   r'   r(   resources.messages.messagesr)   r*   __all__r+   r,   r`   r   rf   r   r-   r.   rW   rW   rW   rX   <module>   s>   (
 u o