
    .MgEU                    t   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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mZ dd	lmZ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'm(Z(m)Z)m*Z* g dZ+ G d de'      Z, G d de(      Z- G d d      Z. G d d      Z/ G d d      Z0 G d d      Z1e,Z2e-Z3y)    )annotationsN)AnyUnionMapping)Selfoverride   )	resources
_constants_exceptionsQuerystring)		NOT_GIVENOmitHeadersTimeoutNotGiven	TransportProxiesTypesAsyncTransportRequestOptions)is_givenget_async_library)__version__)StreamAsyncStream)APIStatusError)DEFAULT_MAX_RETRIESDEFAULT_CONNECTION_LIMITSSyncAPIClientAsyncAPIClientSyncHttpxClientWrapperAsyncHttpxClientWrapper)	r   r   r   r   r
   	AnthropicAsyncAnthropicClientAsyncClientc                      e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ej
                  Zej                  Zdddeedddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	e
edd              Ze
edd              Ze
dd       Ze
dd       Ze
ed fd              Zedd       Zdddeddeddddi d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d dZeZe	 	 	 	 	 	 	 	 d!d       Z xZS )"r$   zresources.Completionscompletionszresources.Messagesmessageszresources.BetabetaAnthropicWithRawResponsewith_raw_responseAnthropicWithStreamedResponsewith_streaming_response
str | Noneapi_key
auth_tokenNFr1   r2   base_urltimeoutmax_retriesdefault_headersdefault_queryhttp_client	transportproxiesconnection_pool_limits_strict_response_validationc                  |t         j                  j                  d      }|| _        |t         j                  j                  d      }|| _        |t         j                  j                  d      }|d}t
        |   t        |||||	|
||||       t        | _	        t        j                  |       | _        t        j                  |       | _        t        j                  |       | _        t#        |       | _        t'        |       | _        y)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   r:   r;   limitscustom_headerscustom_queryr=   )osenvirongetr1   r2   super__init__r   r   _default_stream_clsr
   Completionsr)   Messagesr*   Betar+   r,   r-   r.   r/   selfr1   r2   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   	__class__s                _E:\wamp.anq\www\apps\calme\nutritwin\resources\nutritwin\Lib\site-packages\anthropic/_client.pyrL   zAnthropic.__init__D   s    H ?jjnn%89G(>?J$zz~~&:;H2H##)*&(C 	 	
 $* $006!**40NN4(	!9$!?'DT'J$    c                    t        d      S Ncomma)array_formatr   rR   s    rT   qszAnthropic.qs        00rU   c                f    | j                   r| j                   S | j                  r| j                  S i S N_api_key_auth_bearer_authrZ   s    rT   auth_headerszAnthropic.auth_headers   3     %%%$$$	rU   c                *    | j                   }|i S d|iS N	X-Api-Keyr1   rR   r1   s     rT   r`   zAnthropic._api_key_auth        ,,?IW%%rU   c                0    | j                   }|i S dd| iS NAuthorizationzBearer r2   rR   r2   s     rT   ra   zAnthropic._bearer_auth   (    __
I7:,!788rU   c                >    i t         |   ddd| j                  S )Nfalse
2023-06-01zX-Stainless-Asynczanthropic-version)rK   r7   _custom_headersrR   rS   s    rT   r7   zAnthropic.default_headers   s5    
g%
!(!-
 ""	
 	
rU   c                   | j                   r|j                  d      ry t        |j                  d      t              ry | j                  r|j                  d      ry t        |j                  d      t              ry t        d      Nrf   rl   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"r1   rJ   
isinstancer   r2   	TypeErrorrR   headersrF   s      rT   _validate_headerszAnthropic._validate_headers   o    <<GKK4n((5t<??w{{?;n((94@ |
 	
rU   r1   r2   r4   r5   r9   r<   r6   r7   set_default_headersr8   set_default_query_extra_kwargsc               d   ||	t        d      |
|t        d      | j                  }|i ||}n|	|	}| j                  }|
i ||
}n||}|5|t        d      t        | j                  t
              st        d      d}n1| j                  t        ur| j                  }nd}|xs | j                  } | j                  d|xs | j                  |xs | j                  |xs | 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 exclusivezNThe 'http_client' argument is mutually exclusive with 'connection_pool_limits'zfA custom HTTP client has been set and is mutually exclusive with the 'connection_pool_limits' argument)	r1   r2   r4   r5   r9   r<   r6   r7   r8    )
ValueErrorrt   _custom_queryry   _clientr"   _limitsr   rS   r1   r2   r4   r   r5   r   r6   rR   r1   r2   r4   r5   r9   r<   r6   r7   r   r8   r   r   r|   paramss                  rT   copyzAnthropic.copy   si   & &+>+Jopp$):)Fkll&&&44O4G ,)G##$00-0F*&F!-& !qrrdll,BC |  K||#<<)-&)-&%5Kt~~ 
+t||!4T__.$.w$ADLLw##9'/'<$BRBR# 
 
 	
rU   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 t        |||      S 
Ni  )responsebodyi  i  i  i  i  i  i  status_coder   BadRequestErrorAuthenticationErrorPermissionDeniedErrorNotFoundErrorConflictErrorUnprocessableEntityErrorRateLimitErrorInternalServerErrorr   rR   err_msgr   r   s       rT   _make_status_errorzAnthropic._make_status_error	  0    3&..wPTUU3&227XTXYY3&44WxVZ[[3&,,WxdSS3&,,WxdSS3&77(Y]^^3&--gtTT3&227XTXYYgtDDrU   )r1   r0   r2   r0   r4   str | httpx.URL | Noner5   %Union[float, Timeout, None, NotGiven]r6   intr7   Mapping[str, str] | Noner8   Mapping[str, object] | Noner9   httpx.Client | Noner:   zTransport | Noner;   ProxiesTypes | Noner<   httpx.Limits | Noner=   boolreturnNoner   r   r   zdict[str, str]r   zdict[str, str | Omit]r|   r   rF   r   r   r   )r1   r0   r2   r0   r4   r   r5   !float | Timeout | None | NotGivenr9   r   r<   r   r6   int | NotGivenr7   r   r   r   r8   r   r   r   r   Mapping[str, Any]r   r   r   strr   objectr   zhttpx.Responser   r   __name__
__module____qualname____annotations__r   HUMAN_PROMPT	AI_PROMPTr   r   rL   propertyr   r[   rb   r`   ra   r7   r}   r   with_optionsr   __classcell__rS   s   @rT   r$   r$   5   s   &&  
//::  **L$$I
 #!%+/9B.4859 ,0&*'+6: -29EK EK 	EK
 )EK 7EK EK 2EK 3EK )EK $EK" %#EK& !4'EK8 &*9EK: 
