o
    -i                     @   sV   d dl mZ d dlmZ d dlmZmZmZmZ da	dd Z
dd ZG d	d
 d
ZdS )    )	Awaitable)JSONResponse)ASGIAppReceiveScopeSendFc                   C   s   t S N_scaling_elastic_ep r   r   i/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/vllm/entrypoints/serve/elastic_ep/middleware.pyget_scaling_elastic_ep   s   r   c                 C   s   | a d S r   r	   )valuer   r   r   set_scaling_elastic_ep   s   r   c                	   @   s@   e Zd ZdZdeddfddZdeded	ede	d fd
dZ
dS )ScalingMiddlewarez
    Middleware that checks if the model is currently scaling and
    returns a 503 Service Unavailable response if it is.

    This middleware applies to all HTTP requests and prevents
    processing when the model is in a scaling state.
    appreturnNc                 C   s
   || _ d S r   )r   )selfr   r   r   r   __init__   s   
zScalingMiddleware.__init__scopereceivesendc                 C   sJ   |d dkr|  |||S t rtddidd}||||S |  |||S )Ntypehttperrorz7The model is currently scaling. Please try again later.i  )contentstatus_code)r   r   r   )r   r   r   r   responser   r   r   __call__"   s   zScalingMiddleware.__call__)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r   r      s    "r   N)collections.abcr   fastapi.responsesr   starlette.typesr   r   r   r   r
   r   r   r   r   r   r   r   <module>   s   