U
    ·ÜŸj/  ã                   @  sP  d dl mZ d dlZd dlZd dlmZmZmZmZ d dl	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 dd	l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$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddg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ƒZ0G dd„ dƒZ1dS )é    )ÚannotationsN)ÚListÚUnionÚIterableÚcast)ÚLiteralé   )Ú_legacy_response)Úembedding_create_params)Ú	NOT_GIVENÚBodyÚQueryÚHeadersÚNotGiven)Úis_givenÚmaybe_transform)Úcached_property)ÚnumpyÚ	has_numpy)ÚSyncAPIResourceÚAsyncAPIResource)Úto_streamed_response_wrapperÚ"async_to_streamed_response_wrapper)Úmake_request_options)ÚEmbeddingModel)ÚCreateEmbeddingResponseÚ
EmbeddingsÚAsyncEmbeddingsc                   @  sb   e Zd Zeddœdd„ƒZeddœdd„ƒZeeeddded	œd
ddddddddddœ
dd„ZdS )r   ÚEmbeddingsWithRawResponse©Úreturnc                 C  s   t | ƒS ©a  
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
        )r   ©Úself© r$   ú?/tmp/pip-unpacked-wheel-2qj3ofc_/openai/resources/embeddings.pyÚwith_raw_response   s    zEmbeddings.with_raw_responseÚEmbeddingsWithStreamingResponsec                 C  s   t | ƒS ©zÌ
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/openai/openai-python#with_streaming_response
        )r'   r"   r$   r$   r%   Úwith_streaming_response&   s    z"Embeddings.with_streaming_responseN©Ú
dimensionsÚencoding_formatÚuserÚextra_headersÚextra_queryÚ
extra_bodyÚtimeoutú=Union[str, List[str], Iterable[int], Iterable[Iterable[int]]]úUnion[str, EmbeddingModel]úint | NotGivenú'Literal[('float', 'base64')] | NotGivenústr | NotGivenúHeaders | NoneúQuery | NoneúBody | Noneú'float | httpx.Timeout | None | NotGivenr   ©
ÚinputÚmodelr+   r,   r-   r.   r/   r0   r1   r    c       	      
     s\   ||||ˆ dœ}
