Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanmai committed May 3, 2024
1 parent fe3dbec commit bfbc2b0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/helm/clients/vertexai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ def do_it() -> Dict[str, Any]:
len(response.candidates) == 1
), f"Expected 1 candidate since candidate_count is 1, got {len(response.candidates)}."
candidate = response.candidates[0]
# Depending on the version of the Vertex AI library and the type of prompt blocking,
# content blocking can show up in many ways, so this defensively handles most of these ways
if candidate.finish_reason in VertexAIChatClient.CONTENT_BLOCKED_FINISH_REASONS:
raise VertexAIContentBlockedError(f"Content blocked with reason: {candidate.finish_reason}")
if not candidate.content.parts:
Expand All @@ -353,7 +355,9 @@ def do_it() -> Dict[str, Any]:

cache_key = CachingClient.make_cache_key(raw_cache_key, request)
response, cached = self.cache.get(cache_key, wrap_request_time(do_it))

except requests.exceptions.RequestException as e:
error: str = f"Gemini Vision error: {e}"
return RequestResult(success=False, cached=False, error=error, completions=[], embedding=[])
except VertexAIContentBlockedError as e:
return RequestResult(
success=False,
Expand All @@ -367,7 +371,7 @@ def do_it() -> Dict[str, Any]:
if "error" in response:
return RequestResult(
success=False,
cached=False,
cached=True,
error=f"Content blocked error in cached response: {str(response)}",
completions=[],
embedding=[],
Expand Down

0 comments on commit bfbc2b0

Please sign in to comment.