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

Fix buggy response handling in vertexai_client #2614

Merged
merged 1 commit into from
May 7, 2024
Merged
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
12 changes: 8 additions & 4 deletions src/helm/clients/vertexai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def do_it() -> Dict[str, Any]:

# Depending on the version of the Vertex AI library and the type of prompt blocking,
# prompt blocking can show up in many ways, so this defensively handles most of these ways
if response.prompt_feedback.block_reason:
if response.prompt_feedback and response.prompt_feedback.block_reason:
raise VertexAIContentBlockedError(
f"Prompt blocked with reason: {response.prompt_feedback.block_reason}"
)
Expand All @@ -209,8 +209,10 @@ def do_it() -> Dict[str, Any]:
# 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:
raise VertexAIContentBlockedError(f"No content in candidate: {candidate}")
if not candidate.content.parts:
raise VertexAIContentBlockedError(f"No parts in candidate: {candidate}")
raise VertexAIContentBlockedError(f"No content parts in candidate: {candidate}")
predictions.append({"text": candidate.content.text})
# TODO: Extract more information from the response
return {"predictions": predictions}
Expand Down Expand Up @@ -330,7 +332,7 @@ def do_it() -> Dict[str, Any]:
)
# Depending on the version of the Vertex AI library and the type of prompt blocking,
# prompt blocking can show up in many ways, so this defensively handles most of these ways
if response.prompt_feedback.block_reason:
if response.prompt_feedback and response.prompt_feedback.block_reason:
raise VertexAIContentBlockedError(
f"Prompt blocked with reason: {response.prompt_feedback.block_reason}"
)
Expand All @@ -345,8 +347,10 @@ def do_it() -> Dict[str, Any]:
# 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:
raise VertexAIContentBlockedError(f"No content in candidate: {candidate}")
if not candidate.content.parts:
raise VertexAIContentBlockedError(f"No parts in candidate: {candidate}")
raise VertexAIContentBlockedError(f"No content parts in candidate: {candidate}")
return {"predictions": [{"text": candidate.text}]}

raw_cache_key = {"model_name": model_name, "prompt": prompt_key, **parameters}
Expand Down