pub struct CreateMessageRequest {
pub role: MessageRole,
pub content: String,
pub file_ids: Option<Vec<String>>,
pub metadata: Option<HashMap<String, String>>,
}
Expand description
Represents a request to create a new message.
Fields§
§role: MessageRole
Role of the message sender.
content: String
Content of the message.
file_ids: Option<Vec<String>>
Optional file IDs associated with the message.
metadata: Option<HashMap<String, String>>
Optional metadata for the message.
Implementations§
Source§impl CreateMessageRequest
impl CreateMessageRequest
Sourcepub fn new(role: MessageRole, content: String) -> Self
pub fn new(role: MessageRole, content: String) -> Self
Creates a new CreateMessageRequest
with the specified role and content.
Examples found in repository?
examples/assistant.rs (lines 34-37)
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 CreateMessageRequest
impl Clone for CreateMessageRequest
Source§fn clone(&self) -> CreateMessageRequest
fn clone(&self) -> CreateMessageRequest
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 CreateMessageRequest
impl Debug for CreateMessageRequest
Auto Trait Implementations§
impl Freeze for CreateMessageRequest
impl RefUnwindSafe for CreateMessageRequest
impl Send for CreateMessageRequest
impl Sync for CreateMessageRequest
impl Unpin for CreateMessageRequest
impl UnwindSafe for CreateMessageRequest
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