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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Request structures for embeddings API
/// Define a private namespace for all its items.
mod private
{
use serde::{ Serialize, Deserialize };
use former::Former;
/// Input for embedding creation - can be a single string or array of strings
#[ derive( Debug, Serialize, Deserialize, Clone, PartialEq ) ]
#[ serde( untagged ) ]
pub enum EmbeddingInput
{
/// Single text input
Single( String ),
/// Multiple text inputs for batch processing
Multiple( Vec< String > ),
}
/// Request for creating embeddings
#[ derive( Debug, Serialize, Deserialize, Clone, PartialEq, Former ) ]
pub struct CreateEmbeddingRequest
{
/// Input text to embed, encoded as a string or array of strings
pub input : EmbeddingInput,
/// ID of the model to use
pub model : String,
/// The number of dimensions the resulting output embeddings should have.
/// Only supported in text-embedding-3 and later models.
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub dimensions : Option< u32 >,
/// The format to return the embeddings in. Can be either `float` or `base64`.
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub encoding_format : Option< String >,
/// A unique identifier representing your end-user, which can help `OpenAI` to monitor and detect abuse.
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub user : Option< String >,
}
impl CreateEmbeddingRequest
{
/// Create a new embedding request with single text input
#[ inline ]
#[ must_use ]
pub fn new_single( input : String, model : String ) -> Self
{
Self
{
input : EmbeddingInput::Single( input ),
model,
dimensions : None,
encoding_format : None,
user : None,
}
}
/// Create a new embedding request with multiple text inputs
#[ inline ]
#[ must_use ]
pub fn new_multiple( input : Vec< String >, model : String ) -> Self
{
Self
{
input : EmbeddingInput::Multiple( input ),
model,
dimensions : None,
encoding_format : None,
user : None,
}
}
}
impl Default for CreateEmbeddingRequest
{
#[ inline ]
fn default() -> Self
{
Self
{
input : EmbeddingInput::Single( String::new() ),
model : "text-embedding-ada-002".to_string(),
dimensions : None,
encoding_format : None,
user : None,
}
}
}
}
crate ::mod_interface!
{
exposed use
{
EmbeddingInput,
CreateEmbeddingRequest,
};
}