1- from datetime import date
2-
1+ from datetime import datetime , date
32from langchain_core .prompts import ChatPromptTemplate
43from langchain_openai import ChatOpenAI
5- from pydantic import BaseModel , EmailStr , Field
4+ from pydantic import BaseModel , Field , computed_field
65
76
87class NoticeEmailExtract (BaseModel ):
9- date_of_notice : date | None = Field (
8+ date_of_notice_str : str | None = Field (
109 default = None ,
10+ exclude = True ,
11+ repr = False ,
1112 description = """The date of the notice (if any) reformatted
1213 to match YYYY-mm-dd""" ,
1314 )
@@ -21,7 +22,7 @@ class NoticeEmailExtract(BaseModel):
2122 description = """The phone number of the entity sending the notice
2223 (if present in the message)""" ,
2324 )
24- entity_email : EmailStr | None = Field (
25+ entity_email : str | None = Field (
2526 default = None ,
2627 description = """The email of the entity sending the notice
2728 (if present in the message)""" ,
@@ -46,8 +47,10 @@ class NoticeEmailExtract(BaseModel):
4647 description = """The required changes specified by the entity
4748 (if present in the message)""" ,
4849 )
49- compliance_deadline : date | None = Field (
50+ compliance_deadline_str : str | None = Field (
5051 default = None ,
52+ exclude = True ,
53+ repr = False ,
5154 description = """The date that the company must comply (if any)
5255 reformatted to match YYYY-mm-dd""" ,
5356 )
@@ -57,6 +60,28 @@ class NoticeEmailExtract(BaseModel):
5760 (if any)""" ,
5861 )
5962
63+ @computed_field
64+ @property
65+ def date_of_notice (self ) -> date | None :
66+ try :
67+ return datetime .strptime (
68+ self .date_of_notice_str , "%Y-%m-%d"
69+ ).date ()
70+ except Exception as e :
71+ print (e )
72+ return None
73+
74+ @computed_field
75+ @property
76+ def compliance_deadline (self ) -> date | None :
77+ try :
78+ return datetime .strptime (
79+ self .compliance_deadline_str , "%Y-%m-%d"
80+ ).date ()
81+ except Exception as e :
82+ print (e )
83+ return None
84+
6085
6186info_parse_prompt = ChatPromptTemplate .from_messages (
6287 [
0 commit comments