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
32impl GenerationRequest for EmbeddingRequest {
33 fn rid(&self) -> Option<&str> {
34 self.rid.as_deref()
35 }
36
37 fn is_stream(&self) -> bool {
38 false
40 }
41
42 fn get_model(&self) -> Option<&str> {
43 Some(&self.model)
44 }
45
46 fn extract_text_for_routing(&self) -> String {
47 match &self.input {
49 Value::String(s) => s.clone(),
50 Value::Array(arr) => arr
51 .iter()
52 .filter_map(|v| v.as_str())
53 .collect::<Vec<_>>()
54 .join(" "),
55 _ => String::new(),
56 }
57 }
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
61pub struct EmbeddingObject {
62 pub object: String, pub embedding: Vec<f32>,
64 pub index: u32,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
68pub struct EmbeddingResponse {
69 pub object: String, pub data: Vec<EmbeddingObject>,
71 pub model: String,
72 pub usage: UsageInfo,
73}