Skip to content

Commit 524f0b5

Browse files
author
hfhoffman1144
committed
tech review updates
1 parent e54ab48 commit 524f0b5

File tree

5 files changed

+42
-28
lines changed

5 files changed

+42
-28
lines changed

python-langgraph/chains/notice_extraction.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from datetime import date
2-
1+
from datetime import datetime, date
32
from langchain_core.prompts import ChatPromptTemplate
43
from langchain_openai import ChatOpenAI
5-
from pydantic import BaseModel, EmailStr, Field
4+
from pydantic import BaseModel, Field, computed_field
65

76

87
class 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

6186
info_parse_prompt = ChatPromptTemplate.from_messages(
6287
[

python-langgraph/graphs/email_agent.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import logging
21
import time
3-
42
from chains.notice_extraction import NoticeEmailExtract
53
from graphs.notice_extraction import NOTICE_EXTRACTION_GRAPH
64
from langchain_core.messages import AIMessage
75
from langchain_core.tools import tool
86
from langchain_openai import ChatOpenAI
97
from langgraph.graph import END, START, MessagesState, StateGraph
108
from langgraph.prebuilt import ToolNode
11-
12-
logging.basicConfig(
13-
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
14-
)
15-
LOGGER = logging.getLogger(__name__)
9+
from utils.logging_config import LOGGER
1610

1711

1812
@tool

python-langgraph/graphs/notice_extraction.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import logging
21
from typing import TypedDict
3-
42
from chains.binary_questions import BINARY_QUESTION_CHAIN
53
from chains.escalation_check import ESCALATION_CHECK_CHAIN
64
from chains.notice_extraction import NOTICE_PARSER_CHAIN, NoticeEmailExtract
75
from langgraph.graph import END, START, StateGraph
86
from pydantic import EmailStr
97
from utils.graph_utils import create_legal_ticket, send_escalation_email
10-
11-
logging.basicConfig(
12-
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
13-
)
14-
LOGGER = logging.getLogger(__name__)
8+
from utils.logging_config import LOGGER
159

1610

1711
class GraphState(TypedDict):

python-langgraph/utils/graph_utils.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import logging
21
import random
32
import time
4-
5-
from chains.notice_extraction import NoticeEmailExtract
63
from pydantic import EmailStr
7-
8-
logging.basicConfig(
9-
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
10-
)
11-
LOGGER = logging.getLogger(__name__)
4+
from chains.notice_extraction import NoticeEmailExtract
5+
from utils.logging_config import LOGGER
126

137

148
def send_escalation_email(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import logging
2+
3+
logging.getLogger("httpx").setLevel(logging.WARNING)
4+
logging.basicConfig(
5+
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
6+
)
7+
LOGGER = logging.getLogger(__name__)

0 commit comments

Comments
 (0)