From 0dccd83e4d8f5b44a169765f70bc4f96645c0776 Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Wed, 13 Dec 2023 07:16:48 -0800 Subject: [PATCH] chore: GenAI - Validating `history` in the `ChatSession` constructor PiperOrigin-RevId: 590588154 --- vertexai/generative_models/_generative_models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vertexai/generative_models/_generative_models.py b/vertexai/generative_models/_generative_models.py index e5e79ffbcc..52e26a68be 100644 --- a/vertexai/generative_models/_generative_models.py +++ b/vertexai/generative_models/_generative_models.py @@ -655,6 +655,10 @@ def __init__( history: Optional[List["Content"]] = None, raise_on_blocked: bool = True, ): + if history: + if not all(isinstance(item, Content) for item in history): + raise ValueError("history must be a list of Content objects.") + self._model = model self._history = history or [] self._raise_on_blocked = raise_on_blocked