openai_api_rs/v1/
message.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4use crate::impl_builder_methods;
5
6#[derive(Debug, Serialize, Clone)]
7pub struct CreateMessageRequest {
8    pub role: MessageRole,
9    pub content: String,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub attachments: Option<Vec<Attachment>>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub metadata: Option<HashMap<String, String>>,
14}
15
16impl CreateMessageRequest {
17    pub fn new(role: MessageRole, content: String) -> Self {
18        Self {
19            role,
20            content,
21            attachments: None,
22            metadata: None,
23        }
24    }
25}
26
27impl_builder_methods!(
28    CreateMessageRequest,
29    attachments: Vec<Attachment>,
30    metadata: HashMap<String, String>
31);
32
33#[derive(Debug, Serialize, Clone)]
34pub struct ModifyMessageRequest {
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub metadata: Option<HashMap<String, String>>,
37}
38
39impl ModifyMessageRequest {
40    pub fn new() -> Self {
41        Self { metadata: None }
42    }
43}
44
45impl Default for ModifyMessageRequest {
46    fn default() -> Self {
47        Self::new()
48    }
49}
50
51impl_builder_methods!(
52    ModifyMessageRequest,
53    metadata: HashMap<String, String>
54);
55
56#[derive(Debug, Deserialize, Serialize)]
57pub struct MessageObject {
58    pub id: String,
59    pub object: String,
60    pub created_at: i64,
61    pub thread_id: String,
62    pub role: MessageRole,
63    pub content: Vec<Content>,
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub assistant_id: Option<String>,
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub run_id: Option<String>,
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub attachments: Option<Vec<Attachment>>,
70    pub metadata: Option<HashMap<String, String>>,
71}
72
73#[derive(Serialize, Deserialize, Debug, Clone)]
74pub struct Attachment {
75    pub file_id: Option<String>,
76    pub tools: Vec<Tool>,
77}
78
79#[derive(Serialize, Deserialize, Debug, Clone)]
80pub struct Tool {
81    pub r#type: String,
82}
83
84#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
85#[allow(non_camel_case_types)]
86pub enum MessageRole {
87    user,
88    system,
89    assistant,
90    function,
91}
92
93#[derive(Debug, Deserialize, Serialize)]
94pub struct Content {
95    #[serde(rename = "type")]
96    pub content_type: String,
97    pub text: ContentText,
98}
99
100#[derive(Debug, Deserialize, Serialize)]
101pub struct ContentText {
102    pub value: String,
103    pub annotations: Vec<ContentTextAnnotations>,
104}
105
106#[derive(Debug, Deserialize, Serialize)]
107pub struct ListMessage {
108    pub object: String,
109    pub data: Vec<MessageObject>,
110    pub first_id: String,
111    pub last_id: String,
112    pub has_more: bool,
113}
114
115#[derive(Debug, Deserialize, Serialize)]
116pub struct MessageFileObject {
117    pub id: String,
118    pub object: String,
119    pub created_at: i64,
120    pub message_id: String,
121}
122
123#[derive(Debug, Deserialize, Serialize)]
124pub struct ListMessageFile {
125    pub object: String,
126    pub data: Vec<MessageFileObject>,
127    pub first_id: String,
128    pub last_id: String,
129    pub has_more: bool,
130}
131
132#[derive(Debug, Deserialize, Serialize)]
133#[serde(tag = "type")]
134#[serde(rename_all = "snake_case")]
135pub enum ContentTextAnnotations {
136    FileCitation(ContentTextAnnotationsFileCitationObject),
137    FilePath(ContentTextAnnotationsFilePathObject),
138}
139
140#[derive(Debug, Deserialize, Serialize)]
141pub struct ContentTextAnnotationsFileCitationObject {
142    pub text: String,
143    pub file_citation: FileCitation,
144    pub start_index: u32,
145    pub end_index: u32,
146}
147
148#[derive(Debug, Deserialize, Serialize)]
149pub struct FileCitation {
150    pub file_id: String,
151    pub quote: Option<String>,
152}
153
154#[derive(Debug, Deserialize, Serialize)]
155pub struct ContentTextAnnotationsFilePathObject {
156    pub text: String,
157    pub file_path: FilePath,
158    pub start_index: u32,
159    pub end_index: u32,
160}
161
162#[derive(Debug, Deserialize, Serialize)]
163pub struct FilePath {
164    pub file_id: String,
165}