You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

binding.rs 1.0 kB

1234567891011121314151617181920212223242526272829303132
  1. use eyre::Context;
  2. use pyo3::prelude::*;
  3. use std::collections::{BTreeMap, HashMap};
  4. pub fn init(app: &str, function: &str) -> eyre::Result<Py<PyAny>> {
  5. pyo3::prepare_freethreaded_python();
  6. Python::with_gil(|py| {
  7. let file = py
  8. .import(app)
  9. .wrap_err("The import file was not found. Check your PYTHONPATH env variable.")?;
  10. // convert Function into a PyObject
  11. let identity = file
  12. .getattr(function)
  13. .wrap_err("The Function was not found in the imported file.")?;
  14. Ok(identity.to_object(py))
  15. })
  16. }
  17. pub async fn call(
  18. py_function: &PyObject,
  19. states: BTreeMap<String, String>,
  20. ) -> eyre::Result<HashMap<String, String>> {
  21. Python::with_gil(|py| {
  22. let args = (states.into_py(py),);
  23. let result = py_function
  24. .call(py, args, None)
  25. .wrap_err("The Python function call did not succeed.")?;
  26. result
  27. .extract(py)
  28. .wrap_err("The Python function returned an error.")
  29. })
  30. }

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed datafl