o
    ØRWj5  ã                   @  s|   d dl mZ d dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
Z
d dlZd dlZ
edƒZe	dƒZddd„Zddd„ZdS )é    )ÚannotationsN)ÚTypeVarÚCallableÚ	Awaitable)Ú	ParamSpecÚT_RetvalÚT_ParamSpecÚfuncúCallable[T_ParamSpec, T_Retval]ÚargsúT_ParamSpec.argsÚkwargsúT_ParamSpec.kwargsÚreturnc                Ï  sR   �t  ¡ dkrtj| g|¢R i |¤ŽI d H S tj tj| g|¢R i |¤Ž¡I d H S )NÚasyncio)ÚsniffioÚcurrent_async_libraryr   Ú	to_threadÚanyioÚrun_syncÚ	functoolsÚpartial)r	   r   r   © r   úb/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/openai/_utils/_sync.pyr      s   €
ÿr   Úfunctionú*Callable[T_ParamSpec, Awaitable[T_Retval]]c                   s   d
‡ fdd„}|S )ac  
    Take a blocking function and create an async one that receives the same
    positional and keyword arguments.

    Usage:

    ```python
    def blocking_func(arg1, arg2, kwarg1=None):
        # blocking code
        return result


    result = asyncify(blocking_function)(arg1, arg2, kwarg1=value1)
    ```

    ## Arguments

    `function`: a blocking regular callable (e.g. a function)

    ## Return

    An async function that takes the same positional and keyword arguments as the
    original one, that when called runs the same original function in a thread worker
    and returns the result.
    r   r   r   r   r   r   c                  Ÿ  s   �t ˆ g| ¢R i |¤ŽI d H S )N)r   )r   r   ©r   r   r   Úwrapper7   s   €zasyncify.<locals>.wrapperN)r   r   r   r   r   r   r   )r   r   r   r   r   Úasyncify   s   r   )r	   r
   r   r   r   r   r   r   )r   r
   r   r   )Ú
__future__r   r   r   Útypingr   r   r   Útyping_extensionsr   r   r   Úanyio.to_threadr   r   r   r   r   r   r   r   Ú<module>   s    
