forked from rnadigital/agentcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.rs
56 lines (51 loc) · 1.2 KB
/
models.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
#[derive(Debug, Clone, Default)]
pub struct Document {
pub page_content: String,
pub metadata: Option<HashMap<String, String>>,
pub embedding_vector: Option<Vec<f32>>,
}
impl Document {
pub fn new(
page_content: String,
metadata: Option<HashMap<String, String>>,
embedding_vector: Option<Vec<f32>>,
) -> Self {
Document {
page_content,
metadata,
embedding_vector,
}
}
}
impl PartialEq for Document {
fn eq(&self, other: &Self) -> bool {
self.page_content == other.page_content
}
}
impl Eq for Document {}
impl Hash for Document {
fn hash<H: Hasher>(&self, state: &mut H) {
self.page_content.hash(state);
}
}
#[derive(Copy, Clone)]
pub enum FileType {
PDF,
TXT,
CSV,
DOCX,
UNKNOWN,
}
impl From<String> for FileType {
fn from(value: String) -> Self {
match value.as_str() {
"pdf" => Self::PDF,
"txt" => Self::TXT,
"csv" => Self::CSV,
"docx" | "pptx" | "xlsx" | "odt" | "ods" | "odp" => Self::DOCX,
_ => Self::UNKNOWN,
}
}
}