-
Notifications
You must be signed in to change notification settings - Fork 6
Expose priming group #411
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
Expose priming group #411
Changes from all commits
3b91100
5649fd0
288c9ba
407c80c
65bab3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -352,6 +352,7 @@ def _prep_create_detector( # noqa: PLR0913 # pylint: disable=too-many-arguments | |
| patience_time: Optional[float] = None, | ||
| pipeline_config: Optional[str] = None, | ||
| metadata: Union[dict, str, None] = None, | ||
| priming_group_id: Optional[str] = None, | ||
| ) -> Detector: | ||
| """ | ||
| A helper function to prepare the input for creating a detector. Individual create_detector | ||
|
|
@@ -372,6 +373,8 @@ def _prep_create_detector( # noqa: PLR0913 # pylint: disable=too-many-arguments | |
| patience_time = float(patience_time) | ||
| if patience_time: | ||
| detector_creation_input.patience_time = patience_time | ||
| if priming_group_id is not None: | ||
| detector_creation_input.priming_group_id = priming_group_id | ||
| return detector_creation_input | ||
|
|
||
| def create_detector( # noqa: PLR0913 | ||
|
|
@@ -386,6 +389,7 @@ def create_detector( # noqa: PLR0913 | |
| pipeline_config: Optional[str] = None, | ||
| metadata: Union[dict, str, None] = None, | ||
| class_names: Optional[Union[List[str], str]] = None, | ||
| priming_group_id: Optional[str] = None, | ||
| ) -> Detector: | ||
| """ | ||
| Create a new Detector with a given name and query. | ||
|
|
@@ -443,6 +447,7 @@ def create_detector( # noqa: PLR0913 | |
| metadata later by calling `get_detector()`. | ||
| :param class_names: The name or names of the class to use for the detector. Only used for multi-class | ||
| and counting detectors. | ||
| :param priming_group_id: Optional ID of an existing PrimingGroup to associate with this detector. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should callout that a 3rd party won't know what valid ones are and not to use it. |
||
|
|
||
| :return: The created Detector object | ||
| """ | ||
|
|
@@ -458,6 +463,7 @@ def create_detector( # noqa: PLR0913 | |
| patience_time=patience_time, | ||
| pipeline_config=pipeline_config, | ||
| metadata=metadata, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
| if mode == ModeEnum.COUNT: | ||
| if class_names is None: | ||
|
|
@@ -473,6 +479,7 @@ def create_detector( # noqa: PLR0913 | |
| patience_time=patience_time, | ||
| pipeline_config=pipeline_config, | ||
| metadata=metadata, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
| if mode == ModeEnum.MULTI_CLASS: | ||
| if class_names is None: | ||
|
|
@@ -488,6 +495,7 @@ def create_detector( # noqa: PLR0913 | |
| patience_time=patience_time, | ||
| pipeline_config=pipeline_config, | ||
| metadata=metadata, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
| raise ValueError( | ||
| f"Unsupported mode: {mode}, check if your desired mode is only supported in the ExperimentalApi" | ||
|
|
@@ -1557,6 +1565,7 @@ def create_counting_detector( # noqa: PLR0913 # pylint: disable=too-many-argume | |
| patience_time: Optional[float] = None, | ||
| pipeline_config: Optional[str] = None, | ||
| metadata: Union[dict, str, None] = None, | ||
| priming_group_id: Optional[str] = None, | ||
| ) -> Detector: | ||
| """ | ||
| Creates a counting detector that can count objects in images up to a specified maximum count. | ||
|
|
@@ -1595,6 +1604,7 @@ def create_counting_detector( # noqa: PLR0913 # pylint: disable=too-many-argume | |
| the detector (limited to 1KB). This metadata can be used to store additional | ||
| information like location, purpose, or related system IDs. You can retrieve this | ||
| metadata later by calling `get_detector()`. | ||
| :param priming_group_id: Optional ID of an existing PrimingGroup to associate with this detector. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should callout that a 3rd party won't know what valid ones are and not to use it. |
||
|
|
||
| :return: The created Detector object | ||
| """ | ||
|
|
@@ -1607,6 +1617,7 @@ def create_counting_detector( # noqa: PLR0913 # pylint: disable=too-many-argume | |
| patience_time=patience_time, | ||
| pipeline_config=pipeline_config, | ||
| metadata=metadata, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
| detector_creation_input.mode = ModeEnum.COUNT | ||
|
|
||
|
|
@@ -1629,6 +1640,7 @@ def create_binary_detector( # noqa: PLR0913 # pylint: disable=too-many-argument | |
| patience_time: Optional[float] = None, | ||
| pipeline_config: Optional[str] = None, | ||
| metadata: Union[dict, str, None] = None, | ||
| priming_group_id: Optional[str] = None, | ||
| ) -> Detector: | ||
| """ | ||
| Creates a binary detector with the given name and query. | ||
|
|
@@ -1656,6 +1668,7 @@ def create_binary_detector( # noqa: PLR0913 # pylint: disable=too-many-argument | |
| patience_time=patience_time, | ||
| pipeline_config=pipeline_config, | ||
| metadata=metadata, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
| obj = self.detectors_api.create_detector(detector_creation_input, _request_timeout=DEFAULT_REQUEST_TIMEOUT) | ||
| return Detector.parse_obj(obj.to_dict()) | ||
|
|
@@ -1671,6 +1684,7 @@ def create_multiclass_detector( # noqa: PLR0913 # pylint: disable=too-many-argu | |
| patience_time: Optional[float] = None, | ||
| pipeline_config: Optional[str] = None, | ||
| metadata: Union[dict, str, None] = None, | ||
| priming_group_id: Optional[str] = None, | ||
| ) -> Detector: | ||
| """ | ||
| Creates a multiclass detector with the given name and query. | ||
|
|
@@ -1705,6 +1719,7 @@ def create_multiclass_detector( # noqa: PLR0913 # pylint: disable=too-many-argu | |
| the detector (limited to 1KB). This metadata can be used to store additional | ||
| information like location, purpose, or related system IDs. You can retrieve this | ||
| metadata later by calling `get_detector()`. | ||
| :param priming_group_id: Optional ID of an existing PrimingGroup to associate with this detector. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should callout that a 3rd party won't know what valid ones are and not to use it. |
||
|
|
||
| :return: The created Detector object | ||
| """ | ||
|
|
@@ -1717,6 +1732,7 @@ def create_multiclass_detector( # noqa: PLR0913 # pylint: disable=too-many-argu | |
| patience_time=patience_time, | ||
| pipeline_config=pipeline_config, | ||
| metadata=metadata, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
| detector_creation_input.mode = ModeEnum.MULTI_CLASS | ||
| mode_config = MultiClassModeConfiguration(class_names=class_names) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -644,6 +644,7 @@ def create_bounding_box_detector( # noqa: PLR0913 # pylint: disable=too-many-ar | |
| patience_time: Optional[float] = None, | ||
| pipeline_config: Optional[str] = None, | ||
| metadata: Union[dict, str, None] = None, | ||
| priming_group_id: Optional[str] = None, | ||
| ) -> Detector: | ||
| """ | ||
| Creates a bounding box detector that can detect objects in images up to a specified maximum number of bounding | ||
|
|
@@ -684,6 +685,7 @@ def create_bounding_box_detector( # noqa: PLR0913 # pylint: disable=too-many-ar | |
| the detector (limited to 1KB). This metadata can be used to store additional | ||
| information like location, purpose, or related system IDs. You can retrieve this | ||
| metadata later by calling `get_detector()`. | ||
| :param priming_group_id: Optional ID of an existing PrimingGroup to associate with this detector. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should callout that a 3rd party won't know what valid ones are and not to use it. |
||
|
|
||
| :return: The created Detector object | ||
| """ | ||
|
|
@@ -696,6 +698,7 @@ def create_bounding_box_detector( # noqa: PLR0913 # pylint: disable=too-many-ar | |
| patience_time=patience_time, | ||
| pipeline_config=pipeline_config, | ||
| metadata=metadata, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
| detector_creation_input.mode = ModeEnum.BOUNDING_BOX | ||
|
|
||
|
|
@@ -718,6 +721,7 @@ def create_text_recognition_detector( # noqa: PLR0913 # pylint: disable=too-man | |
| patience_time: Optional[float] = None, | ||
| pipeline_config: Optional[str] = None, | ||
| metadata: Union[dict, str, None] = None, | ||
| priming_group_id: Optional[str] = None, | ||
| ) -> Detector: | ||
| """ | ||
| Creates a text recognition detector that can read specified spans of text from images. | ||
|
|
@@ -742,6 +746,10 @@ def create_text_recognition_detector( # noqa: PLR0913 # pylint: disable=too-man | |
| :param pipeline_config: Advanced usage only. Configuration string needed to instantiate a specific | ||
| prediction pipeline for this detector. | ||
| :param metadata: A dictionary or JSON string containing custom key/value pairs to associate with | ||
| the detector (limited to 1KB). This metadata can be used to store additional | ||
| information like location, purpose, or related system IDs. You can retrieve this | ||
| metadata later by calling `get_detector()`. | ||
| :param priming_group_id: Optional ID of an existing PrimingGroup to associate with this detector. | ||
|
|
||
| :return: The created Detector object | ||
| """ | ||
|
|
@@ -754,6 +762,7 @@ def create_text_recognition_detector( # noqa: PLR0913 # pylint: disable=too-man | |
| patience_time=patience_time, | ||
| pipeline_config=pipeline_config, | ||
| metadata=metadata, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
| detector_creation_input.mode = ModeEnum.TEXT | ||
| mode_config = TextModeConfiguration() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -937,3 +937,24 @@ def test_delete_detector(gl: Groundlight): | |
| fake_detector_id = "det_fake123456789" | ||
| with pytest.raises(NotFoundError): | ||
| gl.delete_detector(fake_detector_id) # type: ignore | ||
|
|
||
|
|
||
| def test_create_detector_with_invalid_priming_group_id(gl: Groundlight): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no happy path test is strange. |
||
| """ | ||
| Test that creating a detector with a non-existent priming_group_id returns an appropriate error. | ||
| """ | ||
| name = f"Test invalid priming {datetime.utcnow()}" | ||
| query = "Is there a dog?" | ||
| pipeline_config = "never-review" | ||
| priming_group_id = "prgrp_nonexistent12345678901234567890" | ||
|
|
||
| with pytest.raises(NotFoundException) as exc_info: | ||
| gl.create_detector( | ||
| name=name, | ||
| query=query, | ||
| pipeline_config=pipeline_config, | ||
| priming_group_id=priming_group_id, | ||
| ) | ||
|
|
||
| # Verify the error message mentions PrimingGroup | ||
| assert "PrimingGroup" in str(exc_info.value) | ||
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's been a little while since we ran make generate, slight changes to the npm metadata file