-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Metadata to every Maintenance, addresses issue #246 #249
Merged
+164
−30
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3aba61f
feat: :sparkles: OpenAI parser
chadell a4eec2e
refinement in logic
chadell e7ace76
logic refinement
chadell c98bf4c
Update README.md
chadell 0f9dcf6
Update circuit_maintenance_parser/parser.py
chadell 5eec491
improve question
chadell 6094f3f
make more explicit the text parsing
chadell 86f8154
Automate token management for local tests
chadell de559e8
Make openai library an extra
chadell 38c43bf
Adopt OpenAI library changes
chadell 1656bef
fix mypy
chadell 1dbec38
feat: :sparkles: Metadata for every Maintenance
chadell c328d56
Merge remote-tracking branch 'origin/develop' into issue-246-metadata
chadell 0fe9306
fix tests
chadell 84e5141
update readme
chadell 8510326
Add a boolean in Metadata to reflect LLM parsing
chadell 249ee16
Update circuit_maintenance_parser/parser.py
chadell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This throws KeyError if _metadata key isn't present, thus this change becomes a breaking change.
Some of my existing tests used in my projects start to throw KeyError exception. For example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like Maintenance dataclass is now expecting _metadata to be supplied by users. can't it default to None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @csessh for reporting. I'm going to check and fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking the code, I see that the
_metadata
is injected by theProcessors
automatically, so I don't get why don't you get it in your tests.