MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / analyze

Function analyze

flow-plugins/src/bytes_server.rs:45–75  ·  view source on GitHub ↗
(#[data] state: State, #[body] body: Bytes)

Source from the content-addressed store, hash-verified

43#[post("/analyze/bytes")]
44#[openapi(summary = "analyze user define bytes")]
45async fn analyze(#[data] state: State, #[body] body: Bytes) -> Result<impl Reply, Rejection> {
46 let id = state.id();
47
48 let pyobject: PyObject = Python::with_gil(|py| -> PyResult<_> {
49 let ndarray = body.to_pyarray(py);
50
51 Ok([("data", ndarray.to_object(py))].into_py_dict(py).into())
52 })
53 .map_err(reject_cause)?;
54
55 let r = {
56 let (s, r) = oneshot::channel();
57 state.mapping.lock().await.insert(id, s);
58 let envelope = Envelope::with_info(
59 pyobject,
60 EnvelopeInfo {
61 partial_id: Some(id),
62 ..Default::default()
63 },
64 );
65 state.out.send(envelope).await.ok();
66 r
67 };
68 let message = r.await.map_err(reject_cause)?;
69 Python::with_gil(|py| -> PyResult<_> {
70 let dict: &PyDict = message.extract(py)?;
71 flow_rs::helper::uget_slice(py, dict.get_item("data").expect("error key<data>"))
72 })
73 .map_err(reject_cause)
74 .map(|data| RwebBytes::new(&(data.to_vec())))
75}
76
77impl BytesServer {
78 fn new(_: String, args: &Table) -> BytesServer {

Callers 1

execMethod · 0.70

Calls 7

uget_sliceFunction · 0.85
into_py_dictMethod · 0.80
to_objectMethod · 0.80
insertMethod · 0.80
to_vecMethod · 0.80
idMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected