Skip to content

Commit

Permalink
feat(python): allow setting bandits configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rasendubi committed Sep 27, 2024
1 parent 9228416 commit 1d73256
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions python-sdk/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ pub struct Configuration {
#[pymethods]
impl Configuration {
#[new]
#[pyo3(signature = (*, flags_configuration))]
fn py_new(flags_configuration: &[u8]) -> PyResult<Configuration> {
#[pyo3(signature = (*, flags_configuration, bandits_configuration = None))]
fn py_new(
flags_configuration: &[u8],
bandits_configuration: Option<&[u8]>,
) -> PyResult<Configuration> {
let flag_config = serde_json::from_slice(flags_configuration).map_err(|err| {
PyValueError::new_err(format!("argument 'flags_configuration': {err:?}"))
})?;
let bandits_config = bandits_configuration
.map(|it| serde_json::from_slice(it))
.transpose()
.map_err(|err| {
PyValueError::new_err(format!("argument 'bandits_configuration': {err:?}"))
})?;
Ok(Configuration {
configuration: Arc::new(CoreConfiguration::from_server_response(flag_config, None)),
configuration: Arc::new(CoreConfiguration::from_server_response(
flag_config,
bandits_config,
)),
})
}

Expand Down

0 comments on commit 1d73256

Please sign in to comment.