Skip to content

Commit

Permalink
feat: LLM - Exposed the TextGenerationResponse.raw_prediction_response
Browse files Browse the repository at this point in the history
When a model returns some extra attributes that are not explicitly exposed by the SDK, these attributes will now be accessible via the `repsonse.raw_prediction_response` attribute.

PiperOrigin-RevId: 557276971
  • Loading branch information
Ark-kun authored and Copybara-Service committed Aug 15, 2023
1 parent e99f366 commit f8f2b9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/unit/aiplatform/test_language_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ def test_text_generation(self):
)

assert response.text == _TEST_TEXT_GENERATION_PREDICTION["content"]
assert (
response.raw_prediction_response.predictions[0]
== _TEST_TEXT_GENERATION_PREDICTION
)
assert (
response.safety_attributes["Violent"]
== _TEST_TEXT_GENERATION_PREDICTION["safetyAttributes"]["scores"][0]
Expand Down
5 changes: 5 additions & 0 deletions vertexai/language_models/_language_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ class TextGenerationResponse:
def __repr__(self):
return self.text

@property
def raw_prediction_response(self) -> aiplatform.models.Prediction:
"""Raw prediction response."""
return self._prediction_response


class _TextGenerationModel(_LanguageModel):
"""TextGenerationModel represents a general language model.
Expand Down

0 comments on commit f8f2b9c

Please sign in to comment.