File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,10 @@ use std::env;
7
7
async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
8
8
let client = OpenAIClient :: new ( env:: var ( "OPENAI_API_KEY" ) . unwrap ( ) . to_string ( ) ) ;
9
9
10
- let mut req =
11
- EmbeddingRequest :: new ( TEXT_EMBEDDING_3_SMALL . to_string ( ) , "story time" . to_string ( ) ) ;
10
+ let mut req = EmbeddingRequest :: new (
11
+ TEXT_EMBEDDING_3_SMALL . to_string ( ) ,
12
+ vec ! [ "story time" . to_string( ) , "Once upon a time" . to_string( ) ] ,
13
+ ) ;
12
14
req. dimensions = Some ( 10 ) ;
13
15
14
16
let result = client. embedding ( req) . await ?;
Original file line number Diff line number Diff line change @@ -11,21 +11,30 @@ pub struct EmbeddingData {
11
11
pub index : i32 ,
12
12
}
13
13
14
+ #[ derive( Debug , Serialize , Deserialize , Clone ) ]
15
+ #[ serde( rename_all = "lowercase" ) ]
16
+ pub enum EncodingFormat {
17
+ Float ,
18
+ Base64 ,
19
+ }
20
+
14
21
#[ derive( Debug , Serialize , Clone , Deserialize ) ]
15
22
pub struct EmbeddingRequest {
16
23
pub model : String ,
17
- pub input : String ,
24
+ pub input : Vec < String > ,
25
+ pub encoding_format : Option < EncodingFormat > ,
18
26
#[ serde( skip_serializing_if = "Option::is_none" ) ]
19
27
pub dimensions : Option < i32 > ,
20
28
#[ serde( skip_serializing_if = "Option::is_none" ) ]
21
29
pub user : Option < String > ,
22
30
}
23
31
24
32
impl EmbeddingRequest {
25
- pub fn new ( model : String , input : String ) -> Self {
33
+ pub fn new ( model : String , input : Vec < String > ) -> Self {
26
34
Self {
27
35
model,
28
36
input,
37
+ encoding_format : None ,
29
38
dimensions : None ,
30
39
user : None ,
31
40
}
You can’t perform that action at this time.
0 commit comments