portkey_sdk/model/
messages.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5/// Request to create a message.
6///
7/// # Example
8///
9/// ```rust,ignore
10/// use portkey::model::CreateMessageRequest;
11///
12/// let request = CreateMessageRequest::builder()
13///     .role("user")
14///     .content("Hello, how are you?")
15///     .build()
16///     .unwrap();
17/// ```
18#[derive(Clone, Debug, Serialize, Deserialize)]
19pub struct CreateMessageRequest {
20    /// The role of the entity that is creating the message.
21    pub role: String,
22
23    /// The content of the message.
24    pub content: String,
25
26    /// A list of File IDs that the message should use.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub file_ids: Option<Vec<String>>,
29
30    /// Set of key-value pairs that can be attached to an object.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub metadata: Option<HashMap<String, String>>,
33}
34
35impl Default for CreateMessageRequest {
36    fn default() -> Self {
37        Self {
38            role: "user".to_string(),
39            content: String::new(),
40            file_ids: None,
41            metadata: None,
42        }
43    }
44}
45
46/// Modifies a message.
47#[derive(Clone, Debug, Default, Serialize, Deserialize)]
48pub struct ModifyMessageRequest {
49    /// Set of key-value pairs that can be attached to an object.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub metadata: Option<HashMap<String, String>>,
52}
53
54/// A message object.
55#[derive(Clone, Debug, Serialize, Deserialize)]
56pub struct Message {
57    /// The identifier of the message.
58    pub id: String,
59
60    /// The object type, which is always "thread.message".
61    pub object: String,
62
63    /// The Unix timestamp (in seconds) for when the message was created.
64    pub created_at: i64,
65
66    /// The thread ID that this message belongs to.
67    pub thread_id: String,
68
69    /// The role of the entity that created the message.
70    pub role: String,
71
72    /// The content of the message.
73    pub content: Vec<MessageContent>,
74
75    /// If applicable, the ID of the assistant that authored this message.
76    pub assistant_id: Option<String>,
77
78    /// If applicable, the ID of the run associated with the authoring of this message.
79    pub run_id: Option<String>,
80
81    /// A list of file IDs that the assistant should use.
82    pub file_ids: Vec<String>,
83
84    /// Set of key-value pairs that can be attached to an object.
85    pub metadata: HashMap<String, String>,
86}
87
88/// Content of a message.
89#[derive(Clone, Debug, Serialize, Deserialize)]
90#[serde(tag = "type")]
91pub enum MessageContent {
92    #[serde(rename = "text")]
93    Text { text: TextContent },
94    #[serde(rename = "image_file")]
95    ImageFile { image_file: ImageFileContent },
96}
97
98/// Text content in a message.
99#[derive(Clone, Debug, Serialize, Deserialize)]
100pub struct TextContent {
101    /// The data that makes up the text.
102    pub value: String,
103
104    /// Annotations for the text.
105    pub annotations: Vec<Annotation>,
106}
107
108/// Image file content in a message.
109#[derive(Clone, Debug, Serialize, Deserialize)]
110pub struct ImageFileContent {
111    /// The File ID of the image.
112    pub file_id: String,
113}
114
115/// An annotation in text content.
116#[derive(Clone, Debug, Serialize, Deserialize)]
117#[serde(tag = "type")]
118pub enum Annotation {
119    #[serde(rename = "file_citation")]
120    FileCitation {
121        text: String,
122        file_citation: FileCitation,
123        start_index: usize,
124        end_index: usize,
125    },
126    #[serde(rename = "file_path")]
127    FilePath {
128        text: String,
129        file_path: FilePathAnnotation,
130        start_index: usize,
131        end_index: usize,
132    },
133}
134
135/// A citation within the message that points to a specific quote from a specific File.
136#[derive(Clone, Debug, Serialize, Deserialize)]
137pub struct FileCitation {
138    /// The ID of the specific File the citation is from.
139    pub file_id: String,
140
141    /// The specific quote in the file.
142    pub quote: String,
143}
144
145/// A URL for the file that's generated when the assistant used the code_interpreter tool.
146#[derive(Clone, Debug, Serialize, Deserialize)]
147pub struct FilePathAnnotation {
148    /// The ID of the file that was generated.
149    pub file_id: String,
150}
151
152/// Response containing a list of messages.
153#[derive(Clone, Debug, Serialize, Deserialize)]
154pub struct ListMessagesResponse {
155    pub object: String,
156    pub data: Vec<Message>,
157    pub first_id: Option<String>,
158    pub last_id: Option<String>,
159    pub has_more: bool,
160}
161
162/// A message file object.
163#[derive(Clone, Debug, Serialize, Deserialize)]
164pub struct MessageFile {
165    /// The identifier of the message file.
166    pub id: String,
167
168    /// The object type, which is always "thread.message.file".
169    pub object: String,
170
171    /// The Unix timestamp (in seconds) for when the message file was created.
172    pub created_at: i64,
173
174    /// The ID of the message that the File is attached to.
175    pub message_id: String,
176}
177
178/// Response containing a list of message files.
179#[derive(Clone, Debug, Serialize, Deserialize)]
180pub struct ListMessageFilesResponse {
181    pub object: String,
182    pub data: Vec<MessageFile>,
183    pub first_id: Option<String>,
184    pub last_id: Option<String>,
185    pub has_more: bool,
186}