gproxy_protocol/wire/openai/
embeddings.rs1use crate::{Rest, WireRequest, WireResponse};
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
8#[serde(rename_all = "snake_case")]
9#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
10#[derive(gproxy_protocol_macros::DeclaredFields)]
11pub struct CreateEmbeddingRequestBody {
12 pub input: EmbeddingInput,
13 pub model: String,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub dimensions: Option<i64>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub encoding_format: Option<EmbeddingEncodingFormat>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub user: Option<String>,
20 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
21 pub rest: Rest,
22}
23pub type CreateEmbeddingRequest = WireRequest<CreateEmbeddingRequestBody>;
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25#[serde(untagged)]
26#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
27#[derive(gproxy_protocol_macros::DeclaredFields)]
28pub enum EmbeddingInput {
29 Text(String),
30 Texts(Vec<String>),
31 Tokens(Vec<i64>),
32 TokenArrays(Vec<Vec<i64>>),
33}
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
35#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
36#[derive(gproxy_protocol_macros::DeclaredFields)]
37pub enum EmbeddingModel {
38 #[serde(rename = "text-embedding-ada-002")]
39 Ada002,
40 #[serde(rename = "text-embedding-3-small")]
41 ThreeSmall,
42 #[serde(rename = "text-embedding-3-large")]
43 ThreeLarge,
44}
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
46#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
47#[derive(gproxy_protocol_macros::DeclaredFields)]
48pub enum EmbeddingEncodingFormat {
49 #[serde(rename = "float")]
50 Float,
51 #[serde(rename = "base64")]
52 Base64,
53}
54#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
55#[serde(rename_all = "snake_case")]
56#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
57#[derive(gproxy_protocol_macros::DeclaredFields)]
58pub struct CreateEmbeddingResponseBody {
59 pub data: Vec<OpenAiEmbedding>,
60 pub model: String,
61 #[serde(rename = "object")]
62 pub object_: EmbeddingListObject,
63 pub usage: EmbeddingUsage,
64 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
65 pub rest: Rest,
66}
67pub type CreateEmbeddingResponse = WireResponse<CreateEmbeddingResponseBody>;
68#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
69#[serde(rename_all = "snake_case")]
70#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
71#[derive(gproxy_protocol_macros::DeclaredFields)]
72pub struct OpenAiEmbedding {
73 pub embedding: EmbeddingVector,
74 pub index: i64,
75 #[serde(rename = "object")]
76 pub object_: EmbeddingObject,
77 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
78 pub rest: Rest,
79}
80#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
81#[serde(untagged)]
82#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
83#[derive(gproxy_protocol_macros::DeclaredFields)]
84pub enum EmbeddingVector {
85 Floats(Vec<serde_json::Number>),
86 Base64(String),
87}
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
89#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
90#[derive(gproxy_protocol_macros::DeclaredFields)]
91pub enum EmbeddingObject {
92 #[serde(rename = "embedding")]
93 Embedding,
94}
95#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
96#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
97#[derive(gproxy_protocol_macros::DeclaredFields)]
98pub enum EmbeddingListObject {
99 #[serde(rename = "list")]
100 List,
101}
102#[derive(
103 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
104)]
105#[serde(rename_all = "snake_case")]
106#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
107#[derive(gproxy_protocol_macros::DeclaredFields)]
108pub struct EmbeddingUsage {
109 pub prompt_tokens: i64,
110 pub total_tokens: i64,
111 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
112 pub rest: Rest,
113}