
    "hj5                       U d dl mZ d dl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mZmZmZmZmZmZmZmZ dd	lmZm Z 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. ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC ddlDmEZEmFZFmGZG ddlHmIZJ ddlKmLZL ddlMmNZNmOZO g dZPej                  sddlRmSZS ddlTmUZVmWZXmYZY ddlZm[Z[ ddl\m]Z]m^Z^ ddl_m`Z`maZa ddlb ddlcmdZdmeZe  eJ         ef       ZgePD ]  Zhehj                  d      r	 degeh   _j        ! d dlZd dlZmd dlnZoddlDm,Z,m-Z- dapdeqd<   dardeqd <   dasdeqd!<   datdeqd"<   daudeqd#<   dZvd$eqd%<   e,awd&eqd'<   e-axd(eqd)<   dayd*eqd+<   dazd,eqd-<   da{d.eqd/<   emj                  d0   Z} ej                  e}ej                  j                  d1            ad2eqd3<   ej                  j                  d4      adeqd5<   ej                  j                  d6      adeqd7<   ej                  j                  d8      adeqd9<   dZd:eqd;<   dadeqd<<   dZd=eqd><    G d? d@e      Z G dA dBee]      Z G dC dDee`      Z G dE dFe2      ZdOdGZdOdHZdOdIZdadJeqdK<   dPdLZdQdMZddNlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ y# ekelf$ r Y w xY w)R    )annotationsN)override   )types)	NOT_GIVENOmitNoneTypeNotGiven	TransportProxiesTypesomit	not_given)file_from_path)	ClientOpenAIStreamTimeoutr   AsyncClientAsyncOpenAIAsyncStreamRequestOptions)DefaultHttpx2ClientDefaultAsyncHttpx2Clientnormalize_httpx_url)	BaseModel)	__title____version__)APIResponseAsyncAPIResponse)DEFAULT_TIMEOUTDEFAULT_MAX_RETRIESDEFAULT_CONNECTION_LIMITS)APIError
OAuthErrorOpenAIErrorConflictErrorNotFoundErrorAPIStatusErrorRateLimitErrorAPITimeoutErrorBadRequestErrorAPIConnectionErrorAuthenticationErrorInternalServerErrorPermissionDeniedErrorLengthFinishReasonErrorWebSocketQueueFullErrorUnprocessableEntityErrorAPIResponseValidationErrorInvalidWebhookSignatureErrorContentFilterFinishReasonErrorWebSocketConnectionClosedError)DefaultHttpxClientDefaultAioHttpClientDefaultAsyncHttpxClient)setup_logging)HttpxBinaryResponseContent)ReconnectingEventReconnectingOverrides)5r   r   r   r	   r   r   r
   r   r   r   r   r%   r#   r(   r*   r,   r3   r+   r-   r$   r/   r'   r&   r2   r)   r.   r0   r5   r4   r   r   r   r   r   r   r   r   BedrockOpenAIAsyncBedrockOpenAIr   r   r    r!   r"   r7   r9   r8   r   r   r<   r=   r1   r6   )	resources)azurebedrockpydantic_function_tool)VERSION)AzureOpenAIAsyncAzureOpenAI)r>   r?   )*)AssistantEventHandlerAsyncAssistantEventHandler__openai)r    r!   
str | Noneapi_keyadmin_api_keyorganizationprojectwebhook_secretzstr | _httpx.URL | Nonebase_urlfloat | Timeout | Nonetimeoutintmax_retries_t.Mapping[str, str] | Nonedefault_headers_t.Mapping[str, object] | Nonedefault_queryz_httpx.Client | Nonehttp_client)rK   rA   amazon-bedrockOPENAI_API_TYPEz_ApiType | Noneapi_typeOPENAI_API_VERSIONapi_versionAZURE_OPENAI_ENDPOINTazure_endpointAZURE_OPENAI_AD_TOKENazure_ad_tokenz"_azure.AzureADTokenProvider | Noneazure_ad_token_provider_bedrock_api_keyz$_bedrock.BedrockTokenProvider | Nonebedrock_token_providerc                      e Zd Zeedd              Zej                  dd       Zeedd              Zej                  dd       Zeedd              Zej                  dd       Zeedd              Z	e	j                  dd       Z	eedd	              Z
e
j                  dd
       Z
