a2a-source-edit: write agent.py
This commit is contained in:
8
agent.py
8
agent.py
@@ -54,6 +54,7 @@ AMBIGUOUS_DATE_RE = re.compile(
|
|||||||
re.IGNORECASE,
|
re.IGNORECASE,
|
||||||
)
|
)
|
||||||
RENEWAL_RE = re.compile(r"\brenew(?:s|al|ed|ing)?\b", re.IGNORECASE)
|
RENEWAL_RE = re.compile(r"\brenew(?:s|al|ed|ing)?\b", re.IGNORECASE)
|
||||||
|
DEADLINE_KIND_ORDER = {"renewal": 0, "notice": 1, "obligation": 2}
|
||||||
|
|
||||||
|
|
||||||
class ContractClockStudioV1Config(BaseModel):
|
class ContractClockStudioV1Config(BaseModel):
|
||||||
@@ -443,13 +444,16 @@ def extract_timeline(text: str) -> ExtractedTimeline:
|
|||||||
elif RENEWAL_RE.search(text):
|
elif RENEWAL_RE.search(text):
|
||||||
warnings.append("No explicit notice-window duration was found for the renewal date.")
|
warnings.append("No explicit notice-window duration was found for the renewal date.")
|
||||||
|
|
||||||
order = {"renewal": 0, "notice": 1, "obligation": 2}
|
|
||||||
deduped: dict[tuple[str, str], Deadline] = {}
|
deduped: dict[tuple[str, str], Deadline] = {}
|
||||||
for deadline in sorted(deadlines, key=lambda item: (order[item.kind], item.date, item.summary)):
|
for deadline in sorted(deadlines, key=deadline_sort_key):
|
||||||
deduped.setdefault((deadline.kind, deadline.date), deadline)
|
deduped.setdefault((deadline.kind, deadline.date), deadline)
|
||||||
return ExtractedTimeline(deadlines=list(deduped.values()), warnings=warnings)
|
return ExtractedTimeline(deadlines=list(deduped.values()), warnings=warnings)
|
||||||
|
|
||||||
|
|
||||||
|
def deadline_sort_key(deadline: Deadline) -> tuple[int, str, str]:
|
||||||
|
return (DEADLINE_KIND_ORDER[deadline.kind], deadline.date, deadline.summary)
|
||||||
|
|
||||||
|
|
||||||
def source_excerpt(text: str, start: int, end: int, radius: int = 140) -> str:
|
def source_excerpt(text: str, start: int, end: int, radius: int = 140) -> str:
|
||||||
left = max(0, start - radius)
|
left = max(0, start - radius)
|
||||||
right = min(len(text), end + radius)
|
right = min(len(text), end + radius)
|
||||||
|
|||||||
Reference in New Issue
Block a user