Skip to content

Commit

Permalink
Internal function bugfix (#296)
Browse files Browse the repository at this point in the history
Considering a case where ask_async returned image queries have no result

---------

Co-authored-by: Auto-format Bot <[email protected]>
  • Loading branch information
brandon-groundlight and Auto-format Bot authored Dec 12, 2024
1 parent ee5d7e1 commit 9d153a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packages = [
{include = "**/*.py", from = "src"},
]
readme = "README.md"
version = "0.21.0"
version = "0.21.1"

[tool.poetry.dependencies]
# For certifi, use ">=" instead of "^" since it upgrades its "major version" every year, not really following semver
Expand Down
4 changes: 4 additions & 0 deletions src/groundlight/internalapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ def iq_is_confident(iq: ImageQuery, confidence_threshold: float) -> bool:
The only subtlety here is that currently confidence of None means
human label, which is treated as confident.
"""
if not iq.result:
return False
return iq.result.confidence >= confidence_threshold # type: ignore


def iq_is_answered(iq: ImageQuery) -> bool:
"""Returns True if the image query has a ML or human label.
Placeholder and special labels (out of domain) have confidences exactly 0.5
"""
if not iq.result:
return False
if (iq.result.source == Source.STILL_PROCESSING) or (iq.result.source is None): # Should never be None
return False
return True
Expand Down
14 changes: 14 additions & 0 deletions test/unit/test_internalapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from groundlight import ExperimentalApi
from groundlight.internalapi import iq_is_answered, iq_is_confident


def test_iq_is_confident(gl_experimental: ExperimentalApi):
det = gl_experimental.get_or_create_detector("Test", "test_query")
iq = gl_experimental.ask_async(det, image="test/assets/dog.jpeg", wait=10)
assert not iq_is_confident(iq, 0.9)


def test_iq_is_answered(gl_experimental: ExperimentalApi):
det = gl_experimental.get_or_create_detector("Test", "test_query")
iq = gl_experimental.ask_async(det, image="test/assets/dog.jpeg", wait=10)
assert not iq_is_answered(iq)

0 comments on commit 9d153a4

Please sign in to comment.