Skip to content
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

quick fix to support counting unclear in the SDK #299

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generated/docs/CountingResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**count** | **int** | |
**count** | **int, none_type** | |
**confidence** | **float** | | [optional]
**source** | **str** | | [optional]
**greater_than_max** | **bool** | | [optional]
Expand Down
9 changes: 6 additions & 3 deletions generated/groundlight_openapi_client/model/counting_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ def openapi_types():
and the value is attribute type.
"""
return {
"count": (int,), # noqa: E501
"count": (
int,
none_type,
), # noqa: E501
"confidence": (float,), # noqa: E501
"source": (str,), # noqa: E501
"greater_than_max": (bool,), # noqa: E501
Expand All @@ -131,7 +134,7 @@ def _from_openapi_data(cls, count, *args, **kwargs): # noqa: E501
"""CountingResult - a model defined in OpenAPI

Args:
count (int):
count (int, none_type):

Keyword Args:
_check_type (bool): if True, values for parameters in openapi_types
Expand Down Expand Up @@ -222,7 +225,7 @@ def __init__(self, count, *args, **kwargs): # noqa: E501
"""CountingResult - a model defined in OpenAPI

Args:
count (int):
count (int, none_type):

Keyword Args:
_check_type (bool): if True, values for parameters in openapi_types
Expand Down
4 changes: 2 additions & 2 deletions generated/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: public-api.yaml
# timestamp: 2024-12-13T20:10:31+00:00
# timestamp: 2024-12-19T17:53:53+00:00

from __future__ import annotations

Expand Down Expand Up @@ -200,7 +200,7 @@ class BinaryClassificationResult(BaseModel):
class CountingResult(BaseModel):
confidence: Optional[confloat(ge=0.0, le=1.0)] = None
source: Optional[Source] = None
count: conint(ge=0)
count: Optional[conint(ge=0)] = Field(...)
greater_than_max: Optional[bool] = None


Expand Down
1 change: 1 addition & 0 deletions spec/public-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ components:
count:
type: integer
minimum: 0
nullable: true
greater_than_max:
type: boolean
required:
Expand Down
3 changes: 3 additions & 0 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ def get_image_query(self, id: str) -> ImageQuery: # pylint: disable=redefined-b
:return: ImageQuery object containing the query details and results
"""
obj = self.image_queries_api.get_image_query(id=id, _request_timeout=DEFAULT_REQUEST_TIMEOUT)
if obj.result_type == "counting" and getattr(obj.result, "label", None):
obj.result.pop("label")
obj.result["count"] = None
iq = ImageQuery.parse_obj(obj.to_dict())
return self._fixup_image_query(iq)

Expand Down
7 changes: 7 additions & 0 deletions test/unit/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ def test_counting_labels(gl_experimental: ExperimentalApi):
name = f"Test binary labels{datetime.utcnow()}"
det = gl_experimental.create_counting_detector(name, "test_query", "test_object_class")
iq1 = gl_experimental.submit_image_query(det, "test/assets/cat.jpeg")

gl_experimental.add_label(iq1, 0)
iq1 = gl_experimental.get_image_query(iq1.id)
assert iq1.result.count == 0

good_label = 5
gl_experimental.add_label(iq1, good_label)
iq1 = gl_experimental.get_image_query(iq1.id)
assert iq1.result.count == good_label

gl_experimental.add_label(iq1, "UNCLEAR")
iq1 = gl_experimental.get_image_query(iq1.id)
assert iq1.result.count is None

with pytest.raises(ApiException) as _:
gl_experimental.add_label(iq1, "MAYBE")
with pytest.raises(ApiException) as _:
Expand Down