Skip to content

Commit

Permalink
feat: GenAI - Added the GenerationResponse.prompt_feedback property
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 625506526
  • Loading branch information
Ark-kun authored and Copybara-Service committed Apr 17, 2024
1 parent 423c764 commit efd5a72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/unit/vertexai/test_generative_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ def test_chat_send_message_response_blocked_errors(
chat.send_message("Please block with block_reason=OTHER.")

assert e.match("Blocked for testing")
# Checking that the original response and the block reason are accessible.
assert e.value.responses[0].prompt_feedback.block_reason.name == "OTHER"
# Checking that history did not get updated
assert len(chat.history) == 2

Expand Down
6 changes: 6 additions & 0 deletions vertexai/generative_models/_generative_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,12 @@ def text(self) -> str:
raise ValueError("Response has no candidates (and no text).")
return self.candidates[0].text

@property
def prompt_feedback(
self,
) -> gapic_prediction_service_types.GenerateContentResponse.PromptFeedback:
return self._raw_response.prompt_feedback


class Candidate:
"""A response candidate generated by the model."""
Expand Down

0 comments on commit efd5a72

Please sign in to comment.