Struct CreateThreadRequest

Source
pub struct CreateThreadRequest {
    pub messages: Option<Vec<Message>>,
    pub metadata: Option<HashMap<String, String>>,
}
Expand description

Represents a request to create a new thread.

Fields§

§messages: Option<Vec<Message>>

Optional list of messages in the thread.

§metadata: Option<HashMap<String, String>>

Optional metadata for the thread.

Implementations§

Source§

impl CreateThreadRequest

Source

pub fn new() -> Self

Creates a new CreateThreadRequest.

Examples found in repository?
examples/assistant.rs (line 30)
13async fn main() -> Result<(), Box<dyn std::error::Error>> {
14    let client = Client::from_env().unwrap();
15
16    let mut tools = HashMap::new();
17    tools.insert("type".to_string(), "code_interpreter".to_string());
18
19    let req = AssistantRequest::new(Model::GPT4(GPT4::GPT40125Preview));
20    let req = req
21        .clone()
22        .description("this is a test assistant".to_string());
23    let req = req.clone().instructions("You are a personal math tutor. When asked a question, write and run Python code to answer the question.".to_string());
24    let req = req.clone().tools(vec![tools]);
25    println!("{:?}", req);
26
27    let result = client.create_assistant(req).await?;
28    println!("{:?}", result.id);
29
30    let thread_req = CreateThreadRequest::new();
31    let thread_result = client.create_thread(thread_req).await?;
32    println!("{:?}", thread_result.id.clone());
33
34    let message_req = CreateMessageRequest::new(
35        MessageRole::User,
36        "`I need to solve the equation 3x + 11 = 14. Can you help me?".to_string(),
37    );
38
39    let message_result = client
40        .create_message(thread_result.id.clone(), message_req)
41        .await?;
42    println!("{:?}", message_result.id.clone());
43
44    let run_req = CreateRunRequest::new(result.id);
45    let run_result = client.create_run(thread_result.id.clone(), run_req).await?;
46
47    loop {
48        let run_result = client
49            .retrieve_run(thread_result.id.clone(), run_result.id.clone())
50            .await?;
51        if run_result.status == "completed" {
52            break;
53        } else {
54            println!("waiting...");
55            std::thread::sleep(std::time::Duration::from_secs(1));
56        }
57    }
58
59    let list_message_result = client.list_messages(thread_result.id.clone()).await?;
60    for data in list_message_result.data {
61        for content in data.content {
62            println!(
63                "{:?}: {:?} {:?}",
64                data.role, content.text.value, content.text.annotations
65            );
66        }
67    }
68
69    Ok(())
70}
Source§

impl CreateThreadRequest

Source

pub fn messages(self, messages: Vec<Message>) -> Self

Sets the value of the specified field.

Source

pub fn metadata(self, metadata: HashMap<String, String>) -> Self

Sets the value of the specified field.

Trait Implementations§

Source§

impl Clone for CreateThreadRequest

Source§

fn clone(&self) -> CreateThreadRequest

Returns a duplicate 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 CreateThreadRequest

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CreateThreadRequest

Source§

fn default() -> Self

Provides a default implementation for CreateThreadRequest.

Source§

impl Serialize for CreateThreadRequest

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> 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> ErasedDestructor for T
where T: 'static,