1use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7pub use crate::shared::{Role, SortOrder};
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum RunStatus {
14 Queued,
15 InProgress,
16 RequiresAction,
17 Cancelling,
18 Cancelled,
19 Failed,
20 Completed,
21 Incomplete,
22 Expired,
23 Other(String),
25}
26
27impl serde::Serialize for RunStatus {
28 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
29 where
30 S: serde::Serializer,
31 {
32 match self {
33 Self::Queued => serializer.serialize_str("queued"),
34 Self::InProgress => serializer.serialize_str("in_progress"),
35 Self::RequiresAction => serializer.serialize_str("requires_action"),
36 Self::Cancelling => serializer.serialize_str("cancelling"),
37 Self::Cancelled => serializer.serialize_str("cancelled"),
38 Self::Failed => serializer.serialize_str("failed"),
39 Self::Completed => serializer.serialize_str("completed"),
40 Self::Incomplete => serializer.serialize_str("incomplete"),
41 Self::Expired => serializer.serialize_str("expired"),
42 Self::Other(s) => serializer.serialize_str(s),
43 }
44 }
45}
46
47impl<'de> serde::Deserialize<'de> for RunStatus {
48 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
49 where
50 D: serde::Deserializer<'de>,
51 {
52 let s = String::deserialize(deserializer)?;
53 match s.as_str() {
54 "queued" => Ok(Self::Queued),
55 "in_progress" => Ok(Self::InProgress),
56 "requires_action" => Ok(Self::RequiresAction),
57 "cancelling" => Ok(Self::Cancelling),
58 "cancelled" => Ok(Self::Cancelled),
59 "failed" => Ok(Self::Failed),
60 "completed" => Ok(Self::Completed),
61 "incomplete" => Ok(Self::Incomplete),
62 "expired" => Ok(Self::Expired),
63 _ => Ok(Self::Other(s)),
64 }
65 }
66}
67
68#[derive(Debug, Clone, PartialEq, Eq)]
70#[non_exhaustive]
71pub enum VectorStoreStatus {
72 Expired,
73 InProgress,
74 Completed,
75 Other(String),
77}
78
79impl serde::Serialize for VectorStoreStatus {
80 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
81 where
82 S: serde::Serializer,
83 {
84 match self {
85 Self::Expired => serializer.serialize_str("expired"),
86 Self::InProgress => serializer.serialize_str("in_progress"),
87 Self::Completed => serializer.serialize_str("completed"),
88 Self::Other(s) => serializer.serialize_str(s),
89 }
90 }
91}
92
93impl<'de> serde::Deserialize<'de> for VectorStoreStatus {
94 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
95 where
96 D: serde::Deserializer<'de>,
97 {
98 let s = String::deserialize(deserializer)?;
99 match s.as_str() {
100 "expired" => Ok(Self::Expired),
101 "in_progress" => Ok(Self::InProgress),
102 "completed" => Ok(Self::Completed),
103 _ => Ok(Self::Other(s)),
104 }
105 }
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
112#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
113#[serde(tag = "type")]
114#[non_exhaustive]
115pub enum BetaTool {
116 #[serde(rename = "code_interpreter")]
118 CodeInterpreter,
119 #[serde(rename = "file_search")]
121 FileSearch {
122 #[serde(skip_serializing_if = "Option::is_none")]
123 file_search: Option<FileSearchConfig>,
124 },
125 #[serde(rename = "function")]
127 Function { function: BetaFunctionDef },
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize)]
132#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
133pub struct FileSearchConfig {
134 #[serde(skip_serializing_if = "Option::is_none")]
136 pub max_num_results: Option<i64>,
137 #[serde(skip_serializing_if = "Option::is_none")]
139 pub ranking_options: Option<FileSearchRankingOptions>,
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize)]
144#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
145pub struct FileSearchRankingOptions {
146 pub score_threshold: f64,
148 #[serde(skip_serializing_if = "Option::is_none")]
150 pub ranker: Option<String>,
151}
152
153#[derive(Debug, Clone, Serialize, Deserialize)]
155#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
156pub struct BetaFunctionDef {
157 pub name: String,
158 #[serde(skip_serializing_if = "Option::is_none")]
159 pub description: Option<String>,
160 #[serde(skip_serializing_if = "Option::is_none")]
161 pub parameters: Option<serde_json::Value>,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize)]
166#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
167pub struct MessageAnnotation {
168 #[serde(rename = "type")]
170 pub type_: String,
171 #[serde(default)]
173 pub text: Option<String>,
174 #[serde(default)]
176 pub start_index: Option<i64>,
177 #[serde(default)]
179 pub end_index: Option<i64>,
180 #[serde(default)]
182 pub file_citation: Option<FileCitation>,
183 #[serde(default)]
185 pub file_path: Option<FilePath>,
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
190#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
191pub struct FileCitation {
192 pub file_id: String,
193 #[serde(default)]
194 pub quote: Option<String>,
195}
196
197#[derive(Debug, Clone, Serialize, Deserialize)]
199#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
200pub struct FilePath {
201 pub file_id: String,
202}
203
204#[derive(Debug, Clone, Serialize)]
208#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
209pub struct AssistantCreateRequest {
210 pub model: String,
211 #[serde(skip_serializing_if = "Option::is_none")]
212 pub name: Option<String>,
213 #[serde(skip_serializing_if = "Option::is_none")]
214 pub description: Option<String>,
215 #[serde(skip_serializing_if = "Option::is_none")]
216 pub instructions: Option<String>,
217 #[serde(skip_serializing_if = "Option::is_none")]
218 pub tools: Option<Vec<BetaTool>>,
219 #[serde(skip_serializing_if = "Option::is_none")]
220 pub metadata: Option<HashMap<String, String>>,
221 #[serde(skip_serializing_if = "Option::is_none")]
222 pub temperature: Option<f64>,
223 #[serde(skip_serializing_if = "Option::is_none")]
224 pub top_p: Option<f64>,
225}
226
227impl AssistantCreateRequest {
228 pub fn new(model: impl Into<String>) -> Self {
229 Self {
230 model: model.into(),
231 name: None,
232 description: None,
233 instructions: None,
234 tools: None,
235 metadata: None,
236 temperature: None,
237 top_p: None,
238 }
239 }
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize)]
244#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
245pub struct Assistant {
246 pub id: String,
247 pub object: String,
248 pub created_at: i64,
249 pub model: String,
250 #[serde(default)]
251 pub name: Option<String>,
252 #[serde(default)]
253 pub description: Option<String>,
254 #[serde(default)]
255 pub instructions: Option<String>,
256 #[serde(default)]
257 pub tools: Vec<BetaTool>,
258 #[serde(default)]
259 pub metadata: Option<HashMap<String, String>>,
260 #[serde(default)]
261 pub temperature: Option<f64>,
262 #[serde(default)]
263 pub top_p: Option<f64>,
264}
265
266#[derive(Debug, Clone, Serialize, Deserialize)]
268#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
269pub struct AssistantList {
270 pub object: String,
271 pub data: Vec<Assistant>,
272 #[serde(default)]
274 pub has_more: Option<bool>,
275 #[serde(default)]
277 pub first_id: Option<String>,
278 #[serde(default)]
280 pub last_id: Option<String>,
281}
282
283#[derive(Debug, Clone, Serialize, Deserialize)]
285#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
286pub struct AssistantDeleted {
287 pub id: String,
288 pub deleted: bool,
289 pub object: String,
290}
291
292#[derive(Debug, Clone, Default, Serialize)]
296#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
297pub struct ThreadCreateRequest {
298 #[serde(skip_serializing_if = "Option::is_none")]
299 pub messages: Option<Vec<ThreadMessage>>,
300 #[serde(skip_serializing_if = "Option::is_none")]
301 pub metadata: Option<HashMap<String, String>>,
302}
303
304#[derive(Debug, Clone, Serialize)]
306#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
307pub struct ThreadMessage {
308 pub role: Role,
309 pub content: String,
310}
311
312#[derive(Debug, Clone, Deserialize, Serialize)]
314#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
315pub struct Thread {
316 pub id: String,
317 pub object: String,
318 pub created_at: i64,
319 #[serde(default)]
320 pub metadata: Option<HashMap<String, String>>,
321}
322
323#[derive(Debug, Clone, Serialize, Deserialize)]
325#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
326pub struct ThreadDeleted {
327 pub id: String,
328 pub deleted: bool,
329 pub object: String,
330}
331
332#[derive(Debug, Clone, Deserialize, Serialize)]
334#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
335pub struct Message {
336 pub id: String,
337 pub object: String,
338 pub created_at: i64,
339 pub thread_id: String,
340 pub role: Role,
341 pub content: Vec<MessageContent>,
342 #[serde(default)]
343 pub assistant_id: Option<String>,
344 #[serde(default)]
345 pub run_id: Option<String>,
346 #[serde(default)]
347 pub metadata: Option<HashMap<String, String>>,
348}
349
350#[derive(Debug, Clone, Serialize, Deserialize)]
352#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
353pub struct MessageContent {
354 #[serde(rename = "type")]
355 pub type_: String,
356 #[serde(default)]
357 pub text: Option<MessageText>,
358}
359
360#[derive(Debug, Clone, Serialize, Deserialize)]
362#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
363pub struct MessageText {
364 pub value: String,
365 #[serde(default)]
366 pub annotations: Vec<MessageAnnotation>,
367}
368
369#[derive(Debug, Clone, Serialize)]
371#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
372pub struct MessageCreateRequest {
373 pub role: Role,
374 pub content: String,
375}
376
377#[derive(Debug, Clone, Serialize, Deserialize)]
379#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
380pub struct MessageList {
381 pub object: String,
382 pub data: Vec<Message>,
383 #[serde(default)]
385 pub has_more: Option<bool>,
386 #[serde(default)]
388 pub first_id: Option<String>,
389 #[serde(default)]
391 pub last_id: Option<String>,
392}
393
394#[derive(Debug, Clone, Serialize)]
398#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
399pub struct RunCreateRequest {
400 pub assistant_id: String,
401 #[serde(skip_serializing_if = "Option::is_none")]
402 pub instructions: Option<String>,
403 #[serde(skip_serializing_if = "Option::is_none")]
404 pub tools: Option<Vec<BetaTool>>,
405 #[serde(skip_serializing_if = "Option::is_none")]
406 pub metadata: Option<HashMap<String, String>>,
407 #[serde(skip_serializing_if = "Option::is_none")]
408 pub model: Option<String>,
409}
410
411impl RunCreateRequest {
412 pub fn new(assistant_id: impl Into<String>) -> Self {
413 Self {
414 assistant_id: assistant_id.into(),
415 instructions: None,
416 tools: None,
417 metadata: None,
418 model: None,
419 }
420 }
421}
422
423#[derive(Debug, Clone, Serialize, Deserialize)]
425#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
426pub struct Run {
427 pub id: String,
428 pub object: String,
429 pub created_at: i64,
430 pub thread_id: String,
431 pub assistant_id: String,
432 pub status: RunStatus,
433 #[serde(default)]
434 pub model: Option<String>,
435 #[serde(default)]
436 pub instructions: Option<String>,
437 #[serde(default)]
438 pub tools: Vec<BetaTool>,
439 #[serde(default)]
440 pub started_at: Option<i64>,
441 #[serde(default)]
442 pub completed_at: Option<i64>,
443 #[serde(default)]
444 pub cancelled_at: Option<i64>,
445 #[serde(default)]
446 pub failed_at: Option<i64>,
447 #[serde(default)]
448 pub metadata: Option<HashMap<String, String>>,
449}
450
451#[derive(Debug, Clone, Serialize)]
453#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
454pub struct SubmitToolOutputsRequest {
455 pub tool_outputs: Vec<ToolOutput>,
456}
457
458#[derive(Debug, Clone, Serialize)]
460#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
461pub struct ToolOutput {
462 pub tool_call_id: String,
463 pub output: String,
464}
465
466#[derive(Debug, Clone, Default, Serialize)]
470#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
471pub struct VectorStoreCreateRequest {
472 #[serde(skip_serializing_if = "Option::is_none")]
473 pub name: Option<String>,
474 #[serde(skip_serializing_if = "Option::is_none")]
475 pub file_ids: Option<Vec<String>>,
476 #[serde(skip_serializing_if = "Option::is_none")]
477 pub metadata: Option<HashMap<String, String>>,
478}
479
480#[derive(Debug, Clone, Serialize, Deserialize)]
482#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
483pub struct VectorStore {
484 pub id: String,
485 pub object: String,
486 pub created_at: i64,
487 #[serde(default)]
488 pub name: Option<String>,
489 pub status: VectorStoreStatus,
490 #[serde(default)]
491 pub file_counts: Option<VectorStoreFileCounts>,
492 #[serde(default)]
493 pub metadata: Option<HashMap<String, String>>,
494}
495
496#[derive(Debug, Clone, Serialize, Deserialize)]
498#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
499pub struct VectorStoreFileCounts {
500 pub in_progress: i64,
501 pub completed: i64,
502 pub failed: i64,
503 pub cancelled: i64,
504 pub total: i64,
505}
506
507#[derive(Debug, Clone, Serialize, Deserialize)]
509#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
510pub struct VectorStoreList {
511 pub object: String,
512 pub data: Vec<VectorStore>,
513 #[serde(default)]
515 pub has_more: Option<bool>,
516 #[serde(default)]
518 pub first_id: Option<String>,
519 #[serde(default)]
521 pub last_id: Option<String>,
522}
523
524#[derive(Debug, Clone, Serialize, Deserialize)]
526#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
527pub struct VectorStoreDeleted {
528 pub id: String,
529 pub deleted: bool,
530 pub object: String,
531}
532
533#[derive(Debug, Clone, Default)]
537pub struct AssistantListParams {
538 pub after: Option<String>,
540 pub before: Option<String>,
542 pub limit: Option<i64>,
544 pub order: Option<SortOrder>,
546}
547
548impl AssistantListParams {
549 pub fn new() -> Self {
550 Self::default()
551 }
552
553 pub fn after(mut self, after: impl Into<String>) -> Self {
554 self.after = Some(after.into());
555 self
556 }
557
558 pub fn before(mut self, before: impl Into<String>) -> Self {
559 self.before = Some(before.into());
560 self
561 }
562
563 pub fn limit(mut self, limit: i64) -> Self {
564 self.limit = Some(limit);
565 self
566 }
567
568 pub fn order(mut self, order: SortOrder) -> Self {
569 self.order = Some(order);
570 self
571 }
572
573 pub fn to_query(&self) -> Vec<(String, String)> {
575 let mut q = Vec::new();
576 if let Some(ref after) = self.after {
577 q.push(("after".into(), after.clone()));
578 }
579 if let Some(ref before) = self.before {
580 q.push(("before".into(), before.clone()));
581 }
582 if let Some(limit) = self.limit {
583 q.push(("limit".into(), limit.to_string()));
584 }
585 if let Some(ref order) = self.order {
586 q.push((
587 "order".into(),
588 serde_json::to_value(order)
589 .unwrap()
590 .as_str()
591 .unwrap()
592 .to_string(),
593 ));
594 }
595 q
596 }
597}
598
599#[derive(Debug, Clone, Default)]
601pub struct MessageListParams {
602 pub after: Option<String>,
604 pub before: Option<String>,
606 pub limit: Option<i64>,
608 pub order: Option<SortOrder>,
610 pub run_id: Option<String>,
612}
613
614impl MessageListParams {
615 pub fn new() -> Self {
616 Self::default()
617 }
618
619 pub fn after(mut self, after: impl Into<String>) -> Self {
620 self.after = Some(after.into());
621 self
622 }
623
624 pub fn before(mut self, before: impl Into<String>) -> Self {
625 self.before = Some(before.into());
626 self
627 }
628
629 pub fn limit(mut self, limit: i64) -> Self {
630 self.limit = Some(limit);
631 self
632 }
633
634 pub fn order(mut self, order: SortOrder) -> Self {
635 self.order = Some(order);
636 self
637 }
638
639 pub fn run_id(mut self, run_id: impl Into<String>) -> Self {
640 self.run_id = Some(run_id.into());
641 self
642 }
643
644 pub fn to_query(&self) -> Vec<(String, String)> {
646 let mut q = Vec::new();
647 if let Some(ref after) = self.after {
648 q.push(("after".into(), after.clone()));
649 }
650 if let Some(ref before) = self.before {
651 q.push(("before".into(), before.clone()));
652 }
653 if let Some(limit) = self.limit {
654 q.push(("limit".into(), limit.to_string()));
655 }
656 if let Some(ref order) = self.order {
657 q.push((
658 "order".into(),
659 serde_json::to_value(order)
660 .unwrap()
661 .as_str()
662 .unwrap()
663 .to_string(),
664 ));
665 }
666 if let Some(ref run_id) = self.run_id {
667 q.push(("run_id".into(), run_id.clone()));
668 }
669 q
670 }
671}
672
673#[derive(Debug, Clone, Default)]
675pub struct VectorStoreListParams {
676 pub after: Option<String>,
678 pub before: Option<String>,
680 pub limit: Option<i64>,
682 pub order: Option<SortOrder>,
684}
685
686impl VectorStoreListParams {
687 pub fn new() -> Self {
688 Self::default()
689 }
690
691 pub fn after(mut self, after: impl Into<String>) -> Self {
692 self.after = Some(after.into());
693 self
694 }
695
696 pub fn before(mut self, before: impl Into<String>) -> Self {
697 self.before = Some(before.into());
698 self
699 }
700
701 pub fn limit(mut self, limit: i64) -> Self {
702 self.limit = Some(limit);
703 self
704 }
705
706 pub fn order(mut self, order: SortOrder) -> Self {
707 self.order = Some(order);
708 self
709 }
710
711 pub fn to_query(&self) -> Vec<(String, String)> {
713 let mut q = Vec::new();
714 if let Some(ref after) = self.after {
715 q.push(("after".into(), after.clone()));
716 }
717 if let Some(ref before) = self.before {
718 q.push(("before".into(), before.clone()));
719 }
720 if let Some(limit) = self.limit {
721 q.push(("limit".into(), limit.to_string()));
722 }
723 if let Some(ref order) = self.order {
724 q.push((
725 "order".into(),
726 serde_json::to_value(order)
727 .unwrap()
728 .as_str()
729 .unwrap()
730 .to_string(),
731 ));
732 }
733 q
734 }
735}
736
737#[derive(Debug, Clone, Default)]
739pub struct RunListParams {
740 pub after: Option<String>,
742 pub before: Option<String>,
744 pub limit: Option<i64>,
746 pub order: Option<SortOrder>,
748}
749
750impl RunListParams {
751 pub fn new() -> Self {
752 Self::default()
753 }
754
755 pub fn after(mut self, after: impl Into<String>) -> Self {
756 self.after = Some(after.into());
757 self
758 }
759
760 pub fn before(mut self, before: impl Into<String>) -> Self {
761 self.before = Some(before.into());
762 self
763 }
764
765 pub fn limit(mut self, limit: i64) -> Self {
766 self.limit = Some(limit);
767 self
768 }
769
770 pub fn order(mut self, order: SortOrder) -> Self {
771 self.order = Some(order);
772 self
773 }
774
775 pub fn to_query(&self) -> Vec<(String, String)> {
777 let mut q = Vec::new();
778 if let Some(ref after) = self.after {
779 q.push(("after".into(), after.clone()));
780 }
781 if let Some(ref before) = self.before {
782 q.push(("before".into(), before.clone()));
783 }
784 if let Some(limit) = self.limit {
785 q.push(("limit".into(), limit.to_string()));
786 }
787 if let Some(ref order) = self.order {
788 q.push((
789 "order".into(),
790 serde_json::to_value(order)
791 .unwrap()
792 .as_str()
793 .unwrap()
794 .to_string(),
795 ));
796 }
797 q
798 }
799}