Skip to content

Commit

Permalink
temporary fix for how iqs can be returned
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-groundlight committed Dec 12, 2024
1 parent c80e000 commit a6e1ee2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/groundlight/internalapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ 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:
if not iq.result and not iq.result.confidence:
return False
return iq.result.confidence >= confidence_threshold # type: ignore

Expand All @@ -74,7 +74,7 @@ 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:
if not iq.result and not iq.result.source:
return False
if (iq.result.source == Source.STILL_PROCESSING) or (iq.result.source is None): # Should never be None
return False
Expand Down
18 changes: 17 additions & 1 deletion test/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from groundlight import ExperimentalApi, Groundlight
from model import Detector, ImageQuery
from model import Detector, ImageQuery, ImageQueryTypeEnum, ResultTypeEnum


def pytest_configure(config):
Expand Down Expand Up @@ -46,3 +46,19 @@ def fixture_image_query_no(gl: Groundlight, detector: Detector) -> ImageQuery:
@pytest.fixture(name="gl_experimental")
def _gl() -> ExperimentalApi:
return ExperimentalApi()

@pytest.fixture(name="initial_iq")
def fixture_initial_iq() -> ImageQuery:
ImageQuery(
id="iq_fakeidhere",
type=ImageQueryTypeEnum.image_query,
created_at=datetime.utcnow(),
query = "Is there a dog?",
detector_id="det_fakeidhere",
result_type=ResultTypeEnum.binary_classification,
result=None,
patience_time=30,
confidence_threshold=0.9,
rois=None,
text=None,
)
8 changes: 6 additions & 2 deletions test/unit/test_internalapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
from groundlight.internalapi import iq_is_answered, iq_is_confident


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

assert not iq_is_confident(initial_iq, 0.9)

def test_iq_is_answered(gl_experimental: ExperimentalApi):

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

assert not iq_is_answered(initial_iq)

0 comments on commit a6e1ee2

Please sign in to comment.