Skip to content

Commit

Permalink
remove a whole bunch of unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
sxlijin committed Dec 4, 2024
1 parent b37f1a8 commit 951d1e7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 83 deletions.
1 change: 0 additions & 1 deletion engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion engine/language_client_python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ tracing-subscriber = { version = "0.3.18", features = [
"env-filter",
"valuable",
] }
valuable = { version = "0.1.0", features = ["derive"] }

[build-dependencies]
pyo3-build-config = "0.21.2"
62 changes: 0 additions & 62 deletions engine/language_client_python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,6 @@ fn invoke_runtime_cli(py: Python) -> PyResult<()> {
)
.map_err(errors::BamlError::from_anyhow)
}
#[pyo3::prelude::pyclass(module = "baml_py.baml_py")]
pub struct LoremIpsum {
#[allow(dead_code)]
pub(crate) inner: String,
}

#[pyo3::prelude::pymethods]
impl LoremIpsum {
#[new]
pub fn new() -> Self {
Self {
inner: "Lorem ipsum dolor sit amet".to_string(),
}
}

// pub fn __getnewargs__<'py>(
// &self,
// py: Python<'py>,
// ) -> PyResult<Bound<'py, pyo3::types::PyTuple>> {
// println!("__getnewargs__ LoremIpsum placeholder");
// Ok(pyo3::types::PyTuple::empty_bound(py))
// }

#[classmethod]
pub fn __get_pydantic_core_schema__(
_cls: Bound<'_, pyo3::types::PyType>,
_source_type: Bound<'_, pyo3::types::PyAny>,
_handler: Bound<'_, pyo3::types::PyAny>,
) -> PyResult<pyo3::PyObject> {
Python::with_gil(|py| {
let code = r#"
from pydantic_core import core_schema, SchemaValidator
ret = core_schema.str_schema()
"#;
// py.run(code, None, Some(ret_dict));
let fun: pyo3::Py<pyo3::types::PyAny> =
PyModule::from_code_bound(py, code, "pretend-file", "pretend-module")?
.getattr("ret")?
.into();
use pyo3::ToPyObject;
Ok(fun.to_object(py))
})
}
}

pub(crate) const MODULE_NAME: &str = "baml_py.baml_py";

Expand Down Expand Up @@ -99,8 +54,6 @@ fn baml_py(m: Bound<'_, PyModule>) -> PyResult<()> {
}
}

m.add_class::<LoremIpsum>()?;

m.add_class::<runtime::BamlRuntime>()?;

m.add_class::<types::FunctionResult>()?;
Expand All @@ -123,22 +76,7 @@ fn baml_py(m: Bound<'_, PyModule>) -> PyResult<()> {

m.add_wrapped(wrap_pyfunction!(invoke_runtime_cli))?;

// m.add(
// "BamlValidationError",
// m.py().get_type_bound::<errors::BamlValidationError>(),
// )?;
// m.add_class::<errors::BamlValidationError>()?;
errors::errors(&m)?;

Ok(())
}

mod test {
#[test]
fn test_inspect() {
assert_eq!(
crate::MODULE_NAME,
format!("baml_py.{}", stringify!(baml_asdfpy))
);
}
}
16 changes: 15 additions & 1 deletion engine/language_client_python/src/types/audio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use baml_types::BamlMediaContent;
use pyo3::prelude::{pymethods, PyResult};
use pyo3::types::PyType;
use pyo3::types::{PyTuple, PyType};
use pyo3::{Bound, PyAny, PyObject, Python};
use pythonize::{depythonize_bound, pythonize};

Expand Down Expand Up @@ -50,6 +50,20 @@ impl BamlAudioPy {
}
}

/// Defines the default constructor: https://pyo3.rs/v0.23.3/class#constructor
///
/// Used for `pickle.load`: https://docs.python.org/3/library/pickle.html#object.__getnewargs__
#[new]
pub fn py_new(data: PyObject, py: Python<'_>) -> PyResult<Self> {
Self::baml_deserialize(data, py)
}

/// Used for `pickle.dump`: https://docs.python.org/3/library/pickle.html#object.__getnewargs__
pub fn __getnewargs__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyTuple>> {
let o = self.baml_serialize(py)?;
Ok(PyTuple::new_bound(py, vec![o]))
}

pub fn __repr__(&self) -> String {
match &self.inner.content {
BamlMediaContent::Url(url) => {
Expand Down
24 changes: 8 additions & 16 deletions engine/language_client_python/src/types/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,18 @@ impl BamlImagePy {
}
}

// pub fn __setstate__(&mut self, state: PyObject, py: Python<'_>) -> PyResult<()> {
// log::info!("Setting state");
// *self = BamlImagePy::baml_deserialize(state, py)?;
// Ok(())
// }

// pub fn __getstate__(&self, py: Python<'_>) -> PyResult<PyObject> {
// log::info!("Getting state");
// self.baml_serialize(py)
// }

/// Defines the default constructor: https://pyo3.rs/v0.23.3/class#constructor
///
/// Used for `pickle.load`: https://docs.python.org/3/library/pickle.html#object.__getnewargs__
#[new]
pub fn py_new(_py: Python<'_>) -> PyResult<Self> {
Ok(BamlImagePy::from_url(
"https://example.com/screenshot.png".to_string(),
))
pub fn py_new(data: PyObject, py: Python<'_>) -> PyResult<Self> {
Self::baml_deserialize(data, py)
}

/// Used for `pickle.dump`: https://docs.python.org/3/library/pickle.html#object.__getnewargs__
pub fn __getnewargs__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyTuple>> {
Ok(PyTuple::empty_bound(py))
let o = self.baml_serialize(py)?;
Ok(PyTuple::new_bound(py, vec![o]))
}

pub fn __repr__(&self) -> String {
Expand Down
3 changes: 3 additions & 0 deletions engine/language_client_python/src/types/media_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ impl TryInto<UserFacingBamlMedia> for &BamlMedia {
/// can't implement this in internal_monkeypatch without adding a hard dependency
/// on pydantic. And we don't want to do _that_, because that will make it harder
/// to implement output_type python/vanilla in the future.
///
/// See docs:
/// https://docs.pydantic.dev/latest/concepts/types/#customizing-validation-with-__get_pydantic_core_schema__
pub fn __get_pydantic_core_schema__(
_cls: Bound<'_, PyType>,
_source_type: Bound<'_, PyAny>,
Expand Down
2 changes: 0 additions & 2 deletions typescript/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"version": "0.2.0",
"configurations": [


{
"name": "Launch VS Code extension",
"type": "extensionHost",
Expand Down

0 comments on commit 951d1e7

Please sign in to comment.