File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed
Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " openai-api-rs"
3- version = " 0.1.5 "
3+ version = " 0.1.6 "
44edition = " 2021"
55authors = [
" Dongri Jin <[email protected] >" ]
66license = " MIT"
Original file line number Diff line number Diff line change 1+ use openai_api_rs:: v1:: api:: Client ;
2+ use openai_api_rs:: v1:: embedding:: EmbeddingRequest ;
3+ use std:: env;
4+
5+ #[ tokio:: main]
6+ async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
7+ let client = Client :: new ( env:: var ( "OPENAI_API_KEY" ) . unwrap ( ) . to_string ( ) ) ;
8+ let req = EmbeddingRequest {
9+ model : "text-embedding-ada-002" . to_string ( ) ,
10+ input : "story time" . to_string ( ) ,
11+ user : Option :: None ,
12+ } ;
13+ let result = client. embedding ( req) . await ?;
14+ println ! ( "{:?}" , result. data) ;
15+
16+ Ok ( ( ) )
17+ }
18+
19+ // OPENAI_API_KEY=xxxx cargo run --package openai-api-rs --example embedding
Original file line number Diff line number Diff line change 11use serde:: { Deserialize , Serialize } ;
22use std:: option:: Option ;
33
4- use crate :: v1:: common;
5-
64#[ derive( Debug , Deserialize ) ]
75pub struct EmbeddingData {
86 pub object : String ,
97 pub embedding : Vec < f32 > ,
108 pub index : i32 ,
11- pub usage : common:: Usage ,
129}
1310
1411#[ derive( Debug , Serialize ) ]
@@ -23,4 +20,12 @@ pub struct EmbeddingRequest {
2320pub struct EmbeddingResponse {
2421 pub object : String ,
2522 pub data : Vec < EmbeddingData > ,
23+ pub model : String ,
24+ pub usage : Usage ,
25+ }
26+
27+ #[ derive( Debug , Deserialize ) ]
28+ pub struct Usage {
29+ pub prompt_tokens : i32 ,
30+ pub total_tokens : i32 ,
2631}
You can’t perform that action at this time.
0 commit comments