diff --git a/Cargo.toml b/Cargo.toml index cfecd33..950547f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nova-python" -version = "0.1.1" +version = "0.1.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 8701a01..9d3a1d7 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,12 @@ client.make_request( If everything goes to plan, you'll receive a string containing JSON-Data, which you can then use in your project. *Happy prompting!* - +

## FAQ ## **Q:** I get an error when installing the package **A:** Make you sure, that you have Cargo installed +**Q**: I keep getting `RuntimeError: error sending request for url (https://api.nova-oss.com/v1/moderations): operation timed out` +**A**: Try passing a higher value than 30 as `seconds_until_timeout` to `make_request` + Made with 🩸 by Leander \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 38a6540..235bd4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,8 @@ classifiers = [ "Programming Language :: Python :: Implementation :: PyPy", ] -repository = "https://github.com/NovaOSS/nova-python" +[project.urls] +"Repo" = "https://github.com/henceiusegentoo/nova-python" [tool.maturin] features = ["pyo3/extension-module"] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2d003a1..42182db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use pyo3::types::PyDict; use std::time; +// An enum to represent the different models #[pyclass(module = "nova_python", frozen)] #[derive(PartialEq)] #[derive(Clone)] @@ -17,6 +18,7 @@ enum Models { ModerationStable, } +// An enum to represent the different endpoints #[pyclass(module = "nova_python", frozen)] #[derive(PartialEq)] #[derive(Clone)] @@ -27,6 +29,7 @@ enum Endpoints { Moderation, } +// Interface to the Nova API #[pyclass(module = "nova_python", frozen)] struct NovaClient { #[pyo3(get)] @@ -50,7 +53,8 @@ impl NovaClient { }) } - fn make_request(&self, endpoint: Endpoints, model: Models, data: Vec>) -> PyResult { + // Used to make a request to the Nova API + fn make_request(&self, endpoint: Endpoints, model: Models, data: Vec>, seconds_until_timeout: Option) -> PyResult { if !model_is_compatible(&endpoint, &model) { return Err(NovaClient::get_endpoint_not_compatible_error()); } @@ -59,10 +63,14 @@ impl NovaClient { let request_body = self.get_request_body(&endpoint, &model, data).unwrap(); let rt = tokio::runtime::Runtime::new().unwrap(); - + let seconds_until_timeout = match seconds_until_timeout { + Some(seconds_until_timeout) => seconds_until_timeout.parse::().unwrap(), + None => 30 + }; + let response: Result = rt.block_on(async { let client = reqwest::Client::builder() - .timeout(time::Duration::from_secs(10)) + .timeout(time::Duration::from_secs(seconds_until_timeout)) .user_agent("Mozilla/5.0") .build() .unwrap();