eed fd              Zej                  d fd       Zeedd              Zej                  dd       Zeedd              Zej                  dd       Zeedd              Zej                  d d       Zeed!d              Zej                  d"d       Zeed# fd              Zej                  d$d       Z xZS )%_ModuleClientc                    t         S NrM   selfs    M/root/.hermes/SkillClaw/.venv/lib/python3.12/site-packages/openai/__init__.pyrM   z_ModuleClient.api_key   	         c                    |a y rk   rl   rn   values     ro   rM   z_ModuleClient.api_key   	     rq   c                    t         S rk   rN   rm   s    ro   rN   z_ModuleClient.admin_api_key   
     rq   c                    |a y rk   rw   rs   s     ro   rN   z_ModuleClient.admin_api_key   	     rq   c                    t         S rk   rO   rm   s    ro   rO   z_ModuleClient.organization   s
     rq   c                    |a y rk   r|   rs   s     ro   rO   z_ModuleClient.organization   s	     rq   c                    t         S rk   rP   rm   s    ro   rP   z_ModuleClient.project   rp   rq   c                    |a y rk   r   rs   s     ro   rP   z_ModuleClient.project   ru   rq   c                    t         S rk   rQ   rm   s    ro   rQ   z_ModuleClient.webhook_secret   s
     rq   c                    |a y rk   r   rs   s     ro   rQ   z_ModuleClient.webhook_secret   s	     rq   c                B    t         t        t               S t        |    S rk   )rR   _normalize_httpx_urlsuperrn   	__class__s    ro   rR   z_ModuleClient.base_url   s!     '11wrq   c                $    |t               _        y rk   )r   rR   )rn   urlr   s     ro   rR   z_ModuleClient.base_url   s    rq   c                    t         S rk   rT   rm   s    ro   rT   z_ModuleClient.timeout   rp   rq   c                    |a y rk   r   rs   s     ro   rT   z_ModuleClient.timeout   ru   rq   c                    t         S rk   rV   rm   s    ro   rV   z_ModuleClient.max_retries  s
     rq   c                    |a y rk   r   rs   s     ro   rV   z_ModuleClient.max_retries  	     rq   c                    t         S rk   rX   rm   s    ro   _custom_headersz_ModuleClient._custom_headers  s
     rq   c                    |a y rk   r   rs   s     ro   r   z_ModuleClient._custom_headers  s	      rq   c                    t         S rk   rZ   rm   s    ro   _custom_queryz_ModuleClient._custom_query  rx   rq   c                    |a y rk   r   rs   s     ro   r   z_ModuleClient._custom_query  rz   rq   c                (    t         xs
 t        |   S rk   )r[   r   _clientr   s    ro   r   z_ModuleClient._client#  s     -ego-rq   c                    |a y rk   )r[   rs   s     ro   r   z_ModuleClient._client(  r   rq   returnrL   rt   rL   r   None)r   z
_httpx.URL)r   z_httpx.URL | strr   r   )r   rS   )rt   rS   r   r   )r   rU   )rt   rU   r   r   )r   rW   )rt   rW   r   r   )r   rY   )rt   rY   r   r   )r   _httpx.Client)rt   r   r   r   )__name__
__module____qualname__propertyr   rM   setterrN   rO   rP   rQ   rR   rT   rV   r   r   r   __classcell__r   s   @ro   ri   ri      sK       ^^ 
     
     
    ^^ 
     
      __     ^^ 
     
       
     
 .  . ^^ rq   ri   c                      e Zd Zy)_AzureModuleClientN)r   r   r    rq   ro   r   r   /  s    rq   r   c                       e Zd Zeedd              Zej                  dd       Zed fd       Zed fd       Z xZ	S )	_BedrockModuleClientc                &    t         t         S t        S rk   )rM   rf   rm   s    ro   rM   z_BedrockModuleClient.api_key4  s     "-wC3CCrq   c                    |a y rk   )rf   rs   s     ro   rM   z_BedrockModuleClient.api_key9  s
     !rq   c                8    t         t         S t        | 	         S rk   )rM   r   _refresh_api_keyr   s    ro   r   z%_BedrockModuleClient._refresh_api_key?  s    Nw'))rq   c                <    t         dt         fS t        | 	         S )Nbearer)rM   r   _legacy_auth_configurationr   s    ro   r   z/_BedrockModuleClient._legacy_auth_configurationF  s"    g&&w133rq   r   r   )r   str)r   z!_bedrock._LegacyAuthConfiguration)
