Struct openai_safe::OpenAIAssistant
source · pub struct OpenAIAssistant { /* private fields */ }
Expand description
The Assistants API allows you to build AI assistants within your own applications. An Assistant has instructions and can leverage models, tools, and knowledge to respond to user queries. The Assistants API currently supports three types of tools: Code Interpreter, Retrieval, and Function calling. In the future, we plan to release more OpenAI-built tools, and allow you to provide your own tools on our platform.
Implementations§
source§impl OpenAIAssistant
impl OpenAIAssistant
sourcepub async fn new(
model: OpenAIModels,
open_ai_key: &str,
debug: bool
) -> Result<Self>
pub async fn new( model: OpenAIModels, open_ai_key: &str, debug: bool ) -> Result<Self>
Examples found in repository?
examples/use_openai_assistant.rs (line 31)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
async fn main() -> Result<()> {
env_logger::init();
let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
// Read invoice file
let path = Path::new("examples/sample-bill.pdf");
let bytes = std::fs::read(path)?;
let openai_file = OpenAIFile::new(bytes, &api_key, true).await?;
// Extract invoice detail using Assistant API
let invoice = OpenAIAssistant::new(OpenAIModels::Gpt4Turbo, &api_key, true)
.await?
.get_answer::<Invoice>(
"Extract the following information from the attached invoice: invoice number, vendor name, payment amount, payment date.",
&[openai_file.id],
)
.await?;
println!("Invoice: {:?}", invoice);
Ok(())
}
sourcepub async fn get_answer<T: JsonSchema + DeserializeOwned>(
self,
message: &str,
file_ids: &[String]
) -> Result<T>
pub async fn get_answer<T: JsonSchema + DeserializeOwned>( self, message: &str, file_ids: &[String] ) -> Result<T>
Examples found in repository?
examples/use_openai_assistant.rs (lines 33-36)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
async fn main() -> Result<()> {
env_logger::init();
let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
// Read invoice file
let path = Path::new("examples/sample-bill.pdf");
let bytes = std::fs::read(path)?;
let openai_file = OpenAIFile::new(bytes, &api_key, true).await?;
// Extract invoice detail using Assistant API
let invoice = OpenAIAssistant::new(OpenAIModels::Gpt4Turbo, &api_key, true)
.await?
.get_answer::<Invoice>(
"Extract the following information from the attached invoice: invoice number, vendor name, payment amount, payment date.",
&[openai_file.id],
)
.await?;
println!("Invoice: {:?}", invoice);
Ok(())
}
Trait Implementations§
source§impl Clone for OpenAIAssistant
impl Clone for OpenAIAssistant
source§fn clone(&self) -> OpenAIAssistant
fn clone(&self) -> OpenAIAssistant
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 OpenAIAssistant
impl Debug for OpenAIAssistant
source§impl<'de> Deserialize<'de> for OpenAIAssistant
impl<'de> Deserialize<'de> for OpenAIAssistant
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 RefUnwindSafe for OpenAIAssistant
impl Send for OpenAIAssistant
impl Sync for OpenAIAssistant
impl Unpin for OpenAIAssistant
impl UnwindSafe for OpenAIAssistant
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