pub struct OpenAIFile {
pub id: String,
/* private fields */
}
Fields§
§id: String
Implementations§
Source§impl OpenAIFile
impl OpenAIFile
Sourcepub async fn new(
file_bytes: Vec<u8>,
open_ai_key: &str,
debug: bool,
) -> Result<Self>
pub async fn new( file_bytes: Vec<u8>, open_ai_key: &str, debug: bool, ) -> Result<Self>
Examples found in repository?
examples/use_openai_assistant.rs (line 31)
24async fn main() -> Result<()> {
25 env_logger::init();
26 let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
27 // Read invoice file
28 let path = Path::new("examples/metallica.pdf");
29 let bytes = std::fs::read(path)?;
30
31 let openai_file = OpenAIFile::new(bytes, &api_key, true).await?;
32
33 let bands_genres = vec![
34 ("Metallica", "Metal"),
35 ("The Beatles", "Rock"),
36 ("Daft Punk", "Electronic"),
37 ("Miles Davis", "Jazz"),
38 ("Johnny Cash", "Country"),
39 ];
40
41 // Extract concert information using Assistant API
42 let concert_info = OpenAIAssistant::new(OpenAIModels::Gpt4Turbo, &api_key, true)
43 .await?
44 .set_context(
45 "bands_genres",
46 &bands_genres
47 )
48 .await?
49 .get_answer::<ConcertInfo>(
50 "Extract the information requested in the response type from the attached concert information.
51 The response should include the genre of the music the 'band' represents.
52 The mapping of bands to genres was provided in 'bands_genres' list in a previous message.",
53 &[openai_file.id],
54 )
55 .await?;
56
57 println!("Concert Info: {:?}", concert_info);
58 Ok(())
59}
Trait Implementations§
Source§impl Clone for OpenAIFile
impl Clone for OpenAIFile
Source§fn clone(&self) -> OpenAIFile
fn clone(&self) -> OpenAIFile
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for OpenAIFile
impl Debug for OpenAIFile
Source§impl<'de> Deserialize<'de> for OpenAIFile
impl<'de> Deserialize<'de> for OpenAIFile
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for OpenAIFile
impl RefUnwindSafe for OpenAIFile
impl Send for OpenAIFile
impl Sync for OpenAIFile
impl Unpin for OpenAIFile
impl UnwindSafe for OpenAIFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more