-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path_types.py
68 lines (56 loc) · 1.71 KB
/
_types.py
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
57
58
59
60
61
62
63
64
65
66
67
68
import re
from dataclasses import asdict, dataclass, field
from datetime import datetime
from enum import Enum
class Focus(str, Enum):
Offensive = "Offensive"
Defensive = "Defensive"
Adversarial = "Adversarial"
Safety = "Safety"
Other = "Other"
class AttackType(str, Enum):
ModelEvasion = "Evasion"
ModelExtraction = "Extraction"
ModelInversion = "Inversion"
ModelPoisoning = "Poisoning"
PromptInjection = "Prompt Injection"
Other = "Other"
@dataclass
class Paper:
# Note: These need to reflect in the Notion DB and
# notion_utils functions.
page_id: str | None = None
title: str | None = None
url: str | None = None
focus: Focus | None = None
attack_type: AttackType | None = None
summary: str | None = None
abstract: str | None = None
authors: list[str] = field(default_factory=list)
published: datetime | None = None
explored: bool | None = None
# We don't want to excessively write back to Notion, so we'll
# offer the ability to set change tracking when we read.
track_changes: bool = False
def __post_init__(self):
self._original_state = asdict(self)
def has_changed(self):
if self.track_changes:
return self._original_state != asdict(self)
else:
return True
def has_arxiv_props(self) -> bool:
return all(
[
self.title,
self.url,
self.authors,
self.published,
]
)
@property
def arxiv_id(self) -> str | None:
if not self.url:
return None
match = re.search(r"\d{4}\.\d{5}", self.url)
return match.group(0) if match else None