"launch/dynamo-run/vscode:/vscode.git/clone" did not exist on "03c160afd989817f8377a2a2b4b413799662d06f"
main.rs 2.42 KB
Newer Older
Ryan Olson's avatar
Ryan Olson committed
1
2
3
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

4
use clap::Parser;
5
use std::sync::Arc;
Ryan Olson's avatar
Ryan Olson committed
6

7
use dynamo_llm::http::service::{discovery::ModelWatcher, service_v2::HttpService};
Neelay Shah's avatar
Neelay Shah committed
8
use dynamo_runtime::{
9
10
    component, logging, pipeline::RouterMode, transports::etcd::PrefixWatcher, DistributedRuntime,
    Result, Runtime, Worker,
Ryan Olson's avatar
Ryan Olson committed
11
12
};

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Args {
    /// Host for the HTTP service
    #[arg(long, default_value = "0.0.0.0")]
    host: String,

    /// Port number for the HTTP service
    #[arg(short, long, default_value = "8080")]
    port: u16,

    /// Namespace for the distributed component
    #[arg(long, default_value = "public")]
    namespace: String,

    /// Component name for the service
    #[arg(long, default_value = "http")]
    component: String,
}

33
34
#[tokio::main]
async fn main() -> Result<()> {
Ryan Olson's avatar
Ryan Olson committed
35
    logging::init();
36
37
    let worker = Worker::from_current()?;
    worker.execute_async(app).await
Ryan Olson's avatar
Ryan Olson committed
38
39
40
41
}

async fn app(runtime: Runtime) -> Result<()> {
    let distributed = DistributedRuntime::from_settings(runtime.clone()).await?;
42
43
44
45
46
47
    let args = Args::parse();

    let http_service = HttpService::builder()
        .port(args.port)
        .host(args.host)
        .build()?;
Ryan Olson's avatar
Ryan Olson committed
48
49
50
51
52
53
54
55
56
57
    let manager = http_service.model_manager().clone();

    // todo - use the IntoComponent trait to register the component
    // todo - start a service
    // todo - we want the service to create an entry and register component definition
    // todo - the component definition should be the type of component and it's config
    // in this example we will have an HttpServiceComponentDefinition object which will be
    // written to etcd
    // the cli when operating on an `http` component will validate the namespace.component is
    // registered with HttpServiceComponentDefinition
58

59
60
61
    let watch_obj = Arc::new(
        ModelWatcher::new(distributed.clone(), manager.clone(), RouterMode::Random).await?,
    );
Ryan Olson's avatar
Ryan Olson committed
62

63
64
65
66
    if let Some(etcd_client) = distributed.etcd_client() {
        let models_watcher: PrefixWatcher = etcd_client
            .kv_get_and_watch_prefix(component::MODEL_ROOT_PATH)
            .await?;
67

68
69
        let (_prefix, _watcher, receiver) = models_watcher.dissolve();
        tokio::spawn(watch_obj.watch(receiver));
70
    }
Ryan Olson's avatar
Ryan Olson committed
71

72
    // Run the service
Ryan Olson's avatar
Ryan Olson committed
73
74
    http_service.run(runtime.child_token()).await
}