"vscode:/vscode.git/clone" did not exist on "5c0de09a075ec36b96a0a4609b748c4cb9b59744"
lib.rs 1012 Bytes
Newer Older
1
2
use pyo3::prelude::*;
pub mod router;
3
4
mod server;
pub mod tree;
5
6
7
8
9
10
11

// Python binding
#[pyclass]
struct Router {
    host: String,
    port: u16,
    worker_urls: Vec<String>,
12
    policy: String,
13
14
15
16
17
18
19
20
21
22
}

#[pymethods]
impl Router {
    #[new]
    fn new(host: String, port: u16, worker_urls: Vec<String>, policy: String) -> Self {
        Router {
            host,
            port,
            worker_urls,
23
            policy,
24
25
26
27
28
29
30
31
32
33
        }
    }

    fn start(&self) -> PyResult<()> {
        let host = self.host.clone();
        let port = self.port;
        let worker_urls = self.worker_urls.clone();
        let policy = self.policy.clone();

        actix_web::rt::System::new().block_on(async move {
34
35
36
            server::startup(host, port, worker_urls, policy)
                .await
                .unwrap();
37
38
39
40
41
42
43
44
45
46
47
        });

        Ok(())
    }
}

// python usage: `from sglang_router import Router`
#[pymodule]
fn sglang_router(m: &Bound<'_, PyModule>) -> PyResult<()> {
    m.add_class::<Router>()?;
    Ok(())
48
}