Skip to content

Commit

Permalink
added ask async method
Browse files Browse the repository at this point in the history
  • Loading branch information
sunildkumar committed Oct 9, 2023
1 parent 2b3d07e commit b174917
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.rulers": [
100,
120
],
"python.analysis.extraPaths": [
"./generated"
],
Expand Down
20 changes: 18 additions & 2 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments
params["human_review"] = human_review

if want_async is True:
# If want_async is True, we don't want to wait for a result. As a result using both wait and want_async makes
# no sense.
# If want_async is True, we don't want to wait for a result. As a result using both wait and want_async
# makes no sense.
if wait is not None:
raise ValueError(
"wait must be None if want_async is True as the two are incompatible. Please set wait"
Expand All @@ -247,6 +247,22 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments
image_query = self.wait_for_confident_result(image_query, confidence_threshold=threshold, timeout_sec=wait)

return self._fixup_image_query(image_query, want_async=want_async)

def ask_async(self,
detector: Union[Detector, str],
image: Union[str, bytes, Image.Image, BytesIO, BufferedReader, np.ndarray],
human_review: Optional[str] = None,
inspection_id: Optional[str] = None) -> ImageQuery:
"""
Convenience method for submitting an image query asynchronously. This is equivalent to calling
submit_image_query with want_async=True. Use get_image_query to retrieve the result of the image query.
"""
return self.submit_image_query(detector,
image,
human_review=human_review,
want_async=True,
inspection_id=inspection_id)


def wait_for_confident_result(
self,
Expand Down

0 comments on commit b174917

Please sign in to comment.