Struct allms::OpenAIFile
source · pub struct OpenAIFile {
pub id: String,
/* private fields */
}Fields§
§id: StringImplementations§
source§impl OpenAIFile
impl OpenAIFile
sourcepub async fn new(
file_name: &str,
file_bytes: Vec<u8>,
open_ai_key: &str,
debug: bool
) -> Result<Self>
pub async fn new( file_name: &str, file_bytes: Vec<u8>, open_ai_key: &str, debug: bool ) -> Result<Self>
Examples found in repository?
examples/use_openai_assistant.rs (line 38)
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
async fn main() -> Result<()> {
env_logger::init();
let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
// Read concert file
let path = Path::new("metallica.pdf");
let bytes = std::fs::read(path)?;
let file_name = path
.file_name()
.and_then(OsStr::to_str)
.map(|s| s.to_string())
.ok_or_else(|| anyhow!("Failed to extract file name"))?;
let openai_file = OpenAIFile::new(&file_name, bytes, &api_key, true).await?;
let bands_genres = vec![
("Metallica", "Metal"),
("The Beatles", "Rock"),
("Daft Punk", "Electronic"),
("Miles Davis", "Jazz"),
("Johnny Cash", "Country"),
];
// Extract concert information using Assistant API
let concert_info = OpenAIAssistant::new(OpenAIModels::Gpt4o, &api_key, true)
.await?
// Constructor defaults to V1
.version(OpenAIAssistantVersion::V2)
.set_context(
"bands_genres",
&bands_genres
)
.await?
.get_answer::<ConcertInfo>(
"Extract the information requested in the response type from the attached concert information.
The response should include the genre of the music the 'band' represents.
The mapping of bands to genres was provided in 'bands_genres' list in a previous message.",
&[openai_file.id.clone()],
)
.await?;
println!("Concert Info: {:?}", concert_info);
//Remove the file from OpenAI
openai_file.delete_file().await?;
Ok(())
}sourcepub async fn delete_file(&self) -> Result<()>
pub async fn delete_file(&self) -> Result<()>
Examples found in repository?
examples/use_openai_assistant.rs (line 69)
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
async fn main() -> Result<()> {
env_logger::init();
let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
// Read concert file
let path = Path::new("metallica.pdf");
let bytes = std::fs::read(path)?;
let file_name = path
.file_name()
.and_then(OsStr::to_str)
.map(|s| s.to_string())
.ok_or_else(|| anyhow!("Failed to extract file name"))?;
let openai_file = OpenAIFile::new(&file_name, bytes, &api_key, true).await?;
let bands_genres = vec![
("Metallica", "Metal"),
("The Beatles", "Rock"),
("Daft Punk", "Electronic"),
("Miles Davis", "Jazz"),
("Johnny Cash", "Country"),
];
// Extract concert information using Assistant API
let concert_info = OpenAIAssistant::new(OpenAIModels::Gpt4o, &api_key, true)
.await?
// Constructor defaults to V1
.version(OpenAIAssistantVersion::V2)
.set_context(
"bands_genres",
&bands_genres
)
.await?
.get_answer::<ConcertInfo>(
"Extract the information requested in the response type from the attached concert information.
The response should include the genre of the music the 'band' represents.
The mapping of bands to genres was provided in 'bands_genres' list in a previous message.",
&[openai_file.id.clone()],
)
.await?;
println!("Concert Info: {:?}", concert_info);
//Remove the file from OpenAI
openai_file.delete_file().await?;
Ok(())
}Trait Implementations§
source§impl Clone for OpenAIFile
impl Clone for OpenAIFile
source§fn clone(&self) -> OpenAIFile
fn clone(&self) -> OpenAIFile
Returns a copy 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