next_web_ai/observation/
observation_documentation.rs

1use next_web_core::error::BoxError;
2
3use crate::{
4    chat::observation::observation_convention::ObservationConvention, util::key_name::KeyName,
5};
6
7use super::{
8    observation::{Context, Observation, ObservationImpl},
9    observation_registry::ObservationRegistry,
10};
11
12// use crate::chat::observation::observation_convention::ObservationConvention;
13
14pub type BoxObservationConvention = Box<dyn ObservationConvention<Box<dyn Context>>>;
15
16pub trait ObservationDocumentation: Send + Sync {
17    fn name(&self) -> Option<&str> {
18        None
19    }
20
21    fn contextual_name(&self) -> Option<&str> {
22        None
23    }
24
25    fn default_convention(&self) -> &'static str;
26
27    fn observation(
28        &self,
29        custom_convention: Option<BoxObservationConvention>,
30        default_convention: Option<BoxObservationConvention>,
31        context: impl Context + 'static,
32        registry: Box<dyn ObservationRegistry>,
33    ) -> Result<Box<dyn Observation>, BoxError> {
34        if self.default_convention().is_empty() {
35            return Err("default_convention is empty".into());
36        }
37
38        if let None = default_convention {
39            return Err("default_convention is None".into());
40        }
41
42        let mut observation = ObservationImpl::create_not_started(
43            custom_convention,
44            default_convention,
45            context,
46            Some(registry),
47        );
48
49        if let Some(name) = self.name() {
50            observation.context().set_name(name);
51        }
52
53        if let Some(contextual_name) = self.contextual_name() {
54            observation.contextual_name(contextual_name);
55        }
56
57        return Ok(observation);
58    }
59
60    fn low_cardinality_key_names(&self) -> Vec<KeyName> {
61        vec![]
62    }
63
64    fn high_cardinality_key_names(&self) -> Vec<KeyName> {
65        vec![]
66    }
67
68    fn prefix(&self) -> &str {
69        ""
70    }
71
72    fn events(&self) -> Vec<i32> {
73        vec![]
74    }
75}