Skip to content

temporary fix for how iqs can be returned #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 or 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 or 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
20 changes: 19 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,21 @@ 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:
return ImageQuery(
metadata=None,
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,
)
9 changes: 7 additions & 2 deletions test/unit/test_internalapi.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from groundlight import ExperimentalApi
from groundlight.internalapi import iq_is_answered, iq_is_confident
from model import ImageQuery


def test_iq_is_confident(gl_experimental: ExperimentalApi):
def test_iq_is_confident(gl_experimental: ExperimentalApi, initial_iq: ImageQuery):
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: ImageQuery):
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)
Loading