Skip to content
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

Don't poll the cloud for a confident answer if the client wants only edge answers #307

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
17 changes: 15 additions & 2 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,21 @@ def _wait_for_result(
logger.debug(f"Polling ({target_delay:.1f}/{timeout_sec:.0f}s) {image_query} until result is available")
time.sleep(sleep_time)
next_delay *= self.POLLING_EXPONENTIAL_BACKOFF
image_query = self.get_image_query(image_query.id)
image_query = self._fixup_image_query(image_query)

def is_from_edge(iq: ImageQuery) -> bool:
return iq.metadata and iq.metadata.get("is_from_edge", False)

if is_from_edge(image_query) and not condition(image_query):
# If the query is from the edge and the condition is not met, it means the client wanted only edge
# answers, so we don't want to poll the cloud and we should eventually return whatever the edge response
# was. We'll wait the remaining time to stay consistent with the behavior of the wait parameter.
logger.debug(
"The image query is from the edge and the client wanted only edge answers, so we are not"
" attempting to get a result from the cloud."
)
else:
image_query = self.get_image_query(image_query.id)
image_query = self._fixup_image_query(image_query)
return image_query

def add_label(
Expand Down
Loading