;EKN 1  1    & & 9 9 
  
 
 
$ #!%+/5>+/6:&/488<599=+-B
 B
 	B

 )B
 3B
 )B
 !4B
 $B
 2B
 6B
 3B
 7B
 )B
 
B
L LEE 	E
 !E 
E ErU   r$   c                      e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ej
                  Zej                  Zdddeedddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	e
edd              Ze
edd              Ze
dd       Ze
dd       Ze
ed fd              Zedd       Zdddeddeddddi d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d dZeZe	 	 	 	 	 	 	 	 d!d       Z xZS )"r%   zresources.AsyncCompletionsr)   zresources.AsyncMessagesr*   zresources.AsyncBetar+   AsyncAnthropicWithRawResponser-   "AsyncAnthropicWithStreamedResponser/   r0   r1   r2   NFr3   c                  |t         j                  j                  d      }|| _        |t         j                  j                  d      }|| _        |t         j                  j                  d      }|d}t
        |   t        |||||	|
||||       t        | _	        t        j                  |       | _        t        j                  |       | _        t        j                  |       | _        t#        |       | _        t'        |       | _        y)a  Construct a new async 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`
        Nr?   r@   rA   rB   rC   )rH   rI   rJ   r1   r2   rK   rL   r   r   rM   r
   AsyncCompletionsr)   AsyncMessagesr*   	AsyncBetar+   r   r-   r   r/   rQ   s                rT   rL   zAsyncAnthropic.__init__:  s    H ?jjnn%89G(>?J$zz~~&:;H2H##)*&(C 	 	
 $/ $55d;!//5''-	!>t!D'I$'O$rU   c                    t        d      S rW   r   rZ   s    rT   r[   zAsyncAnthropic.qs  r\   rU   c                f    | j                   r| j                   S | j                  r| j                  S i S r^   r_   rZ   s    rT   rb   zAsyncAnthropic.auth_headers  rc   rU   c                *    | j                   }|i S d|iS re   rg   rh   s     rT   r`   zAsyncAnthropic._api_key_auth  ri   rU   c                0    | j                   }|i S dd| iS rk   rm   rn   s     rT   ra   zAsyncAnthropic._bearer_auth  ro   rU   c                T    i t         |   dt                dd| j                  S )Nzasync:rr   rs   )rK   r7   r   rt   ru   s    rT   r7   zAsyncAnthropic.default_headers  sA    
g%
#)*;*=)>!?!-
 ""	
 	
rU   c                   | j                   r|j                  d      ry t        |j                  d      t              ry | j                  r|j                  d      ry t        |j                  d      t              ry t        d      rw   rx   r{   s      rT   r}   z AsyncAnthropic._validate_headers  r~   rU   r   c               d   ||	t        d      |
|t        d      | j                  }|i ||}n|	|	}| j                  }|
i ||
}n||}|5|t        d      t        | j                  t
              st        d      d}n1| j                  t        ur| j                  }nd}|xs | j                  } | j                  d|xs | j                  |xs | j                  |xs | j                  t        |t              r| j                  n|||t        |      r|n| j                  ||d	|S r   )r   rt   r   ry   r   r#   r   r   rS   r1   r2   r4   r   r5   r   r6   r   s                  rT   r   zAsyncAnthropic.copy  si   & &+>+Jopp$):)Fkll&&&44O4G ,)G##$00-0F*&F!-& !qrrdll,CD |  K||#<<)-&)-&%5Kt~~ 
