dynamo_llm/protocols/openai/
embeddings.rs1use dynamo_runtime::protocols::annotated::AnnotationsProvider;
5use serde::{Deserialize, Serialize};
6use validator::Validate;
7
8mod aggregator;
9mod nvext;
10
11pub use aggregator::DeltaAggregator;
12pub use nvext::{NvExt, NvExtProvider};
13
14#[derive(Serialize, Deserialize, Validate, Debug, Clone)]
15pub struct NvCreateEmbeddingRequest {
16 #[serde(flatten)]
17 pub inner: dynamo_async_openai::types::CreateEmbeddingRequest,
18
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub nvext: Option<NvExt>,
21}
22
23#[derive(Serialize, Deserialize, Validate, Debug, Clone)]
30pub struct NvCreateEmbeddingResponse {
31 #[serde(flatten)]
32 pub inner: dynamo_async_openai::types::CreateEmbeddingResponse,
33}
34
35impl NvCreateEmbeddingResponse {
36 pub fn empty() -> Self {
37 Self {
38 inner: dynamo_async_openai::types::CreateEmbeddingResponse {
39 object: "list".to_string(),
40 model: "embedding".to_string(),
41 data: vec![],
42 usage: dynamo_async_openai::types::EmbeddingUsage {
43 prompt_tokens: 0,
44 total_tokens: 0,
45 },
46 },
47 }
48 }
49}
50
51impl NvExtProvider for NvCreateEmbeddingRequest {
54 fn nvext(&self) -> Option<&NvExt> {
56 self.nvext.as_ref()
57 }
58}
59
60impl AnnotationsProvider for NvCreateEmbeddingRequest {
63 fn annotations(&self) -> Option<Vec<String>> {
65 self.nvext
66 .as_ref()
67 .and_then(|nvext| nvext.annotations.clone())
68 }
69
70 fn has_annotation(&self, annotation: &str) -> bool {
78 self.nvext
79 .as_ref()
80 .and_then(|nvext| nvext.annotations.as_ref())
81 .map(|annotations| annotations.contains(&annotation.to_string()))
82 .unwrap_or(false)
83 }
84}