o
    0j                     @   sH   d dl Z d dlZd dlZd dlZd dlZd dlZddlmZ dd ZdS )    N   )require_genai_engine_pluginc           
   	   C   s   t d t| ||||t|d}tdt| d}tjdddd}|	| |j
}	W d    n1 s8w   Y  zttj|	g W t|	 d S t|	 w )	Nzsglang-server)hostport
model_name	model_dirconfigchat_template_patha  
    import json
    import os

    from paddlex.inference.genai.configs.utils import (
        backend_config_to_args,
        set_config_defaults,
        update_backend_config,
    )
    from paddlex.inference.genai.models import get_model_components, is_integrated_model_available
    from sglang.srt.configs.model_config import multimodal_model_archs
    from sglang.srt.entrypoints.http_server import launch_server
    from sglang.srt.managers.multimodal_processor import PROCESSOR_MAPPING
    from sglang.srt.models.registry import ModelRegistry
    from sglang.srt.server_args import prepare_server_args
    from sglang.srt.utils import kill_process_tree

    data = json.loads(a  )

    host = data["host"]
    port = data["port"]
    model_name = data["model_name"]
    model_dir = data["model_dir"]
    config = data["config"]
    chat_template_path = data["chat_template_path"]

    if not is_integrated_model_available(model_name, "sglang"):
        network_class, processor_class = get_model_components(model_name, "sglang")

        ModelRegistry.models[network_class.__name__] = network_class
        multimodal_model_archs.append(network_class.__name__)
        PROCESSOR_MAPPING[network_class] = processor_class

    set_config_defaults(config, {"served-model-name": model_name})

    if chat_template_path:
        set_config_defaults(config, {"chat-template": chat_template_path})

    set_config_defaults(config, {"enable-metrics": True})

    update_backend_config(
        config,
        {
            "model-path": model_dir,
            "host": host,
            "port": port,
        },
    )

    if __name__ == "__main__":
        args = backend_config_to_args(config)

        server_args = prepare_server_args(args)

        try:
            launch_server(server_args)
        finally:
            kill_process_tree(os.getpid(), include_parent=False)
    wz.pyF)suffixdelete)r   jsondumpsstrtextwrapdedentreprtempfileNamedTemporaryFilewritename
subprocess
check_callsys
executableosunlink)
r   r   r   r   r   r	   datacodefZscript_path r    h/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/genai/backends/sglang.pyrun_sglang_server   s,   >
r"   )	r   r   r   r   r   r   Z
utils.depsr   r"   r    r    r    r!   <module>   s   