Skip to content

Commit 545f6fa

Browse files
brandon-wadaAuto-format Bot
andauthored
temporary fix for how iqs can be returned (#298)
Co-authored-by: Auto-format Bot <[email protected]>
1 parent d9b8297 commit 545f6fa

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/groundlight/internalapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ 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:
68+
if not iq.result or not iq.result.confidence:
6969
return False
7070
return iq.result.confidence >= confidence_threshold # type: ignore
7171

@@ -74,7 +74,7 @@ def iq_is_answered(iq: ImageQuery) -> bool:
7474
"""Returns True if the image query has a ML or human label.
7575
Placeholder and special labels (out of domain) have confidences exactly 0.5
7676
"""
77-
if not iq.result:
77+
if not iq.result or not iq.result.source:
7878
return False
7979
if (iq.result.source == Source.STILL_PROCESSING) or (iq.result.source is None): # Should never be None
8080
return False

test/unit/conftest.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from groundlight import ExperimentalApi, Groundlight
5-
from model import Detector, ImageQuery
5+
from model import Detector, ImageQuery, ImageQueryTypeEnum, ResultTypeEnum
66

77

88
def pytest_configure(config):
@@ -46,3 +46,21 @@ def fixture_image_query_no(gl: Groundlight, detector: Detector) -> ImageQuery:
4646
@pytest.fixture(name="gl_experimental")
4747
def _gl() -> ExperimentalApi:
4848
return ExperimentalApi()
49+
50+
51+
@pytest.fixture(name="initial_iq")
52+
def fixture_initial_iq() -> ImageQuery:
53+
return ImageQuery(
54+
metadata=None,
55+
id="iq_fakeidhere",
56+
type=ImageQueryTypeEnum.image_query,
57+
created_at=datetime.utcnow(),
58+
query="Is there a dog?",
59+
detector_id="det_fakeidhere",
60+
result_type=ResultTypeEnum.binary_classification,
61+
result=None,
62+
patience_time=30,
63+
confidence_threshold=0.9,
64+
rois=None,
65+
text=None,
66+
)

test/unit/test_internalapi.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
from groundlight import ExperimentalApi
22
from groundlight.internalapi import iq_is_answered, iq_is_confident
3+
from model import ImageQuery
34

45

5-
def test_iq_is_confident(gl_experimental: ExperimentalApi):
6+
def test_iq_is_confident(gl_experimental: ExperimentalApi, initial_iq: ImageQuery):
67
det = gl_experimental.get_or_create_detector("Test", "test_query")
78
iq = gl_experimental.ask_async(det, image="test/assets/dog.jpeg")
89
assert not iq_is_confident(iq, 0.9)
910

11+
assert not iq_is_confident(initial_iq, 0.9)
1012

11-
def test_iq_is_answered(gl_experimental: ExperimentalApi):
13+
14+
def test_iq_is_answered(gl_experimental: ExperimentalApi, initial_iq: ImageQuery):
1215
det = gl_experimental.get_or_create_detector("Test", "test_query")
1316
iq = gl_experimental.ask_async(det, image="test/assets/dog.jpeg")
1417
assert not iq_is_answered(iq)
18+
19+
assert not iq_is_answered(initial_iq)

0 commit comments

Comments
 (0)