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

feat: adding possibility to enforce JSON format in VertexAiModel #5290

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/backend/base/langflow/components/models/vertexai.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class ChatVertexAIComponent(LCModelComponent):
file_types=["json"],
),
MessageTextInput(name="model_name", display_name="Model Name", value="gemini-1.5-pro"),
BoolInput(
name="json_mode",
display_name="JSON Mode",
info="If True, enforces JSON output format",
advanced=True,
value=False,
),
StrInput(name="project", display_name="Project", info="The project ID.", advanced=True),
StrInput(name="location", display_name="Location", value="us-central1", advanced=True),
IntInput(name="max_output_tokens", display_name="Max Output Tokens", advanced=True),
Expand Down Expand Up @@ -54,6 +61,8 @@ def build_model(self) -> LanguageModel:
project = self.project or None
credentials = None

generation_config = {"response_mime_type": "application/json"} if self.json_mode else {}

return cast(
"LanguageModel",
ChatVertexAI(
Expand All @@ -67,5 +76,6 @@ def build_model(self) -> LanguageModel:
top_k=self.top_k or None,
top_p=self.top_p,
verbose=self.verbose,
generation_config=generation_config,
),
)
Loading