r   r   r   r   r   rM   r   r   r   r   r   s   @ro   r   r   3  s_    D  D ^^! !
 * * 4 4rq   r   c                        e Zd Zd fdZ xZS ) _AmbiguousModuleClientUsageErrorc                $    t         |   d       y )NzAmbiguous use of module client; please set `openai.api_type` or the `OPENAI_API_TYPE` environment variable to `openai`, `azure`, or `amazon-bedrock`)r   __init__r   s    ro   r   z)_AmbiguousModuleClientUsageError.__init__N  s     c	
rq   r   r   )r   r   r   r   r   r   s   @ro   r   r   M  s    
 
rq   r   c                 D    t         j                  j                  d      d uS )NOPENAI_API_KEY)_osenvirongetr   rq   ro   _has_openai_credentialsr   T  s    ;;??+,D88rq   c                 X    t         d uxs! t        j                  j                  d      d uS )NAZURE_OPENAI_API_KEY)rb   r   r   r   r   rq   ro   _has_azure_credentialsr   X  s&    %\9O)PX\)\\rq   c                 l    t         j                  j                  d      d uxs t        d uxs t        d uS )Nrc   )r   r   r   rd   re   r   rq   ro   _has_azure_ad_credentialsr   \  s7    /0< 	/%	/"$.rq   zOpenAI | Noner   c                    t         t        t        j                  j	                  d      at
        t        j                  j	                  d      at        t        j                  j	                  d      at        mt               } t               }t               }| r|s|r
t               t
        t        *t        j                  j	                  d      	 
t               |s|rdandat        dk(  rMt        t        t        t        t
        t        t        t         t"        t$        t&        t(        t*              a t         S t        dk(  rHt-        t        t.        t        t0        t2        t         t"        t$        t&        t(        t*        	      a t         S t5        t        t6        t        t0        t2        t         t"        t$        t&        t(        t*        d
      a t         S t         S )Nra   rc   r_   r   rA   rK   )r`   rb   rM   rd   re   rO   rR   rT   rV   rX   rZ   r[   r\   )rM   rg   rO   rP   rQ   rR   rT   rV   rX   rZ   r[   F)rM   rN   rO   rP   rQ   rR   rT   rV   rX   rZ   r[   _enforce_credentials)r   rb   r   r   r   rd   r`   r^   r   r   r   r   re   r   rM   rO   rR   rT   rV   rX   rZ   r[   r   rg   rP   rQ   ri   rN   )
has_openai	has_azurehas_azure_ads      ro   _load_clientr   g  s}     ! [[__-DEN! [[__-DEN++//*>?K02J.0I46LyL688*.E.QWZWbWbWfWf&XX 788L"#w('--(?)!' /+'G N''*'=)-!' /+'G N'%)#+'#!&
 Nrq   c                     d a y rk   )r   r   rq   ro   _reset_clientr     s	     Grq   )betachatadminaudioevalsfilesimagesmodelsskillsvideosbatchesuploadsrealtimewebhooks	responses
containers
embeddingscompletionsfine_tuningmoderationsconversationsvector_stores)r   bool)r   r   r   )
__future__r   osr   typing_ttyping_extensionsr    r   _typesr   r   r	   r
   r   r   r   r   _utilsr   r   r   r   r   r   r   r   r   r   _httpx2r   r   r   r   _modelsr   _versionr   r   	_responser   r   
_constantsr    r!   r"   _exceptionsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   _base_clientr7   r8   r9   _utils._logsr:   _setup_logging_legacy_responser;   types.websocket_reconnectionr<   r=   __all__TYPE_CHECKING_utils._resources_proxyr@   librA   _azurerB   _bedrockrC   versionrD   	lib.azurerE   rF   lib.bedrockr>   r?   lib._old_apilib.streamingrH   rI   locals__locals__name
startswithr   	TypeErrorAttributeError_tehttpx_httpxrM   __annotations__rN   rO   rP   rQ   rR   rT   rV   rX   rZ   r[   Literal_ApiTypecastr   r   r^   r`   rb   rd   re   rf   rg   ri   r   r   r   r   r   r   r   r   _module_clientr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rq   ro   <module>r     s   #   &  a a a " v v v o o  , W W W     , \ [ 9 V R6p 
? g g ' W a 
   8 FT"	*2HV'    >  z  j  !
 !$(
! ("1	 1&S &/3, 304- 4$(! (;;:;#BGGHckkoo>O.PQ/ Q++//*>?Z ? [[__-DE
 E [[__-DE
 E>B ; B# * #?C < C|F |~ 4=- 44
{ 
9]  Rj      K
 >* 		s   )
K		KK