ray.serve.get_multiplexed_model_id#

ray.serve.get_multiplexed_model_id() str[源代码]#

获取当前请求的多路复用模型ID。

这用于带有 @serve.multiplexed 装饰器的函数,以检索当前请求的模型 ID。

import ray
from ray import serve
import requests

# Set the multiplexed model id with the key
# "ray_serve_multiplexed_model_id" in the request
# headers when sending requests to the http proxy.
requests.get("http://localhost:8000",
    headers={"ray_serve_multiplexed_model_id": "model_1"})

# This can also be set when using `DeploymentHandle`.
handle.options(multiplexed_model_id="model_1").remote("blablabla")

# In your deployment code, you can retrieve the model id from
# `get_multiplexed_model_id()`.
@serve.deployment
def my_deployment_function(request):
    assert serve.get_multiplexed_model_id() == "model_1"

PublicAPI (测试版): 此API目前处于测试阶段,在成为稳定版本之前可能会发生变化。