t ˆ ƒs d|
d< dddœ‡ fdd„}| jdt|
tjƒt||||	|d	�td
�S )ác  
        Creates an embedding vector representing the input text.

        Args:
          input: Input text to embed, encoded as a string or array of tokens. To embed multiple
              inputs in a single request, pass an array of strings or array of token arrays.
              The input must not exceed the max input tokens for the model (8192 tokens for
              `text-embedding-ada-002`), cannot be an empty string, and any array must be 2048
              dimensions or less.
              [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
              for counting tokens. Some models may also impose a limit on total number of
              tokens summed across inputs.

          model: ID of the model to use. You can use the
              [List models](https://platform.openai.com/docs/api-reference/models/list) API to
              see all of your available models, or see our
              [Model overview](https://platform.openai.com/docs/models) for descriptions of
              them.

          dimensions: The number of dimensions the resulting output embeddings should have. Only
              supported in `text-embedding-3` and later models.

          encoding_format: The format to return the embeddings in. Can be either `float` or
              [`base64`](https://pypi.org/project/pybase64/).

          user: A unique identifier representing your end-user, which can help OpenAI to monitor
              and detect abuse.
              [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        ©r<   r=   r-   r+   r,   Úbase64r,   r   ©Úobjr    c                   sn   t ˆ ƒr| S | jD ]V}tt|jƒ}t|tƒs.qtƒ sNt dt	 
|¡¡ ¡ |_qtjt	 
|¡dd� ¡ |_q| S ©NÚfZfloat32)Zdtype©r   Údatar   ÚobjectÚ	embeddingÚ
isinstanceÚstrr   Úarrayr@   Ú	b64decodeÚtolistÚnpZ
frombuffer©rB   rH   rF   ©r,   r$   r%   Úparserm   s    

 ÿz!Embeddings.create.<locals>.parserú/embeddings©r.   r/   r0   r1   Zpost_parser©ÚbodyÚoptionsZcast_to©r   Ú_postr   r
   ZEmbeddingCreateParamsr   r   ©r#   r<   r=   r+   r,   r-   r.   r/   r0   r1   ÚparamsrQ   r$   rP   r%   Úcreate/   s*    5û
ûözEmbeddings.create©Ú__name__Ú
__module__Ú__qualname__r   r&   r)   r   r[   r$   r$   r$   r%   r      s   	óc                   @  sb   e Zd Zeddœdd„ƒZeddœdd„ƒZeeeddded	œd
ddddddddddœ
dd„ZdS )r   ÚAsyncEmbeddingsWithRawResponser   c                 C  s   t | ƒS r!   )r`   r"   r$   r$   r%   r&   �   s    z!AsyncEmbeddings.with_raw_responseÚ$AsyncEmbeddingsWithStreamingResponsec                 C  s   t | ƒS r(   )ra   r"   r$   r$   r%   r)   ™   s    z'AsyncEmbeddings.with_streaming_responseNr*   r2   r3   r4   r5   r6   r7   r8   r9   r:   r   r;   c       	      
   ƒ  sb   ||||ˆ dœ}
t ˆ ƒs d|
d< dddœ‡ fdd„}| jdt|
tjƒt||||	|d	�td
�I dH S )r>   r?   r@   r,   r   rA   c                   sn   t ˆ ƒr| S | jD ]V}tt|jƒ}t|tƒs.qtƒ sNt dt	 
|¡¡ ¡ |_qtjt	 
|¡dd� ¡ |_q| S rC   rE   rO   rP   r$   r%   rQ   à   s    

 ÿz&AsyncEmbeddings.create.<locals>.parserrR   rS   rT   NrW   rY   r$   rP   r%   r[   ¢   s*    5û
ûözAsyncEmbeddings.creater\   r$   r$   r$   r%   r   Ž   s   	óc                   @  s   e Zd Zdddœdd„ZdS )r   r   ÚNone©Ú
embeddingsr    c                 C  s   || _ t |j¡| _d S ©N)Ú_embeddingsr	   Zto_raw_response_wrapperr[   ©r#   rd   r$   r$   r%   Ú__init__  s    ÿz"EmbeddingsWithRawResponse.__init__N©r]   r^   r_   rh   r$   r$   r$   r%   r     s   r   c                   @  s   e Zd Zdddœdd„ZdS )r`   r   rb   rc   c                 C  s   || _ t |j¡| _d S re   )rf   r	   Zasync_to_raw_response_wrapperr[   rg   r$   r$   r%   rh     s    ÿz'AsyncEmbeddingsWithRawResponse.__init__Nri   r$   r$   r$   r%   r`   
  s   r`   c                   @  s   e Zd Zdddœdd„ZdS )r'   r   rb   rc   c                 C  s   || _ t|jƒ| _d S re   )rf   r   r[   rg   r$   r$   r%   rh     s    ÿz(EmbeddingsWithStreamingResponse.__init__Nri   r$   r$   r$   r%   r'     s   r'   c                   @  s   e Zd Zdddœdd„ZdS )ra   r   rb   rc   c                 C  s   || _ t|jƒ| _d S re   )rf   r   r[   rg   r$   r$   r%   rh     s    ÿz-AsyncEmbeddingsWithStreamingResponse.__init__Nri   r$   r$   r$   r%   ra     s   ra   )2Ú
__future__r   rK   r@   Útypingr   r   r   r   Útyping_extensionsr   ZhttpxÚ r	   Útypesr
   Ú_typesr   r   r   r   r   Ú_utilsr   r   Ú_compatr   Z_extrasr   rN   r   Z	_resourcer   r   Ú	_responser   r   Z_base_clientr   Ztypes.embedding_modelr   Ztypes.create_embedding_responser   Ú__all__r   r   r   r`   r'   ra   r$   r$   r$   r%   Ú<module>   s.   ss			