o
    +i5                     @  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   F/var/www/html/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    
