openai_protocol/
embedding.rs1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use super::common::{GenerationRequest, UsageInfo};
5
6#[serde_with::skip_serializing_none]
11#[derive(Debug, Clone, Deserialize, Serialize, schemars::JsonSchema)]
12pub struct EmbeddingRequest {
13 pub model: String,
15
16 pub input: Value,
18
19 pub encoding_format: Option<String>,
21
22 pub user: Option<String>,
24
25 pub dimensions: Option<u32>,
27
28 pub rid: Option<String>,
30
31 pub log_metrics: Option<bool>,
33}
34
35impl GenerationRequest for EmbeddingRequest {
36 fn is_stream(&self) -> bool {
37 false
39 }
40
41 fn get_model(&self) -> Option<&str> {
42 Some(&self.model)
43 }
44
45 fn extract_text_for_routing(&self) -> String {
46 match &self.input {
48 Value::String(s) => s.clone(),
49 Value::Array(arr) => arr
50 .iter()
51 .filter_map(|v| v.as_str())
52 .collect::<Vec<_>>()
53 .join(" "),
54 _ => String::new(),
55 }
56 }
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
60pub struct EmbeddingObject {
61 pub object: String, pub embedding: Vec<f32>,
63 pub index: u32,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
67pub struct EmbeddingResponse {
68 pub object: String, pub data: Vec<EmbeddingObject>,
70 pub model: String,
71 pub usage: UsageInfo,
72}