Struct OpenAIAssistant

Source
pub struct OpenAIAssistant { /* private fields */ }
๐Ÿ‘ŽDeprecated since 0.6.1: This struct is deprecated. Please use the assistants::OpenAIAssistant struct for latest functionality including Assistants API v2.
Expand description

This is a DEPRECATED implementation of OpenAI Assistants API that will not be maintained going forward (after May 2024). For current implementation, including support for Assistants API v2 and GPT-4o, refer to assistants module.

OpenAI Docs

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

Source

pub async fn new( model: OpenAIModels, open_ai_key: &str, debug: bool, ) -> Result<Self>

Examples found in repository?
examples/deprecated_use_openai_assistant.rs (line 49)
26async fn main() -> Result<()> {
27    env_logger::init();
28    let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
29    // Read concert file
30    let path = Path::new("metallica.pdf");
31    let bytes = std::fs::read(path)?;
32    let file_name = path
33        .file_name()
34        .and_then(OsStr::to_str)
35        .map(|s| s.to_string())
36        .ok_or_else(|| anyhow!("Failed to extract file name"))?;
37
38    let openai_file = OpenAIFile::new(&file_name, bytes, &api_key, true).await?;
39
40    let bands_genres = vec![
41        ("Metallica", "Metal"),
42        ("The Beatles", "Rock"),
43        ("Daft Punk", "Electronic"),
44        ("Miles Davis", "Jazz"),
45        ("Johnny Cash", "Country"),
46    ];
47
48    // Extract concert information using Assistant API
49    let concert_info = OpenAIAssistant::new(OpenAIModels::Gpt4o, &api_key, true)
50        .await?
51        // Constructor defaults to V1
52        .version(OpenAIAssistantVersion::V2)
53        .set_context(
54            "bands_genres",
55            &bands_genres
56        )
57        .await?
58        .get_answer::<ConcertInfo>(
59            "Extract the information requested in the response type from the attached concert information.
60            The response should include the genre of the music the 'band' represents.
61            The mapping of bands to genres was provided in 'bands_genres' list in a previous message.",
62            &[openai_file.id.clone()],
63        )
64        .await?;
65
66    println!("Concert Info: {:?}", concert_info);
67
68    //Remove the file from OpenAI
69    openai_file.delete_file().await?;
70
71    Ok(())
72}
Source

pub fn version(self, version: OpenAIAssistantVersion) -> Self

This method can be used to set the version of Assistants API Beta Current default is V1

Examples found in repository?
examples/deprecated_use_openai_assistant.rs (line 52)
26async fn main() -> Result<()> {
27    env_logger::init();
28    let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
29    // Read concert file
30    let path = Path::new("metallica.pdf");
31    let bytes = std::fs::read(path)?;
32    let file_name = path
33        .file_name()
34        .and_then(OsStr::to_str)
35        .map(|s| s.to_string())
36        .ok_or_else(|| anyhow!("Failed to extract file name"))?;
37
38    let openai_file = OpenAIFile::new(&file_name, bytes, &api_key, true).await?;
39
40    let bands_genres = vec![
41        ("Metallica", "Metal"),
42        ("The Beatles", "Rock"),
43        ("Daft Punk", "Electronic"),
44        ("Miles Davis", "Jazz"),
45        ("Johnny Cash", "Country"),
46    ];
47
48    // Extract concert information using Assistant API
49    let concert_info = OpenAIAssistant::new(OpenAIModels::Gpt4o, &api_key, true)
50        .await?
51        // Constructor defaults to V1
52        .version(OpenAIAssistantVersion::V2)
53        .set_context(
54            "bands_genres",
55            &bands_genres
56        )
57        .await?
58        .get_answer::<ConcertInfo>(
59            "Extract the information requested in the response type from the attached concert information.
60            The response should include the genre of the music the 'band' represents.
61            The mapping of bands to genres was provided in 'bands_genres' list in a previous message.",
62            &[openai_file.id.clone()],
63        )
64        .await?;
65
66    println!("Concert Info: {:?}", concert_info);
67
68    //Remove the file from OpenAI
69    openai_file.delete_file().await?;
70
71    Ok(())
72}
Source

pub async fn get_answer<T: JsonSchema + DeserializeOwned>( self, message: &str, file_ids: &[String], ) -> Result<T>

