openai_api_rs/v1/
thread.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4use crate::impl_builder_methods;
5
6#[derive(Debug, Serialize, Clone)]
7pub struct CreateThreadRequest {
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub messages: Option<Vec<Message>>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub tool_resources: Option<ToolResource>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub metadata: Option<HashMap<String, String>>,
14}
15
16#[derive(Debug, Deserialize, Serialize, Clone)]
17pub struct ToolResource {
18    pub code_interpreter: Option<CodeInterpreter>,
19    pub file_search: Option<FileSearch>,
20}
21
22#[derive(Debug, Deserialize, Serialize, Clone)]
23pub struct CodeInterpreter {
24    pub file_ids: Option<Vec<String>>,
25}
26
27#[derive(Debug, Deserialize, Serialize, Clone)]
28pub struct FileSearch {
29    pub vector_store_ids: Option<Vec<String>>,
30    pub vector_stores: Option<VectorStores>,
31}
32
33#[derive(Debug, Deserialize, Serialize, Clone)]
34pub struct VectorStores {
35    pub file_ids: Option<Vec<String>>,
36    pub chunking_strategy: Option<String>,
37    pub metadata: Option<HashMap<String, String>>,
38}
39
40impl CreateThreadRequest {
41    pub fn new() -> Self {
42        Self {
43            messages: None,
44            tool_resources: None,
45            metadata: None,
46        }
47    }
48}
49
50impl Default for CreateThreadRequest {
51    fn default() -> Self {
52        Self::new()
53    }
54}
55
56impl_builder_methods!(
57    CreateThreadRequest,
58    messages: Vec<Message>,
59    tool_resources: ToolResource
60);
61
62#[derive(Debug, Deserialize, Serialize)]
63pub struct ThreadObject {
64    pub id: String,
65    pub object: String,
66    pub created_at: i64,
67    pub metadata: HashMap<String, String>,
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub tool_resources: Option<ToolResource>,
70}
71
72#[derive(Debug, Deserialize, Serialize, Clone)]
73pub struct Message {
74    pub id: String,
75    pub object: String,
76    pub created_at: i64,
77    pub thread_id: String,
78    pub role: MessageRole,
79    pub content: Vec<Content>,
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub assistant_id: Option<String>,
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub run_id: Option<String>,
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub attachments: Option<Vec<Attachment>>,
86    pub metadata: Option<HashMap<String, String>>,
87}
88
89#[derive(Debug, Deserialize, Serialize, Clone)]
90pub struct Content {
91    #[serde(rename = "type")]
92    pub content_type: String,
93    pub text: ContentText,
94}
95
96#[derive(Debug, Deserialize, Serialize, Clone)]
97pub struct ContentText {
98    pub value: String,
99    pub annotations: Vec<String>,
100}
101
102#[derive(Serialize, Deserialize, Debug, Clone)]
103pub struct Attachment {
104    pub file_id: String,
105    pub tools: Vec<Tool>,
106}
107
108#[derive(Serialize, Deserialize, Debug, Clone)]
109pub struct Tool {
110    pub r#type: String,
111}
112
113#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
114#[allow(non_camel_case_types)]
115pub enum MessageRole {
116    user,
117    system,
118    assistant,
119    function,
120}
121
122#[derive(Debug, Serialize, Clone)]
123pub struct ModifyThreadRequest {
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub metadata: Option<HashMap<String, String>>,
126}
127
128impl ModifyThreadRequest {
129    pub fn new() -> Self {
130        Self { metadata: None }
131    }
132}
133
134impl Default for ModifyThreadRequest {
135    fn default() -> Self {
136        Self::new()
137    }
138}
139
140impl_builder_methods!(
141    ModifyThreadRequest,
142    metadata: HashMap<String, String>
143);