dynamo_llm/protocols/openai/embeddings/
nvext.rs1use derive_builder::Builder;
17use serde::{Deserialize, Serialize};
18use validator::{Validate, ValidationError};
19
20pub trait NvExtProvider {
21 fn nvext(&self) -> Option<&NvExt>;
22}
23
24#[derive(Serialize, Deserialize, Builder, Validate, Debug, Clone)]
26#[validate(schema(function = "validate_nv_ext"))]
27pub struct NvExt {
28 #[serde(default, skip_serializing_if = "Option::is_none")]
32 #[builder(default, setter(strip_option))]
33 pub annotations: Option<Vec<String>>,
34}
35
36impl Default for NvExt {
37 fn default() -> Self {
38 NvExt::builder().build().unwrap()
39 }
40}
41
42impl NvExt {
43 pub fn builder() -> NvExtBuilder {
44 NvExtBuilder::default()
45 }
46}
47
48fn validate_nv_ext(_nv_ext: &NvExt) -> Result<(), ValidationError> {
49 Ok(())
50}
51
52impl NvExtBuilder {
53 pub fn add_annotation(&mut self, annotation: impl Into<String>) -> &mut Self {
54 self.annotations
55 .get_or_insert_with(|| Some(vec![]))
56 .as_mut()
57 .expect("stop should always be Some(Vec)")
58 .push(annotation.into());
59 self
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
69 fn test_nv_ext_builder_default() {
70 let nv_ext = NvExt::builder().build().unwrap();
71 assert_eq!(nv_ext.annotations, None);
72 }
73}