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
impl CreateThreadRequest
Sourcepub fn new() -> Self
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}
Trait Implementations§
Source§impl Clone for CreateThreadRequest
impl Clone for CreateThreadRequest
Source§fn clone(&self) -> CreateThreadRequest
fn clone(&self) -> CreateThreadRequest
Returns a duplicate 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 CreateThreadRequest
impl Debug for CreateThreadRequest
Source§impl Default for CreateThreadRequest
impl Default for CreateThreadRequest
Auto Trait Implementations§
impl Freeze for CreateThreadRequest
impl RefUnwindSafe for CreateThreadRequest
impl Send for CreateThreadRequest
impl Sync for CreateThreadRequest
impl Unpin for CreateThreadRequest
impl UnwindSafe for CreateThreadRequest
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