1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::{Input, JsonRequest};
use serde::{Serialize,Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EmbeddingRequest{
pub model:String,
pub input:Input,
#[serde(skip_serializing_if = "Option::is_none")]
pub user: Option<String>
}
impl JsonRequest<EmbeddingResponse> for EmbeddingRequest{
const ENDPOINT: &'static str = "/embeddings";
}
impl EmbeddingRequest {
pub fn new(input: Input) -> Self {
EmbeddingRequest {
model: "text-embedding-ada-002".to_string(),
input,
user: None,
}
}
pub fn with_model(model: String, input: Input) -> Self {
EmbeddingRequest {
model,
input,
user: None,
}
}
pub fn user(mut self, user: String) -> Self {
self.user = Some(user);
self
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Usage {
pub prompt_tokens: i64,
pub total_tokens: i64,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Struct {
pub object: String,
pub embedding: Vec<f64>,
pub index: i64,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EmbeddingResponse {
pub object: String,
pub data: Vec<Struct>,
pub model: String,
pub usage: Usage,
}