Skip to content

Commit f8f2b9c

Browse files
Ark-kuncopybara-github
authored andcommitted
feat: LLM - Exposed the TextGenerationResponse.raw_prediction_response
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
1 parent e99f366 commit f8f2b9c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

tests/unit/aiplatform/test_language_models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ def test_text_generation(self):
577577
)
578578

579579
assert response.text == _TEST_TEXT_GENERATION_PREDICTION["content"]
580+
assert (
581+
response.raw_prediction_response.predictions[0]
582+
== _TEST_TEXT_GENERATION_PREDICTION
583+
)
580584
assert (
581585
response.safety_attributes["Violent"]
582586
== _TEST_TEXT_GENERATION_PREDICTION["safetyAttributes"]["scores"][0]

vertexai/language_models/_language_models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ class TextGenerationResponse:
222222
def __repr__(self):
223223
return self.text
224224

225+
@property
226+
def raw_prediction_response(self) -> aiplatform.models.Prediction:
227+
"""Raw prediction response."""
228+
return self._prediction_response
229+
225230

226231
class _TextGenerationModel(_LanguageModel):
227232
"""TextGenerationModel represents a general language model.

0 commit comments

Comments
 (0)