| 449 | } |
| 450 | |
| 451 | fn initialize(&self, config: &NeMoGuardrailsConfig) -> PluginResult<()> { |
| 452 | let response = self |
| 453 | .request_blocking( |
| 454 | json!({ |
| 455 | "command": "init", |
| 456 | "config": config, |
| 457 | }), |
| 458 | WORKER_INIT_TIMEOUT, |
| 459 | ) |
| 460 | .map_err(|err| PluginError::RegistrationFailed(err.to_string()))?; |
| 461 | if response.ok { |
| 462 | Ok(()) |
| 463 | } else { |
| 464 | Err(PluginError::RegistrationFailed( |
| 465 | response |
| 466 | .error |
| 467 | .unwrap_or_else(|| "NeMo Guardrails local Python worker failed".to_string()), |
| 468 | )) |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | async fn request(&self, mut payload: Json) -> FlowResult<Json> { |
| 473 | let receiver = self.send_request(&mut payload)?; |