-
Notifications
You must be signed in to change notification settings - Fork 36
feat: Added support for new task type Tag Detection for Workflows #2342
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
base: master
Are you sure you want to change the base?
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2342 +/- ##
==========================================
+ Coverage 90.96% 90.98% +0.01%
==========================================
Files 192 192
Lines 26138 26217 +79
==========================================
+ Hits 23777 23853 +76
- Misses 2361 2364 +3
🚀 New features to boost your workflow:
|
doctrino
left a comment
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 seems to not be completed. Lots of the spec is missing.
|
doctrino
left a comment
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.
Good job. There are a few minor fixes that are necessary.
Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
Co-authored-by: Anders Albert <60234212+doctrino@users.noreply.github.com>
…low-task' into tag-detection-workflow-task
doctrino
left a comment
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.
Good stuff :)
|
One thing to consider, should we have raise an alpha warning everytime a TagDetectionParameter is initialized? I assume this feature is in alpha? |
It is in private beta, does the same apply? |
arnels
left a comment
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 looks good. Could you please add unit tests for the new classes? Since they contain custom logic for serialization/deserialization in methods like _load and dump, it's important to ensure that logic is covered.
Just to narrow this a bit, any object inheriting from e.g. Other class hierarchies must be tested, e.g. subclasses of |
|
Sorry for the late review, was on vacation. Making some last changes to the API spec before the testing is commencing (out-of-sync updates and some small breaking changes). Will write a summary here when ready. Waiting for this PR to be merged on the Jazz side: |
|
The pr above has been merged. @ronpal @VerstraeteBert |
|
@ronpal
|
@VerstraeteBert can you please review again? These are the commits that address these changes 👆 |
cbc7008 to
3f79906
Compare
|
/gemini review |
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.
Code Review
This pull request adds support for the new tagDetection task type in Workflows. The changes include new data classes for the task parameters and output, as well as integrating it into the existing workflow structure. The implementation is mostly solid, but I've identified a critical issue with loading optional parameters that could lead to runtime errors, and some inconsistencies with the project's naming conventions and API consistency. Addressing these points will improve the robustness and maintainability of the new feature.
| min_tokens=tag_detection["minTokens"], | ||
| partial_match=tag_detection["partialMatch"], | ||
| write_annotations=tag_detection["writeAnnotations"], |
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.
The _load method should handle optional fields gracefully. Accessing minTokens, partialMatch, and writeAnnotations with [] will raise a KeyError if they are not present in the API response. Since these are optional in __init__, you should use the .get() method to avoid potential runtime errors.
| min_tokens=tag_detection["minTokens"], | |
| partial_match=tag_detection["partialMatch"], | |
| write_annotations=tag_detection["writeAnnotations"], | |
| min_tokens=tag_detection.get("minTokens"), | |
| partial_match=tag_detection.get("partialMatch"), | |
| write_annotations=tag_detection.get("writeAnnotations", False), |
| def __init__(self, instanceId: NodeId, page_range: PageRange, error_message: str | None) -> None: | ||
| self.instanceId = instanceId | ||
| self.page_range = page_range | ||
| self.error_message = error_message |
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.
The parameter instanceId and attribute self.instanceId should be instance_id to adhere to the snake_case naming convention specified in the style guide.1 You will also need to update the dump method to use self.instance_id.
| def __init__(self, instanceId: NodeId, page_range: PageRange, error_message: str | None) -> None: | |
| self.instanceId = instanceId | |
| self.page_range = page_range | |
| self.error_message = error_message | |
| def __init__(self, instance_id: NodeId, page_range: PageRange, error_message: str | None) -> None: | |
| self.instance_id = instance_id | |
| self.page_range = page_range | |
| self.error_message = error_message |
Style Guide References
Footnotes
-
The style guide requires
snake_casefor variable and function names. ↩
| def __init__( | ||
| self, | ||
| jobId: int, | ||
| status: TagDetectionStatus, | ||
| filePageRanges: list[TagDetectionJobFilePageRange], | ||
| errorMessage: str | None, | ||
| ) -> None: | ||
| self.jobId = jobId | ||
| self.status = status | ||
| self.filePageRanges = filePageRanges | ||
| self.errorMessage = errorMessage |
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.
The parameters jobId, filePageRanges, and errorMessage and their corresponding attributes should be job_id, file_page_ranges, and error_message to follow the snake_case naming convention from the style guide.1 You will also need to update the _load and dump methods to use these new attribute names.
| def __init__( | |
| self, | |
| jobId: int, | |
| status: TagDetectionStatus, | |
| filePageRanges: list[TagDetectionJobFilePageRange], | |
| errorMessage: str | None, | |
| ) -> None: | |
| self.jobId = jobId | |
| self.status = status | |
| self.filePageRanges = filePageRanges | |
| self.errorMessage = errorMessage | |
| def __init__( | |
| self, | |
| job_id: int, | |
| status: TagDetectionStatus, | |
| file_page_ranges: list[TagDetectionJobFilePageRange], | |
| error_message: str | None, | |
| ) -> None: | |
| self.job_id = job_id | |
| self.status = status | |
| self.file_page_ranges = file_page_ranges | |
| self.error_message = error_message |
Style Guide References
Footnotes
-
The style guide requires
snake_casefor variable and function names. ↩
| output = data["output"] | ||
| return cls([TagDetectionJob.load(tagDetectionJob) for tagDetectionJob in output["jobs"]]) | ||
|
|
||
| def dump(self, camel_case: bool = False) -> dict[str, Any]: |
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.
The default value for camel_case in the dump method is False, which is inconsistent with most other WorkflowTaskOutput subclasses that default to True. For consistency across the SDK, it's better to use True as the default.
| def dump(self, camel_case: bool = False) -> dict[str, Any]: | |
| def dump(self, camel_case: bool = True) -> dict[str, Any]: |
|
@ronpal Going through old PRs that have been "stuck", this seems like it needs a team-review, and potentially some follow-ups of the Gemini feedback (I haven't looked at whether it is sensible things it raises). Could you please help us figure out if this PR is still relevant to risk-review? And get a team-review so it is ready? |

Description
Added new task type to Workflows based on spec
https://pr-2871.specs.preview.cogniteapp.com/20230101-internal.json.html#tag/Workflow-versions/operation/CreateOrUpdateWorkflowVersion
Checklist:
If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.