+t||!4T__.$.w$ADLLw##9'/'<$BRBR# 
 
 	
rU   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 t        |||      S r   r   r   s       rT   r   z!AsyncAnthropic._make_status_error  r   rU   )r1   r0   r2   r0   r4   r   r5   r   r6   r   r7   r   r8   r   r9   httpx.AsyncClient | Noner:   zAsyncTransport | Noner;   r   r<   r   r=   r   r   r   r   r   r   r   )r1   r0   r2   r0   r4   r   r5   r   r9   r   r<   r   r6   r   r7   r   r   r   r8   r   r   r   r   r   r   r   r   r   r   s   @rT   r%   r%   +  s   ++%%
44??  **L$$I
 #!%+/9B.4859 15+/'+6: -29EP EP 	EP
 )EP 7EP EP 2EP 3EP .EP )EP" %#EP& !4'EP8 &*9EP: 
;EPN 1  1    & & 9 9 
  
 
 
$ #!%+/5>046:&/488<599=+-B
 B
 	B

 )B
 3B
 .B
 !4B
 $B
 2B
 6B
 3B
 7B
 )B
 
B
L LEE 	E
 !E 
E ErU   r%   c                      e Zd ZddZy)r,   c                    t        j                  |j                        | _        t        j                  |j                        | _        t        j
                  |j                        | _        y r^   )r
   CompletionsWithRawResponser)   MessagesWithRawResponser*   BetaWithRawResponser+   rR   clients     rT   rL   z!AnthropicWithRawResponse.__init__"  sG    $??@R@RS!99&//J11&++>	rU   Nr   r$   r   r   r   r   r   rL   r   rU   rT   r,   r,   !  s    ?rU   r,   c                      e Zd ZddZy)r   c                    t        j                  |j                        | _        t        j                  |j                        | _        t        j
                  |j                        | _        y r^   )r
   AsyncCompletionsWithRawResponser)   AsyncMessagesWithRawResponser*   AsyncBetaWithRawResponser+   r   s     rT   rL   z&AsyncAnthropicWithRawResponse.__init__)  sG    $DDVEWEWX!>>vO66v{{C	rU   Nr   r%   r   r   r   r   rU   rT   r   r   (  s    DrU   r   c                      e Zd ZddZy)r.   c                    t        j                  |j                        | _        t        j                  |j                        | _        t        j
                  |j                        | _        y r^   )r
    CompletionsWithStreamingResponser)   MessagesWithStreamingResponser*   BetaWithStreamingResponser+   r   s     rT   rL   z&AnthropicWithStreamedResponse.__init__0  sG    $EEfFXFXY!??P77D	rU   Nr   r   r   rU   rT   r.   r.   /  s    ErU   r.   c                      e Zd ZddZy)r   c                    t        j                  |j                        | _        t        j                  |j                        | _        t        j
                  |j                        | _        y r^   )r
   %AsyncCompletionsWithStreamingResponser)   "AsyncMessagesWithStreamingResponser*   AsyncBetaWithStreamingResponser+   r   s     rT   rL   z+AsyncAnthropicWithStreamedResponse.__init__7  sG    $JJ6K]K]^!DDV__U<<V[[I	rU   Nr   r   r   rU   rT   r   r   6  s    JrU   r   )4
__future__r   rH   typingr   r   r   typing_extensionsr   r   httpx r
   r   r   _qsr   _typesr   r   r   r   r   r   r   r   r   _utilsr   r   _versionr   
_streamingr   r   r   _base_clientr   r   r    r!   r"   r#   __all__r$   r%   r,   r   r.   r   r&   r'   r   rU   rT   <module>r      s    # 	 & & ,  0 0 
 
 
 " D ' 
sE sElsE^ sEl? ?D DE EJ J 
rU   