-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: ✨ OpenAI parser * refinement in logic * logic refinement * Update README.md Co-authored-by: Glenn Matthews <[email protected]> * Update circuit_maintenance_parser/parser.py Co-authored-by: Glenn Matthews <[email protected]> * improve question * make more explicit the text parsing * Automate token management for local tests * Make openai library an extra * Adopt OpenAI library changes * fix mypy * feat: ✨ Metadata for every Maintenance * fix tests * update readme * Add a boolean in Metadata to reflect LLM parsing * Update circuit_maintenance_parser/parser.py Co-authored-by: Glenn Matthews <[email protected]> --------- Co-authored-by: Glenn Matthews <[email protected]>
- Loading branch information
1 parent
13dfea4
commit 9ba38f0
Showing
7 changed files
with
164 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
from typing import List | ||
|
||
from pydantic import BaseModel, validator, StrictStr, StrictInt, Extra | ||
from pydantic import BaseModel, validator, StrictStr, StrictInt, Extra, PrivateAttr | ||
|
||
|
||
class Impact(str, Enum): | ||
|
@@ -91,6 +91,15 @@ def validate_impact_type(cls, value): | |
return value | ||
|
||
|
||
class Metadata(BaseModel): | ||
"""Metadata class to provide context about the Maintenance object.""" | ||
|
||
provider: StrictStr | ||
processor: StrictStr | ||
parsers: List[StrictStr] | ||
generated_by_llm: bool = False | ||
|
||
|
||
class Maintenance(BaseModel, extra=Extra.forbid): | ||
"""Maintenance class. | ||
|
@@ -113,6 +122,11 @@ class Maintenance(BaseModel, extra=Extra.forbid): | |
order | ||
Example: | ||
>>> metadata = Metadata( | ||
... processor="SimpleProcessor", | ||
... provider="genericprovider", | ||
... parsers=["EmailDateParser"] | ||
... ) | ||
>>> Maintenance( | ||
... account="12345000", | ||
... end=1533712380, | ||
|
@@ -126,6 +140,7 @@ class Maintenance(BaseModel, extra=Extra.forbid): | |
... status="COMPLETED", | ||
... summary="This is a maintenance notification", | ||
... uid="1111", | ||
... _metadata=metadata, | ||
... ) | ||
Maintenance(provider='A random NSP', account='12345000', maintenance_id='VNOC-1-99999999999', status=<Status.COMPLETED: 'COMPLETED'>, circuits=[CircuitImpact(circuit_id='123', impact=<Impact.NO_IMPACT: 'NO-IMPACT'>), CircuitImpact(circuit_id='456', impact=<Impact.OUTAGE: 'OUTAGE'>)], start=1533704400, end=1533712380, stamp=1533595768, organizer='[email protected]', uid='1111', sequence=1, summary='This is a maintenance notification') | ||
""" | ||
|
@@ -139,12 +154,18 @@ class Maintenance(BaseModel, extra=Extra.forbid): | |
end: StrictInt | ||
stamp: StrictInt | ||
organizer: StrictStr | ||
_metadata: Metadata = PrivateAttr() | ||
|
||
# Non mandatory attributes | ||
uid: StrictStr = "0" | ||
sequence: StrictInt = 1 | ||
summary: StrictStr = "" | ||
|
||
def __init__(self, **data): | ||
"""Initialize the Maintenance object.""" | ||
self._metadata = data.pop("_metadata") | ||
super().__init__(**data) | ||
|
||
# pylint: disable=no-self-argument | ||
@validator("status") | ||
def validate_status_type(cls, value): | ||
|
@@ -185,3 +206,8 @@ def slug(self) -> str: | |
def to_json(self) -> str: | ||
"""Get JSON representation of the class object.""" | ||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=2) | ||
|
||
@property | ||
def metadata(self): | ||
"""Get Maintenance Metadata.""" | ||
return self._metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.