Skip to content

Commit

Permalink
Allows for filtering iqs by detector_id (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-groundlight authored Dec 13, 2024
1 parent c80e000 commit d9b8297
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
6 changes: 3 additions & 3 deletions generated/docs/ImageQueriesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ with groundlight_openapi_client.ApiClient(configuration) as api_client:
api_instance = image_queries_api.ImageQueriesApi(api_client)
page = 1 # int | A page number within the paginated result set. (optional)
page_size = 1 # int | Number of items to return per page. (optional)
predictor_id = "predictor_id_example" # str | Optionally filter image queries by detector ID. (optional)
detector_id = "detector_id_example" # str | Optionally filter image queries by detector ID. (optional)

# example passing only required values which don't have defaults set
# and optional values
try:
api_response = api_instance.list_image_queries(page=page, page_size=page_size, predictor_id=predictor_id)
api_response = api_instance.list_image_queries(page=page, page_size=page_size, detector_id=detector_id)
pprint(api_response)
except groundlight_openapi_client.ApiException as e:
print("Exception when calling ImageQueriesApi->list_image_queries: %s\n" % e)
Expand All @@ -221,7 +221,7 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**page** | **int**| A page number within the paginated result set. | [optional]
**page_size** | **int**| Number of items to return per page. | [optional]
**predictor_id** | **str**| Optionally filter image queries by detector ID. | [optional]
**detector_id** | **str**| Optionally filter image queries by detector ID. | [optional]

### Return type

Expand Down
10 changes: 5 additions & 5 deletions generated/groundlight_openapi_client/api/image_queries_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(self, api_client=None):
"all": [
"page",
"page_size",
"predictor_id",
"detector_id",
],
"required": [],
"nullable": [],
Expand All @@ -142,17 +142,17 @@ def __init__(self, api_client=None):
"openapi_types": {
"page": (int,),
"page_size": (int,),
"predictor_id": (str,),
"detector_id": (str,),
},
"attribute_map": {
"page": "page",
"page_size": "page_size",
"predictor_id": "predictor_id",
"detector_id": "detector_id",
},
"location_map": {
"page": "query",
"page_size": "query",
"predictor_id": "query",
"detector_id": "query",
},
"collection_format_map": {},
},
Expand Down Expand Up @@ -379,7 +379,7 @@ def list_image_queries(self, **kwargs):
Keyword Args:
page (int): A page number within the paginated result set.. [optional]
page_size (int): Number of items to return per page.. [optional]
predictor_id (str): Optionally filter image queries by detector ID.. [optional]
detector_id (str): Optionally filter image queries by detector ID.. [optional]
_return_http_data_only (bool): response data without head status
code and headers. Default is True.
_preload_content (bool): if False, the urllib3.HTTPResponse object
Expand Down
2 changes: 1 addition & 1 deletion 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-10T01:13:13+00:00
# timestamp: 2024-12-13T20:10:31+00:00

from __future__ import annotations

Expand Down
7 changes: 6 additions & 1 deletion spec/public-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ paths:
schema:
type: integer
description: Number of items to return per page.
- in: query
name: detector_id
schema:
type: string
description: Optionally filter image queries by detector ID.
tags:
- image-queries
security:
Expand Down Expand Up @@ -1457,4 +1462,4 @@ servers:
- url: https://device.positronix.ai/device-api
description: Device Prod
- url: https://device.integ.positronix.ai/device-api
description: Device Integ
description: Device Integ
13 changes: 8 additions & 5 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings
from functools import partial
from io import BufferedReader, BytesIO
from typing import Callable, List, Optional, Union
from typing import Any, Callable, List, Optional, Union

from groundlight_openapi_client import Configuration
from groundlight_openapi_client.api.detectors_api import DetectorsApi
Expand Down Expand Up @@ -530,7 +530,9 @@ def get_image_query(self, id: str) -> ImageQuery: # pylint: disable=redefined-b
iq = ImageQuery.parse_obj(obj.to_dict())
return self._fixup_image_query(iq)

def list_image_queries(self, page: int = 1, page_size: int = 10) -> PaginatedImageQueryList:
def list_image_queries(
self, page: int = 1, page_size: int = 10, detector_id: Union[str, None] = None
) -> PaginatedImageQueryList:
"""
List all image queries associated with your account, with pagination support.
Expand All @@ -552,9 +554,10 @@ def list_image_queries(self, page: int = 1, page_size: int = 10) -> PaginatedIma
:return: PaginatedImageQueryList containing the requested page of image queries and pagination metadata
like total count and links to next/previous pages.
"""
obj = self.image_queries_api.list_image_queries(
page=page, page_size=page_size, _request_timeout=DEFAULT_REQUEST_TIMEOUT
)
params: dict[str, Any] = {"page": page, "page_size": page_size, "_request_timeout": DEFAULT_REQUEST_TIMEOUT}
if detector_id:
params["detector_id"] = detector_id
obj = self.image_queries_api.list_image_queries(**params)
image_queries = PaginatedImageQueryList.parse_obj(obj.to_dict())
if image_queries.results is not None:
image_queries.results = [self._fixup_image_query(iq) for iq in image_queries.results]
Expand Down
14 changes: 14 additions & 0 deletions test/integration/test_groundlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,20 @@ def test_list_image_queries(gl: Groundlight):
assert is_valid_display_result(image_query.result)


def test_list_image_queries_with_filter(gl: Groundlight):
# We want a fresh detector so we know exactly what image queries are associated with it
detector = gl.create_detector(name=f"Test {datetime.utcnow()}", query="Is there a dog?")
image_query_yes = gl.ask_async(detector=detector.id, image="test/assets/dog.jpeg", human_review="NEVER")
image_query_no = gl.ask_async(detector=detector.id, image="test/assets/cat.jpeg", human_review="NEVER")
iq_ids = [image_query_yes.id, image_query_no.id]

image_queries = gl.list_image_queries(detector_id=detector.id)
num_image_queries = 2
assert len(image_queries.results) == num_image_queries
for image_query in image_queries.results:
assert image_query.id in iq_ids


def test_get_image_query(gl: Groundlight, image_query_yes: ImageQuery):
_image_query = gl.get_image_query(id=image_query_yes.id)
assert str(_image_query)
Expand Down

0 comments on commit d9b8297

Please sign in to comment.