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