1use serde::{de::DeserializeOwned, Deserialize, Serialize};
8
9use super::Purpose;
10
11pub mod content;
12pub mod content_checked;
13pub mod delete;
14pub mod list;
15pub mod metadata;
16pub mod upload;
17
18pub trait FilePurpose {
19 fn purpose(&self) -> Purpose;
20}
21pub trait ValidFile {}
22#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct Search<T = ()> {
27 pub text: String,
28 pub metadata: T,
29}
30#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct Answers<T = ()> {
35 pub text: String,
36 pub metadata: T,
37}
38#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct Classifications<T = ()> {
43 pub text: String,
44 pub label: String,
45 pub metadata: T,
46}
47#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct FineTuning {
52 pub prompt: String,
53 pub completion: String,
54}
55#[derive(Debug, Clone)]
56pub struct Raw {
57 pub name: String,
58 pub data: String,
59 pub purpose: Purpose,
60}
61
62#[derive(Debug, Clone, Deserialize)]
63pub struct File<T> {
64 #[serde(skip)]
65 pub name: String,
66 pub lines: Vec<T>,
67}
68
69impl<T> File<T> {
70 pub fn new(name: String, lines: Vec<T>) -> Self {
71 File { name, lines }
72 }
73}
74
75impl<T: Serialize + DeserializeOwned> FilePurpose for File<Search<T>> {
76 fn purpose(&self) -> Purpose {
77 Purpose::Search
78 }
79}
80impl<T: Serialize> FilePurpose for File<Answers<T>> {
81 fn purpose(&self) -> Purpose {
82 Purpose::Answers
83 }
84}
85
86impl<T: Serialize> FilePurpose for File<Classifications<T>> {
87 fn purpose(&self) -> Purpose {
88 Purpose::Classifications
89 }
90}
91
92impl FilePurpose for File<FineTuning> {
93 fn purpose(&self) -> Purpose {
94 Purpose::FineTuning
95 }
96}
97impl FilePurpose for Raw {
98 fn purpose(&self) -> Purpose {
99 self.purpose
100 }
101}
102impl<T> ValidFile for File<Search<T>> {}
103impl<T> ValidFile for File<Answers<T>> {}
104impl<T> ValidFile for File<Classifications<T>> {}
105impl ValidFile for File<FineTuning> {}
106impl ValidFile for Raw {}