Struct allms::OpenAIFile
source ยท pub struct OpenAIFile {
pub id: String,
/* private fields */
}๐Deprecated since 0.6.1: This struct is deprecated. Please use the
assistants::OpenAIFile struct for latest functionality.Expand description
This is a LEGACY implementation of OpenAI File API that will not be maintained going forward (after May 2024).
For current implementation refer to assistants module.
Fieldsยง
ยงid: String๐Deprecated since 0.6.1: This struct is deprecated. Please use the
assistants::OpenAIFile struct for latest functionality.Implementationsยง
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/deprecated_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/deprecated_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
sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
sourceยงdefault unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
๐ฌThis is a nightly-only experimental API. (
clone_to_uninit)