44class MySettings (BaseModel ):
55 email : str = "your.email@mail.com"
66 top_references : int = 5
7+ top_n_articles : int = 10
8+ citation_weight : float = 0.7
9+ year_weight : float = 0.5
10+ journal_weight : float = 0.9
711
812 @field_validator ("email" )
913 @classmethod
@@ -12,6 +16,43 @@ def email_validator(cls, email):
1216 raise ValueError ("Invalid email address" )
1317 elif "your.email@mail.com" == email :
1418 raise ValueError ("Please set your email address" )
19+
20+ @field_validator ("top_references" )
21+ @classmethod
22+ def top_references_validator (cls , top_references ):
23+ assert isinstance (top_references , int ), f"Top references is { type (top_references )} , it must be an integer"
24+ if top_references < 0 :
25+ raise ValueError ("Invalid top references" )
26+
27+
28+ @field_validator ("top_n_articles" )
29+ @classmethod
30+ def top_n_articles_validator (cls , top_n_articles ):
31+ assert isinstance (top_n_articles , int ), f"Top n articles is { type (top_n_articles )} , it must be an integer"
32+ if top_n_articles < 0 :
33+ raise ValueError ("Invalid top n articles" )
34+
35+ @field_validator ("citation_weight" )
36+ @classmethod
37+ def citation_weight_validator (cls , citation_weight ):
38+ assert isinstance (citation_weight , float ), f"Citation weight is { type (citation_weight )} , it must be a float"
39+ if citation_weight < 0 or citation_weight > 1 :
40+ raise ValueError ("Invalid citation weight" )
41+
42+ @field_validator ("year_weight" )
43+ @classmethod
44+ def year_weight_validator (cls , year_weight ):
45+ assert isinstance (year_weight , float ), f"Year weight is { type (year_weight )} , it must be a float"
46+ if year_weight < 0 or year_weight > 1 :
47+ raise ValueError ("Invalid year weight" )
48+
49+ @field_validator ("journal_weight" )
50+ @classmethod
51+ def journal_weight_validator (cls , journal_weight ):
52+ assert isinstance (journal_weight , float ), f"Journal weight is { type (journal_weight )} , it must be a float"
53+ if journal_weight < 0 or journal_weight > 1 :
54+ raise ValueError ("Invalid journal weight" )
55+
1556
1657@plugin
1758def settings_model ():
0 commit comments