Skip to content

Commit

Permalink
update spec and add image_query_id param
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreyEWood committed Oct 30, 2024
1 parent bb33854 commit cb83e7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
17 changes: 9 additions & 8 deletions spec/public-api.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.3
info:
title: Groundlight API
version: 0.18.1
version: 0.18.2
description: Groundlight makes it simple to understand images. You can easily create
computer vision detectors just by describing what you want to know using natural
language.
Expand Down Expand Up @@ -336,18 +336,16 @@ paths:
description: ''
post:
operationId: Submit image query
description: |2+
description: |2
Submit an image query against a detector.
You must use `"Content-Type: image/jpeg"` for the image data. For example:
You must use `"Content-Type: image/jpeg"` or similar (image/png, image/webp, etc) for the image data. For example:
```Bash
$ curl https://api.groundlight.ai/device-api/v1/image-queries?detector_id=det_abc123 \
--header "Content-Type: image/jpeg" \
--data-binary @path/to/filename.jpeg
```
parameters:
- in: query
name: detector_id
Expand All @@ -363,6 +361,11 @@ paths:
If set to `DEFAULT`, use the regular escalation logic (i.e., send the image query for human review if the ML model is not confident).
If set to `ALWAYS`, always send the image query for human review even if the ML model is confident.
If set to `NEVER`, never send the image query for human review even if the ML model is not confident.
- in: query
name: image_query_id
schema:
type: string
description: The ID to assign to the created image query.
- in: query
name: inspection_id
schema:
Expand Down Expand Up @@ -995,6 +998,7 @@ components:
- confidence
- created_at
- detector_id
- source
- text
LabelValueRequest:
type: object
Expand Down Expand Up @@ -1330,7 +1334,6 @@ components:
minimum: 0.0
maximum: 1.0
source:
description: Source is optional to support edge v0.2
type: string
enum:
- STILL_PROCESSING
Expand All @@ -1355,7 +1358,6 @@ components:
minimum: 0.0
maximum: 1.0
source:
description: Source is optional to support edge v0.2
type: string
enum:
- STILL_PROCESSING
Expand All @@ -1380,7 +1382,6 @@ components:
minimum: 0.0
maximum: 1.0
source:
description: Source is optional to support edge v0.2
type: string
enum:
- STILL_PROCESSING
Expand Down
22 changes: 22 additions & 0 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments, t
want_async: bool = False,
inspection_id: Optional[str] = None,
metadata: Union[dict, str, None] = None,
image_query_id: Optional[str] = None,
) -> ImageQuery:
"""
Evaluates an image with Groundlight.
Expand Down Expand Up @@ -482,6 +483,9 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments, t
the image query (limited to 1KB). You can retrieve this metadata later by calling
`get_image_query()`.
:param image_query_id: The ID for the image query. This is to enable specific functionality and is not intended
for general external use. If not set, a random ID will be generated.
:return: ImageQuery
"""
if wait is None:
Expand Down Expand Up @@ -516,6 +520,9 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments, t
# which means we need to put the metadata in the query string. To do that safely, we
# url- and base64-encode the metadata.
params["metadata"] = url_encode_dict(metadata, name="metadata", size_limit_bytes=1024)

if image_query_id is not None:
params["image_query_id"] = image_query_id

raw_image_query = self.image_queries_api.submit_image_query(**params)
image_query = ImageQuery.parse_obj(raw_image_query.to_dict())
Expand All @@ -536,6 +543,7 @@ def ask_confident( # noqa: PLR0913 # pylint: disable=too-many-arguments
confidence_threshold: Optional[float] = None,
wait: Optional[float] = None,
metadata: Union[dict, str, None] = None,
image_query_id: Optional[str] = None,
inspection_id: Optional[str] = None,
) -> ImageQuery:
"""
Expand All @@ -561,6 +569,9 @@ def ask_confident( # noqa: PLR0913 # pylint: disable=too-many-arguments
:param metadata: A dictionary or JSON string of custom key/value metadata to associate with
the image query (limited to 1KB). You can retrieve this metadata later by calling
`get_image_query()`.
:param image_query_id: The ID for the image query. This is to enable specific functionality and is not intended
for general external use. If not set, a random ID will be generated.
:return: ImageQuery
"""
Expand All @@ -572,6 +583,7 @@ def ask_confident( # noqa: PLR0913 # pylint: disable=too-many-arguments
patience_time=wait,
human_review=None,
metadata=metadata,
image_query_id=image_query_id,
inspection_id=inspection_id,
)

Expand All @@ -581,6 +593,7 @@ def ask_ml( # noqa: PLR0913 # pylint: disable=too-many-arguments, too-many-loca
image: Union[str, bytes, Image.Image, BytesIO, BufferedReader, np.ndarray],
wait: Optional[float] = None,
metadata: Union[dict, str, None] = None,
image_query_id: Optional[str] = None,
inspection_id: Optional[str] = None,
) -> ImageQuery:
"""
Expand All @@ -602,6 +615,9 @@ def ask_ml( # noqa: PLR0913 # pylint: disable=too-many-arguments, too-many-loca
:param metadata: A dictionary or JSON string of custom key/value metadata to associate with
the image query (limited to 1KB). You can retrieve this metadata later by calling
`get_image_query()`.
:param image_query_id: The ID for the image query. This is to enable specific functionality and is not intended
for general external use. If not set, a random ID will be generated.
:return: ImageQuery
"""
Expand All @@ -610,6 +626,7 @@ def ask_ml( # noqa: PLR0913 # pylint: disable=too-many-arguments, too-many-loca
image,
wait=0,
metadata=metadata,
image_query_id=image_query_id,
inspection_id=inspection_id,
)
if iq_is_answered(iq):
Expand All @@ -625,6 +642,7 @@ def ask_async( # noqa: PLR0913 # pylint: disable=too-many-arguments
confidence_threshold: Optional[float] = None,
human_review: Optional[str] = None,
metadata: Union[dict, str, None] = None,
image_query_id: Optional[str] = None,
inspection_id: Optional[str] = None,
) -> ImageQuery:
"""
Expand Down Expand Up @@ -664,6 +682,9 @@ def ask_async( # noqa: PLR0913 # pylint: disable=too-many-arguments
:param metadata: A dictionary or JSON string of custom key/value metadata to associate with
the image query (limited to 1KB). You can retrieve this metadata later by calling
`get_image_query()`.
:param image_query_id: The ID for the image query. This is to enable specific functionality and is not intended
for general external use. If not set, a random ID will be generated.
:return: ImageQuery
Expand Down Expand Up @@ -708,6 +729,7 @@ def ask_async( # noqa: PLR0913 # pylint: disable=too-many-arguments
human_review=human_review,
want_async=True,
metadata=metadata,
image_query_id=image_query_id,
inspection_id=inspection_id,
)

Expand Down

0 comments on commit cb83e7b

Please sign in to comment.