portkey_sdk/model/
assistants.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use super::chat::ResponseFormat;
7
8/// Request to create an assistant.
9///
10/// # Example
11///
12/// ```rust,ignore
13/// use portkey::model::CreateAssistantRequest;
14///
15/// let request = CreateAssistantRequest::builder()
16///     .model("gpt-4")
17///     .name("Math Tutor")
18///     .instructions("You are a helpful math tutor.")
19///     .build()
20///     .unwrap();
21/// ```
22#[derive(Clone, Debug, Default, Serialize, Deserialize)]
23pub struct CreateAssistantRequest {
24    /// ID of the model to use.
25    pub model: String,
26
27    /// The name of the assistant.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub name: Option<String>,
30
31    /// The description of the assistant.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub description: Option<String>,
34
35    /// The system instructions that the assistant uses.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub instructions: Option<String>,
38
39    /// A list of tool enabled on the assistant.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub tools: Option<Vec<AssistantTool>>,
42
43    /// A list of file IDs attached to this assistant.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub file_ids: Option<Vec<String>>,
46
47    /// Set of key-value pairs that can be attached to an object.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub metadata: Option<HashMap<String, String>>,
50
51    /// What sampling temperature to use, between 0 and 2.
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub temperature: Option<f32>,
54
55    /// An alternative to sampling with temperature.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub top_p: Option<f32>,
58
59    /// Specifies the format that the model must output.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub response_format: Option<ResponseFormat>,
62}
63
64/// Modifies an existing assistant.
65#[derive(Clone, Debug, Default, Serialize, Deserialize)]
66pub struct ModifyAssistantRequest {
67    /// ID of the model to use.
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub model: Option<String>,
70
71    /// The name of the assistant.
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub name: Option<String>,
74
75    /// The description of the assistant.
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub description: Option<String>,
78
79    /// The system instructions that the assistant uses.
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub instructions: Option<String>,
82
83    /// A list of tool enabled on the assistant.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub tools: Option<Vec<AssistantTool>>,
86
87    /// A list of file IDs attached to this assistant.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub file_ids: Option<Vec<String>>,
90
91    /// Set of key-value pairs that can be attached to an object.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub metadata: Option<HashMap<String, String>>,
94
95    /// What sampling temperature to use, between 0 and 2.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub temperature: Option<f32>,
98
99    /// An alternative to sampling with temperature.
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub top_p: Option<f32>,
102
103    /// Specifies the format that the model must output.
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub response_format: Option<ResponseFormat>,
106}
107
108/// An assistant object.
109#[derive(Clone, Debug, Serialize, Deserialize)]
110pub struct Assistant {
111    /// The identifier of the assistant.
112    pub id: String,
113
114    /// The object type, which is always "assistant".
115    pub object: String,
116
117    /// The Unix timestamp (in seconds) for when the assistant was created.
118    pub created_at: i64,
119
120    /// The name of the assistant.
121    pub name: Option<String>,
122
123    /// The description of the assistant.
124    pub description: Option<String>,
125
126    /// ID of the model to use.
127    pub model: String,
128
129    /// The system instructions that the assistant uses.
130    pub instructions: Option<String>,
131
132    /// A list of tool enabled on the assistant.
133    pub tools: Vec<AssistantTool>,
134
135    /// A list of file IDs attached to this assistant.
136    pub file_ids: Vec<String>,
137
138    /// Set of key-value pairs that can be attached to an object.
139    pub metadata: HashMap<String, String>,
140
141    /// What sampling temperature to use, between 0 and 2.
142    pub temperature: Option<f32>,
143
144    /// An alternative to sampling with temperature.
145    pub top_p: Option<f32>,
146
147    /// Specifies the format that the model must output.
148    pub response_format: Option<ResponseFormat>,
149}
150
151/// Tool enabled on an assistant.
152#[derive(Clone, Debug, Serialize, Deserialize)]
153#[serde(tag = "type")]
154pub enum AssistantTool {
155    #[serde(rename = "code_interpreter")]
156    CodeInterpreter,
157    #[serde(rename = "retrieval")]
158    Retrieval,
159    #[serde(rename = "function")]
160    Function { function: FunctionDefinition },
161}
162
163/// Definition of a function tool.
164#[derive(Clone, Debug, Serialize, Deserialize)]
165pub struct FunctionDefinition {
166    /// The name of the function to be called.
167    pub name: String,
168
169    /// A description of what the function does.
170    pub description: String,
171
172    /// The parameters the functions accepts, described as a JSON Schema object.
173    pub parameters: Value,
174}
175
176/// Response containing a list of assistants.
177#[derive(Clone, Debug, Serialize, Deserialize)]
178pub struct ListAssistantsResponse {
179    pub object: String,
180    pub data: Vec<Assistant>,
181    pub first_id: Option<String>,
182    pub last_id: Option<String>,
183    pub has_more: bool,
184}
185
186/// Response from deleting an assistant.
187#[derive(Clone, Debug, Serialize, Deserialize)]
188pub struct DeleteAssistantResponse {
189    pub id: String,
190    pub object: String,
191    pub deleted: bool,
192}
193
194/// An assistant file object.
195#[derive(Clone, Debug, Serialize, Deserialize)]
196pub struct AssistantFile {
197    /// The identifier of the assistant file.
198    pub id: String,
199
200    /// The object type, which is always "assistant.file".
201    pub object: String,
202
203    /// The Unix timestamp (in seconds) for when the assistant file was created.
204    pub created_at: i64,
205
206    /// The assistant ID that the file is attached to.
207    pub assistant_id: String,
208}
209
210/// Request to create an assistant file.
211#[derive(Clone, Debug, Serialize, Deserialize)]
212pub struct CreateAssistantFileRequest {
213    /// A File ID that the assistant should use.
214    pub file_id: String,
215}
216
217/// Response containing a list of assistant files.
218#[derive(Clone, Debug, Serialize, Deserialize)]
219pub struct ListAssistantFilesResponse {
220    pub object: String,
221    pub data: Vec<AssistantFile>,
222    pub first_id: Option<String>,
223    pub last_id: Option<String>,
224    pub has_more: bool,
225}
226
227/// Response from deleting an assistant file.
228#[derive(Clone, Debug, Serialize, Deserialize)]
229pub struct DeleteAssistantFileResponse {
230    pub id: String,
231    pub object: String,
232    pub deleted: bool,
233}