Skip to content

Commit

Permalink
feat: improve reliability for vertex models by setting ANY mode (#2437
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sarahwooders authored Feb 15, 2025
2 parents 441fa70 + ca245ea commit bf4ac12
Showing 1 changed file with 14 additions and 2 deletions.
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

0 comments on commit bf4ac12

Please sign in to comment.