pub struct AssistantRequest {
pub model: Model,
pub name: Option<String>,
pub description: Option<String>,
pub instructions: Option<String>,
pub tools: Option<Vec<HashMap<String, String>>>,
pub file_ids: Option<Vec<String>>,
pub metadata: Option<HashMap<String, String>>,
}
Expand description
Represents a request to create or update an assistant.
Fields§
§model: Model
Model to be used for the assistant.
name: Option<String>
Optional name of the assistant.
description: Option<String>
Optional description of the assistant.
instructions: Option<String>
Optional instructions for the assistant.
tools: Option<Vec<HashMap<String, String>>>
Optional tools to be used by the assistant.
file_ids: Option<Vec<String>>
Optional file IDs associated with the assistant.
metadata: Option<HashMap<String, String>>
Optional metadata for the assistant.
Implementations§
Source§impl AssistantRequest
impl AssistantRequest
Sourcepub fn new(model: Model) -> Self
pub fn new(model: Model) -> Self
Creates a new AssistantRequest
with the specified model.
Examples found in repository?
examples/assistant.rs (line 19)
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 AssistantRequest
impl AssistantRequest
Sourcepub fn description(self, description: String) -> Self
pub fn description(self, description: String) -> Self
Sets the value of the specified field.
Examples found in repository?
examples/assistant.rs (line 22)
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}
Sourcepub fn instructions(self, instructions: String) -> Self
pub fn instructions(self, instructions: String) -> Self
Sets the value of the specified field.
Examples found in repository?
examples/assistant.rs (line 23)
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}
Sourcepub fn tools(self, tools: Vec<HashMap<String, String>>) -> Self
pub fn tools(self, tools: Vec<HashMap<String, String>>) -> Self
Sets the value of the specified field.
Examples found in repository?
examples/assistant.rs (line 24)
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 AssistantRequest
impl Clone for AssistantRequest
Source§fn clone(&self) -> AssistantRequest
fn clone(&self) -> AssistantRequest
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 AssistantRequest
impl Debug for AssistantRequest
Auto Trait Implementations§
impl Freeze for AssistantRequest
impl RefUnwindSafe for AssistantRequest
impl Send for AssistantRequest
impl Sync for AssistantRequest
impl Unpin for AssistantRequest
impl UnwindSafe for AssistantRequest
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