File tree Expand file tree Collapse file tree 3 files changed +11
-8
lines changed
Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change 11use openai_api_rs:: v1:: api:: Client ;
2+ use openai_api_rs:: v1:: common:: TEXT_EMBEDDING_3_SMALL ;
23use openai_api_rs:: v1:: embedding:: EmbeddingRequest ;
34use std:: env;
45
56fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
67 let client = Client :: new ( env:: var ( "OPENAI_API_KEY" ) . unwrap ( ) . to_string ( ) ) ;
78
8- let req = EmbeddingRequest :: new (
9- "text-embedding-ada-002" . to_string ( ) ,
10- "story time" . to_string ( ) ,
11- ) ;
9+ let req = EmbeddingRequest :: new ( TEXT_EMBEDDING_3_SMALL . to_string ( ) , "story time" . to_string ( ) ) ;
1210
1311 let result = client. embedding ( req) ?;
1412 println ! ( "{:?}" , result. data) ;
Original file line number Diff line number Diff line change @@ -158,15 +158,15 @@ pub struct ChatCompletionMessageForResponse {
158158 pub tool_calls : Option < Vec < ToolCall > > ,
159159}
160160
161- #[ derive( Debug , Deserialize ) ]
161+ #[ derive( Debug , Deserialize , Serialize ) ]
162162pub struct ChatCompletionChoice {
163163 pub index : i64 ,
164164 pub message : ChatCompletionMessageForResponse ,
165165 pub finish_reason : Option < FinishReason > ,
166166 pub finish_details : Option < FinishDetails > ,
167167}
168168
169- #[ derive( Debug , Deserialize ) ]
169+ #[ derive( Debug , Deserialize , Serialize ) ]
170170pub struct ChatCompletionResponse {
171171 pub id : String ,
172172 pub object : String ,
Original file line number Diff line number Diff line change 1- use serde:: Deserialize ;
1+ use serde:: { Deserialize , Serialize } ;
22
3- #[ derive( Debug , Deserialize ) ]
3+ #[ derive( Debug , Deserialize , Serialize ) ]
44pub struct Usage {
55 pub prompt_tokens : i32 ,
66 pub completion_tokens : i32 ,
@@ -45,3 +45,8 @@ pub const GPT4_32K_0314: &str = "gpt-4-32k-0314";
4545// https://platform.openai.com/docs/api-reference/images/object
4646pub const DALL_E_2 : & str = "dall-e-2" ;
4747pub const DALL_E_3 : & str = "dall-e-3" ;
48+
49+ // https://platform.openai.com/docs/guides/embeddings/embedding-models
50+ pub const TEXT_EMBEDDING_3_SMALL : & str = "text-embedding-3-small" ;
51+ pub const TEXT_EMBEDDING_3_LARGE : & str = "text-embedding-3-large" ;
52+ pub const TEXT_EMBEDDING_ADA_002 : & str = "text-embedding-ada-002" ;
You can’t perform that action at this time.
0 commit comments