use dynamo_runtime::protocols::annotated::AnnotationsProvider;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use validator::Validate;
mod aggregator;
mod nvext;
pub use aggregator::DeltaAggregator;
pub use nvext::{NvExt, NvExtProvider};
#[derive(ToSchema, Serialize, Deserialize, Validate, Debug, Clone)]
pub struct NvCreateEmbeddingRequest {
#[serde(flatten)]
pub inner: dynamo_async_openai::types::CreateEmbeddingRequest,
#[serde(skip_serializing_if = "Option::is_none")]
pub nvext: Option<NvExt>,
}
#[derive(ToSchema, Serialize, Deserialize, Validate, Debug, Clone)]
pub struct NvCreateEmbeddingResponse {
#[serde(flatten)]
pub inner: dynamo_async_openai::types::CreateEmbeddingResponse,
}
impl NvCreateEmbeddingResponse {
pub fn empty() -> Self {
Self {
inner: dynamo_async_openai::types::CreateEmbeddingResponse {
object: "list".to_string(),
model: "embedding".to_string(),
data: vec![],
usage: dynamo_async_openai::types::EmbeddingUsage {
prompt_tokens: 0,
total_tokens: 0,
},
},
}
}
}
impl NvExtProvider for NvCreateEmbeddingRequest {
fn nvext(&self) -> Option<&NvExt> {
self.nvext.as_ref()
}
}
impl AnnotationsProvider for NvCreateEmbeddingRequest {
fn annotations(&self) -> Option<Vec<String>> {
self.nvext
.as_ref()
.and_then(|nvext| nvext.annotations.clone())
}
fn has_annotation(&self, annotation: &str) -> bool {
self.nvext
.as_ref()
.and_then(|nvext| nvext.annotations.as_ref())
.map(|annotations| annotations.contains(&annotation.to_string()))
.unwrap_or(false)
}
}