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: improve reliability for vertex models by setting ANY mode #2437

Merged
merged 4 commits into from
Feb 15, 2025
Merged
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
16 changes: 14 additions & 2 deletions letta/llm_api/google_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,27 @@ def google_vertex_chat_completions_request(
"""

from google import genai
from google.genai.types import FunctionCallingConfig, FunctionCallingConfigMode, ToolConfig

client = genai.Client(vertexai=True, project=project_id, location=region, http_options={"api_version": "v1"})
# add dummy model messages to the end of the input
if add_postfunc_model_messages:
contents = add_dummy_model_messages(contents)

tool_config = ToolConfig(
function_calling_config=FunctionCallingConfig(
# ANY mode forces the model to predict only function calls
mode=FunctionCallingConfigMode.ANY,
)
)
config["tool_config"] = tool_config.model_dump()

# make request to client
response = client.models.generate_content(model=model, contents=contents, config=config)
print(response)
response = client.models.generate_content(
model=model,
contents=contents,
config=config,
)

# convert back response
try:
Expand Down
Loading