o
    Rh`                     @  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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(m)Z) ddl*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; g dZ<G 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 ZAG d!d" d"ZBe=ZCe>ZDdS )#    )annotationsN)AnyUnionMapping)Selfoverride   )_exceptionsQuerystring)	NOT_GIVENOmitTimeoutNotGiven	TransportProxiesTypesRequestOptions)is_given
is_mappingget_async_library)__version__)filesimagesmodelsbatches
embeddingscompletionsmoderations)StreamAsyncStream)OpenAIErrorAPIStatusError)DEFAULT_MAX_RETRIESSyncAPIClientAsyncAPIClient)beta)chat)audio)uploads)	responses)fine_tuning)vector_stores)r   r   r   r   OpenAIAsyncOpenAIClientAsyncClientc                      P  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< ded< ded< ded< ded< ded< ded< ded< ded< ded < d!ed"< d#ed$< d#ed%< d&ed'< 	 d(d(d(d(d(eed(d(d(d)d*dW fd:d;ZeedXd=d>Z	eedYd@dAZ
eedZ fdCdDZd(d(d(d(d(ed(ed(d(d(d(i dEd[dMdNZeZed\dUdVZ  ZS )]r,   zcompletions.Completionsr   z	chat.Chatr&   zembeddings.Embeddingsr   zfiles.Filesr   zimages.Imagesr   zaudio.Audior'   zmoderations.Moderationsr   zmodels.Modelsr   zfine_tuning.FineTuningr*   zvector_stores.VectorStoresr+   z	beta.Betar%   zbatches.Batchesr   zuploads.Uploadsr(   zresponses.Responsesr)   OpenAIWithRawResponsewith_raw_responseOpenAIWithStreamedResponsewith_streaming_responsestrapi_key
str | Noneorganizationprojectstr | httpx.URL | Nonewebsocket_base_urlNFr6   r8   r9   base_urlr;   timeoutmax_retriesdefault_headersdefault_queryhttp_client_strict_response_validationr=   r>   %Union[float, Timeout, None, NotGiven]r?   intr@   Mapping[str, str] | NonerA   Mapping[str, object] | NonerB   httpx.Client | NonerC   boolreturnNonec             
     f  |du r
t jd}|du rtd|| _|du rt jd}|| _|du r,t jd}|| _|| _|du r<t jd}|du rBd}t j	t
||||
||	|d t| _t| | _t| | _t| | _t| | _t| | _t| | _t| | _t| | _t| | _t | | _t!"| | _!t#$| | _#t%&| | _%t'(| | _'t)| | _*t+| | _,dS )	aE  Construct a new synchronous OpenAI client instance.

        This automatically infers the following arguments from their corresponding environment variables if they are not provided:
        - `api_key` from `OPENAI_API_KEY`
        - `organization` from `OPENAI_ORG_ID`
        - `project` from `OPENAI_PROJECT_ID`
        NOPENAI_API_KEYThe api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variableOPENAI_ORG_IDOPENAI_PROJECT_IDOPENAI_BASE_URLhttps://api.openai.com/v1versionr=   r?   r>   rB   custom_headerscustom_queryrC   )-osenvirongetr    r6   r8   r9   r;   super__init__r   r   _default_stream_clsr   Completionsr&   Chatr   
Embeddingsr   Filesr   Imagesr'   Audior   Moderationsr   Modelsr*   
FineTuningr+   VectorStoresr%   Betar   Batchesr(   Uploadsr)   	Responsesr1   r2   r3   r4   selfr6   r8   r9   r=   r;   r>   r?   r@   rA   rB   rC   	__class__ P/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/openai/_client.pyr[   N   Z   !
zOpenAI.__init__r   c                 C  
   t ddS Nbrackets)array_formatr
   rl   ro   ro   rp   qs      
z	OpenAI.qsdict[str, str]c                 C     | j }dd| iS NAuthorizationzBearer r6   rl   r6   ro   ro   rp   auth_headers      zOpenAI.auth_headersdict[str, str | Omit]c                   sB   i t  jd| jd ur| jnt | jd ur| jnt d| jS )NfalsezX-Stainless-AsynczOpenAI-OrganizationzOpenAI-Project)rZ   r@   r8   r   r9   _custom_headersrv   rm   ro   rp   r@      s   zOpenAI.default_headersr6   r8   r9   r;   r=   r>   rB   r?   r@   set_default_headersrA   set_default_query_extra_kwargs!float | Timeout | None | NotGiven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|pX| j|p\| j	t
|trd| jn||t|rl|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>   rB   r?   r@   rA   ro   
ValueErrorr   _custom_query_clientrn   r6   r8   r9   r;   r=   
isinstancer   r>   r   r?   rl   r6   r8   r9   r;   r=   r>   rB   r?   r@   r   rA   r   r   headersparamsro   ro   rp   copy   :   
zOpenAI.copyerr_msgbodyobjectresponsehttpx.Responser!   c                C     t |r
|d|n|}|jdkrtj|||dS |jdkr&tj|||dS |jdkr3tj|||dS |jdkr@tj|||dS |jdkrMtj|||dS |jdkrZtj	|||dS |jd	krgtj
|||dS |jd
krttj|||dS t|||dS Nerrori  )r   r   i  i  i  i  i  i  i  r   rY   status_coder	   BadRequestErrorAuthenticationErrorPermissionDeniedErrorNotFoundErrorConflictErrorUnprocessableEntityErrorRateLimitErrorInternalServerErrorr!   rl   r   r   r   dataro   ro   rp   _make_status_error   $   







zOpenAI._make_status_error)r6   r7   r8   r7   r9   r7   r=   r:   r;   r:   r>   rD   r?   rE   r@   rF   rA   rG   rB   rH   rC   rI   rJ   rK   rJ   r   rJ   ry   rJ   r   )r6   r7   r8   r7   r9   r7   r;   r:   r=   r:   r>   r   rB   rH   r?   r   r@   rF   r   rF   rA   rG   r   rG   r   r   rJ   r   r   r5   r   r   r   r   rJ   r!   __name__
__module____qualname____annotations__r   r"   r[   propertyr   rw   r   r@   r   with_optionsr   __classcell__ro   ro   rm   rp   r,   /   x   
 
	V7r,   c                      r0   )]r-   zcompletions.AsyncCompletionsr   zchat.AsyncChatr&   zembeddings.AsyncEmbeddingsr   zfiles.AsyncFilesr   zimages.AsyncImagesr   zaudio.AsyncAudior'   zmoderations.AsyncModerationsr   zmodels.AsyncModelsr   zfine_tuning.AsyncFineTuningr*   zvector_stores.AsyncVectorStoresr+   zbeta.AsyncBetar%   zbatches.AsyncBatchesr   zuploads.AsyncUploadsr(   zresponses.AsyncResponsesr)   AsyncOpenAIWithRawResponser2   AsyncOpenAIWithStreamedResponser4   r5   r6   r7   r8   r9   r:   r;   NFr<   r=   r>   rD   r?   rE   r@   rF   rA   rG   rB   httpx.AsyncClient | NonerC   rI   rJ   rK   c             
     rL   )	aD  Construct a new async AsyncOpenAI client instance.

        This automatically infers the following arguments from their corresponding environment variables if they are not provided:
        - `api_key` from `OPENAI_API_KEY`
        - `organization` from `OPENAI_ORG_ID`
        - `project` from `OPENAI_PROJECT_ID`
        NrM   rN   rO   rP   rQ   rR   rS   )-rW   rX   rY   r    r6   r8   r9   r;   rZ   r[   r   r   r\   r   AsyncCompletionsr&   	AsyncChatr   AsyncEmbeddingsr   
AsyncFilesr   AsyncImagesr'   
AsyncAudior   AsyncModerationsr   AsyncModelsr*   AsyncFineTuningr+   AsyncVectorStoresr%   	AsyncBetar   AsyncBatchesr(   AsyncUploadsr)   AsyncResponsesr   r2   r   r4   rk   rm   ro   rp   r[   5  rq   zAsyncOpenAI.__init__r   c                 C  rr   rs   r
   rv   ro   ro   rp   rw     rx   zAsyncOpenAI.qsry   c                 C  rz   r{   r}   r~   ro   ro   rp   r     r   zAsyncOpenAI.auth_headersr   c                   sJ   i t  jdt  | jd ur| jnt | jd ur| jnt d| jS )Nzasync:r   )rZ   r@   r   r8   r   r9   r   rv   rm   ro   rp   r@     s   
zAsyncOpenAI.default_headersr   r   r   r   r   r   r   r   c                C  r   r   r   r   ro   ro   rp   r     r   zAsyncOpenAI.copyr   r   r   r   r   r!   c                C  r   r   r   r   ro   ro   rp   r     r   zAsyncOpenAI._make_status_error)r6   r7   r8   r7   r9   r7   r=   r:   r;   r:   r>   rD   r?   rE   r@   rF   rA   rG   rB   r   rC   rI   rJ   rK   r   r   r   )r6   r7   r8   r7   r9   r7   r;   r:   r=   r:   r>   r   rB   r   r?   r   r@   rF   r   rF   rA   rG   r   rG   r   r   rJ   r   r   r   ro   ro   rm   rp   r-     r   r-   c                   @     e Zd ZdddZdS )	r1   clientr,   rJ   rK   c                 C     t |j | _ t|j| _t|j| _t|j| _t	|j| _t
|j
| _
t|j| _t|j| _t|j| _t|j| _t|j| _t|j| _t|j| _t|j| _d S N)r   CompletionsWithRawResponser&   ChatWithRawResponser   EmbeddingsWithRawResponser   FilesWithRawResponser   ImagesWithRawResponser'   AudioWithRawResponser   ModerationsWithRawResponser   ModelsWithRawResponser*   FineTuningWithRawResponser+   VectorStoresWithRawResponser%   BetaWithRawResponser   BatchesWithRawResponser(   UploadsWithRawResponser)   ResponsesWithRawResponserl   r   ro   ro   rp   r[        zOpenAIWithRawResponse.__init__Nr   r,   rJ   rK   r   r   r   r[   ro   ro   ro   rp   r1         r1   c                   @  r   )	r   r   r-   rJ   rK   c                 C  r   r   )r   AsyncCompletionsWithRawResponser&   AsyncChatWithRawResponser   AsyncEmbeddingsWithRawResponser   AsyncFilesWithRawResponser   AsyncImagesWithRawResponser'   AsyncAudioWithRawResponser   AsyncModerationsWithRawResponser   AsyncModelsWithRawResponser*   AsyncFineTuningWithRawResponser+    AsyncVectorStoresWithRawResponser%   AsyncBetaWithRawResponser   AsyncBatchesWithRawResponser(   AsyncUploadsWithRawResponser)   AsyncResponsesWithRawResponser   ro   ro   rp   r[     r   z#AsyncOpenAIWithRawResponse.__init__Nr   r-   rJ   rK   r   ro   ro   ro   rp   r     r   r   c                   @  r   )	r3   r   r,   rJ   rK   c                 C  r   r   )r    CompletionsWithStreamingResponser&   ChatWithStreamingResponser   EmbeddingsWithStreamingResponser   FilesWithStreamingResponser   ImagesWithStreamingResponser'   AudioWithStreamingResponser    ModerationsWithStreamingResponser   ModelsWithStreamingResponser*   FineTuningWithStreamingResponser+   !VectorStoresWithStreamingResponser%   BetaWithStreamingResponser   BatchesWithStreamingResponser(   UploadsWithStreamingResponser)   ResponsesWithStreamingResponser   ro   ro   rp   r[   "  r   z#OpenAIWithStreamedResponse.__init__Nr   r   ro   ro   ro   rp   r3   !  r   r3   c                   @  r   )	r   r   r-   rJ   rK   c                 C  r   r   )r   %AsyncCompletionsWithStreamingResponser&   AsyncChatWithStreamingResponser   $AsyncEmbeddingsWithStreamingResponser   AsyncFilesWithStreamingResponser    AsyncImagesWithStreamingResponser'   AsyncAudioWithStreamingResponser   %AsyncModerationsWithStreamingResponser    AsyncModelsWithStreamingResponser*   $AsyncFineTuningWithStreamingResponser+   &AsyncVectorStoresWithStreamingResponser%   AsyncBetaWithStreamingResponser   !AsyncBatchesWithStreamingResponser(   !AsyncUploadsWithStreamingResponser)   #AsyncResponsesWithStreamingResponser   ro   ro   rp   r[   4  r   z(AsyncOpenAIWithStreamedResponse.__init__Nr   r   ro   ro   ro   rp   r   3  r   r   )E
__future__r   rW   typingr   r   r   typing_extensionsr   r   httpx r	   _qsr   _typesr   r   r   r   r   r   r   _utilsr   r   r   _versionr   	resourcesr   r   r   r   r   r   r   
_streamingr   r   r    r!   _base_clientr"   r#   r$   resources.betar%   resources.chatr&   resources.audior'   resources.uploadsr(   resources.responsesr)   resources.fine_tuningr*   resources.vector_storesr+   __all__r,   r-   r1   r   r3   r   r.   r/   ro   ro   ro   rp   <module>   s@   $	$ h h