Examples found in repository?
examples/deprecated_use_openai_assistant.rs (lines 58-63)
26async fn main() -> Result<()> {
27    env_logger::init();
28    let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
29    // Read concert file
30    let path = Path::new("metallica.pdf");
31    let bytes = std::fs::read(path)?;
32    let file_name = path
33        .file_name()
34        .and_then(OsStr::to_str)
35        .map(|s| s.to_string())
36        .ok_or_else(|| anyhow!("Failed to extract file name"))?;
37
38    let openai_file = OpenAIFile::new(&file_name, bytes, &api_key, true).await?;
39
40    let bands_genres = vec![
41        ("Metallica", "Metal"),
42        ("The Beatles", "Rock"),
43        ("Daft Punk", "Electronic"),
44        ("Miles Davis", "Jazz"),
45        ("Johnny Cash", "Country"),
46    ];
47
48    // Extract concert information using Assistant API
49    let concert_info = OpenAIAssistant::new(OpenAIModels::Gpt4o, &api_key, true)
50        .await?
51        // Constructor defaults to V1
52        .version(OpenAIAssistantVersion::V2)
53        .set_context(
54            "bands_genres",
55            &bands_genres
56        )
57        .await?
58        .get_answer::<ConcertInfo>(
59            "Extract the information requested in the response type from the attached concert information.
60            The response should include the genre of the music the 'band' represents.
61            The mapping of bands to genres was provided in 'bands_genres' list in a previous message.",
62            &[openai_file.id.clone()],
63        )
64        .await?;
65
66    println!("Concert Info: {:?}", concert_info);
67
68    //Remove the file from OpenAI
69    openai_file.delete_file().await?;
70
71    Ok(())
72}
Source

pub async fn set_context<T: Serialize>( self, dataset_name: &str, data: &T, ) -> Result<Self>

This method can be used to provide data that will be used as context for the prompt. Using this function you can provide multiple sets of context data by calling it multiple times. New values will be as messages to the thread It accepts any struct that implements the Serialize trait.

Examples found in repository?
examples/deprecated_use_openai_assistant.rs (lines 53-56)
26async fn main() -> Result<()> {
27    env_logger::init();
28    let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
29    // Read concert file
30    let path = Path::new("metallica.pdf");
31    let bytes = std::fs::read(path)?;
32    let file_name = path
33        .file_name()
34        .and_then(OsStr::to_str)
35        .map(|s| s.to_string())
36        .ok_or_else(|| anyhow!("Failed to extract file name"))?;
37
38    let openai_file = OpenAIFile::new(&file_name, bytes, &api_key, true).await?;
39
40    let bands_genres = vec![
41        ("Metallica", "Metal"),
42        ("The Beatles", "Rock"),
43        ("Daft Punk", "Electronic"),
44        ("Miles Davis", "Jazz"),
45        ("Johnny Cash", "Country"),
46    ];
47
48    // Extract concert information using Assistant API
49    let concert_info = OpenAIAssistant::new(OpenAIModels::Gpt4o, &api_key, true)
50        .await?
51        // Constructor defaults to V1
52        .version(OpenAIAssistantVersion::V2)
53        .set_context(
54            "bands_genres",
55            &bands_genres
56        )
57        .await?
58        .get_answer::<ConcertInfo>(
59            "Extract the information requested in the response type from the attached concert information.
60            The response should include the genre of the music the 'band' represents.
61            The mapping of bands to genres was provided in 'bands_genres' list in a previous message.",
62            &[openai_file.id.clone()],
63        )
64        .await?;
65
66    println!("Concert Info: {:?}", concert_info);
67
68    //Remove the file from OpenAI
69    openai_file.delete_file().await?;
70
71    Ok(())
72}

Trait Implementationsยง

Sourceยง

impl Clone for OpenAIAssistant

Sourceยง

fn clone(&self) -> OpenAIAssistant

Returns a copy of the value. Read more
1.0.0 ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for OpenAIAssistant

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl<'de> Deserialize<'de> for OpenAIAssistant

Sourceยง

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Sourceยง

impl Serialize for OpenAIAssistant

Sourceยง

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dst: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Sourceยง

impl<T> DynClone for T
where T: Clone,

Sourceยง

fn __clone_box(&self, _: Private) -> *mut ()

Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Sourceยง

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Sourceยง

impl<T> Same for T

Sourceยง

type Output = T

Should always be Self
Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,

Sourceยง

impl<T> MaybeSendSync for T