Skip to content

Commit c5d9d26

Browse files
authored
feat(frontend): support setting HTTP host via CLI (--http-host) (#2523)
1 parent 6bc6d40 commit c5d9d26

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

components/frontend/src/dynamo/frontend/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ def parse_args():
8787
parser.add_argument(
8888
"--kv-cache-block-size", type=int, help="KV cache block size (u32)."
8989
)
90+
parser.add_argument(
91+
"--http-host",
92+
type=str,
93+
default=os.environ.get("DYN_HTTP_HOST", "0.0.0.0"),
94+
help="HTTP host for the engine (str). Can be set via DYN_HTTP_HOST env var.",
95+
)
9096
parser.add_argument(
9197
"--http-port",
9298
type=int,
@@ -209,6 +215,7 @@ async def async_main():
209215
kv_router_config = None
210216

211217
kwargs = {
218+
"http_host": flags.http_host,
212219
"http_port": flags.http_port,
213220
"kv_cache_block_size": flags.kv_cache_block_size,
214221
"router_config": RouterConfig(

lib/bindings/python/rust/llm/entrypoint.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub(crate) struct EntrypointArgs {
102102
template_file: Option<PathBuf>,
103103
router_config: Option<RouterConfig>,
104104
kv_cache_block_size: Option<u32>,
105+
http_host: Option<String>,
105106
http_port: u16,
106107
tls_cert_path: Option<PathBuf>,
107108
tls_key_path: Option<PathBuf>,
@@ -112,7 +113,7 @@ pub(crate) struct EntrypointArgs {
112113
impl EntrypointArgs {
113114
#[allow(clippy::too_many_arguments)]
114115
#[new]
115-
#[pyo3(signature = (engine_type, model_path=None, model_name=None, model_config=None, endpoint_id=None, context_length=None, template_file=None, router_config=None, kv_cache_block_size=None, http_port=None, tls_cert_path=None, tls_key_path=None, extra_engine_args=None))]
116+
#[pyo3(signature = (engine_type, model_path=None, model_name=None, model_config=None, endpoint_id=None, context_length=None, template_file=None, router_config=None, kv_cache_block_size=None, http_host=None, http_port=None, tls_cert_path=None, tls_key_path=None, extra_engine_args=None))]
116117
pub fn new(
117118
engine_type: EngineType,
118119
model_path: Option<PathBuf>,
@@ -123,6 +124,7 @@ impl EntrypointArgs {
123124
template_file: Option<PathBuf>,
124125
router_config: Option<RouterConfig>,
125126
kv_cache_block_size: Option<u32>,
127+
http_host: Option<String>,
126128
http_port: Option<u16>,
127129
tls_cert_path: Option<PathBuf>,
128130
tls_key_path: Option<PathBuf>,
@@ -153,6 +155,7 @@ impl EntrypointArgs {
153155
template_file,
154156
router_config,
155157
kv_cache_block_size,
158+
http_host,
156159
http_port: http_port.unwrap_or(DEFAULT_HTTP_PORT),
157160
tls_cert_path,
158161
tls_key_path,
@@ -184,6 +187,7 @@ pub fn make_engine<'p>(
184187
.request_template(args.template_file.clone())
185188
.kv_cache_block_size(args.kv_cache_block_size)
186189
.router_config(args.router_config.clone().map(|rc| rc.into()))
190+
.http_host(args.http_host.clone())
187191
.http_port(args.http_port)
188192
.tls_cert_path(args.tls_cert_path.clone())
189193
.tls_key_path(args.tls_key_path.clone())

lib/llm/src/entrypoint/input/http.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pub async fn run(runtime: Runtime, engine_config: EngineConfig) -> anyhow::Resul
4545
);
4646
}
4747
};
48+
if let Some(http_host) = local_model.http_host() {
49+
http_service_builder = http_service_builder.host(http_host);
50+
}
4851
http_service_builder =
4952
http_service_builder.with_request_template(engine_config.local_model().request_template());
5053

lib/llm/src/local_model.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct LocalModelBuilder {
5050
template_file: Option<PathBuf>,
5151
router_config: Option<RouterConfig>,
5252
kv_cache_block_size: u32,
53+
http_host: Option<String>,
5354
http_port: u16,
5455
tls_cert_path: Option<PathBuf>,
5556
tls_key_path: Option<PathBuf>,
@@ -64,6 +65,7 @@ impl Default for LocalModelBuilder {
6465
fn default() -> Self {
6566
LocalModelBuilder {
6667
kv_cache_block_size: DEFAULT_KV_CACHE_BLOCK_SIZE,
68+
http_host: Default::default(),
6769
http_port: DEFAULT_HTTP_PORT,
6870
tls_cert_path: Default::default(),
6971
tls_key_path: Default::default(),
@@ -115,6 +117,11 @@ impl LocalModelBuilder {
115117
self
116118
}
117119

120+
pub fn http_host(&mut self, host: Option<String>) -> &mut Self {
121+
self.http_host = host;
122+
self
123+
}
124+
118125
pub fn http_port(&mut self, port: u16) -> &mut Self {
119126
self.http_port = port;
120127
self
@@ -200,6 +207,7 @@ impl LocalModelBuilder {
200207
full_path: PathBuf::new(),
201208
endpoint_id,
202209
template,
210+
http_host: self.http_host.take(),
203211
http_port: self.http_port,
204212
tls_cert_path: self.tls_cert_path.take(),
205213
tls_key_path: self.tls_key_path.take(),
@@ -275,6 +283,7 @@ impl LocalModelBuilder {
275283
full_path,
276284
endpoint_id,
277285
template,
286+
http_host: self.http_host.take(),
278287
http_port: self.http_port,
279288
tls_cert_path: self.tls_cert_path.take(),
280289
tls_key_path: self.tls_key_path.take(),
@@ -290,6 +299,7 @@ pub struct LocalModel {
290299
card: ModelDeploymentCard,
291300
endpoint_id: EndpointId,
292301
template: Option<RequestTemplate>,
302+
http_host: Option<String>,
293303
http_port: u16,
294304
tls_cert_path: Option<PathBuf>,
295305
tls_key_path: Option<PathBuf>,
@@ -321,6 +331,10 @@ impl LocalModel {
321331
self.template.clone()
322332
}
323333

334+
pub fn http_host(&self) -> Option<String> {
335+
self.http_host.clone()
336+
}
337+
324338
pub fn http_port(&self) -> u16 {
325339
self.http_port
326340
}

0 commit comments

Comments
 (0)