@@ -61,9 +61,9 @@ def _gemini_vertex_url(model: str) -> str:
6161 return f"https://{ host } /v1/projects/{ project } /locations/{ location } /publishers/google/models/{ model } :generateContent"
6262
6363
64- def _complete_anthropic_on_vertex (prompt : str , * , timeout : int ) -> GatekeeperCompletion :
64+ def _complete_anthropic_on_vertex (prompt : str , * , max_tokens : int , timeout : int ) -> GatekeeperCompletion :
6565 model = normalize_model_id (CONFIG .gatekeeper .model or "" )
66- body = build_messages_body (prompt , include_model = False )
66+ body = build_messages_body (prompt , include_model = False , max_tokens = max_tokens )
6767 body ["anthropic_version" ] = ANTHROPIC_VERTEX_VERSION
6868 response = post_json (
6969 provider = "anthropic" ,
@@ -75,36 +75,36 @@ def _complete_anthropic_on_vertex(prompt: str, *, timeout: int) -> GatekeeperCom
7575 return GatekeeperCompletion (text = extract_messages_text (response ))
7676
7777
78- def _complete_gemini_on_vertex (prompt : str , * , timeout : int ) -> GatekeeperCompletion :
78+ def _complete_gemini_on_vertex (prompt : str , * , max_tokens : int , timeout : int ) -> GatekeeperCompletion :
7979 model = normalize_model_id (CONFIG .gatekeeper .model or "" )
8080 response = post_json (
8181 provider = "gemini" ,
8282 url = _gemini_vertex_url (model ),
8383 headers = {** _vertex_auth_headers (), "Content-Type" : "application/json" },
84- body = build_gemini_body (prompt ),
84+ body = build_gemini_body (prompt , max_tokens = max_tokens ),
8585 timeout = timeout ,
8686 )
8787 return GatekeeperCompletion (text = extract_gemini_text (response ))
8888
8989
90- def _complete_openai_compatible_on_vertex (prompt : str , * , timeout : int ) -> GatekeeperCompletion :
90+ def _complete_openai_compatible_on_vertex (prompt : str , * , max_tokens : int , timeout : int ) -> GatekeeperCompletion :
9191 base_url = _get_vertex_openapi_base_url ()
9292 response = post_json (
9393 provider = "openai" ,
9494 url = f"{ base_url } /chat/completions" ,
9595 headers = {** _vertex_auth_headers (), "Content-Type" : "application/json" },
96- body = build_chat_completions_body (prompt ),
96+ body = build_chat_completions_body (prompt , max_tokens = max_tokens ),
9797 timeout = timeout ,
9898 )
9999 return GatekeeperCompletion (text = extract_chat_completions_text (response ))
100100
101101
102- def complete_vertex_ai (prompt : str , * , timeout : int = DEFAULT_TIMEOUT_SECONDS ) -> GatekeeperCompletion :
102+ def complete_vertex_ai (prompt : str , * , max_tokens : int , timeout : int = DEFAULT_TIMEOUT_SECONDS ) -> GatekeeperCompletion :
103103 model = CONFIG .gatekeeper .model or ""
104104 match _vertex_api_style (model ):
105105 case "anthropic" :
106- return _complete_anthropic_on_vertex (prompt , timeout = timeout )
106+ return _complete_anthropic_on_vertex (prompt , max_tokens = max_tokens , timeout = timeout )
107107 case "gemini" :
108- return _complete_gemini_on_vertex (prompt , timeout = timeout )
108+ return _complete_gemini_on_vertex (prompt , max_tokens = max_tokens , timeout = timeout )
109109 case "openai_compatible" :
110- return _complete_openai_compatible_on_vertex (prompt , timeout = timeout )
110+ return _complete_openai_compatible_on_vertex (prompt , max_tokens = max_tokens , timeout = timeout )
0 commit comments