Skip to content

Commit 9d153a4

Browse files
brandon-wadaAuto-format Bot
andauthored
Internal function bugfix (#296)
Considering a case where ask_async returned image queries have no result --------- Co-authored-by: Auto-format Bot <[email protected]>
1 parent ee5d7e1 commit 9d153a4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ packages = [
99
{include = "**/*.py", from = "src"},
1010
]
1111
readme = "README.md"
12-
version = "0.21.0"
12+
version = "0.21.1"
1313

1414
[tool.poetry.dependencies]
1515
# For certifi, use ">=" instead of "^" since it upgrades its "major version" every year, not really following semver

src/groundlight/internalapi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ def iq_is_confident(iq: ImageQuery, confidence_threshold: float) -> bool:
6565
The only subtlety here is that currently confidence of None means
6666
human label, which is treated as confident.
6767
"""
68+
if not iq.result:
69+
return False
6870
return iq.result.confidence >= confidence_threshold # type: ignore
6971

7072

7173
def iq_is_answered(iq: ImageQuery) -> bool:
7274
"""Returns True if the image query has a ML or human label.
7375
Placeholder and special labels (out of domain) have confidences exactly 0.5
7476
"""
77+
if not iq.result:
78+
return False
7579
if (iq.result.source == Source.STILL_PROCESSING) or (iq.result.source is None): # Should never be None
7680
return False
7781
return True

test/unit/test_internalapi.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from groundlight import ExperimentalApi
2+
from groundlight.internalapi import iq_is_answered, iq_is_confident
3+
4+
5+
def test_iq_is_confident(gl_experimental: ExperimentalApi):
6+
det = gl_experimental.get_or_create_detector("Test", "test_query")
7+
iq = gl_experimental.ask_async(det, image="test/assets/dog.jpeg", wait=10)
8+
assert not iq_is_confident(iq, 0.9)
9+
10+
11+
def test_iq_is_answered(gl_experimental: ExperimentalApi):
12+
det = gl_experimental.get_or_create_detector("Test", "test_query")
13+
iq = gl_experimental.ask_async(det, image="test/assets/dog.jpeg", wait=10)
14+
assert not iq_is_answered(iq)

0 commit comments

Comments
 (0)