|
49 | 49 | logger.setLevel(logging.INFO) |
50 | 50 |
|
51 | 51 |
|
| 52 | +def _CancelQueryJobAgentEngineConfig_to_vertex( |
| 53 | + from_object: Union[dict[str, Any], object], |
| 54 | + parent_object: Optional[dict[str, Any]] = None, |
| 55 | +) -> dict[str, Any]: |
| 56 | + to_object: dict[str, Any] = {} |
| 57 | + |
| 58 | + if getv(from_object, ["operation_name"]) is not None: |
| 59 | + setv(parent_object, ["operationName"], getv(from_object, ["operation_name"])) |
| 60 | + |
| 61 | + return to_object |
| 62 | + |
| 63 | + |
| 64 | +def _CancelQueryJobAgentEngineRequestParameters_to_vertex( |
| 65 | + from_object: Union[dict[str, Any], object], |
| 66 | + parent_object: Optional[dict[str, Any]] = None, |
| 67 | +) -> dict[str, Any]: |
| 68 | + to_object: dict[str, Any] = {} |
| 69 | + if getv(from_object, ["name"]) is not None: |
| 70 | + setv(to_object, ["_url", "name"], getv(from_object, ["name"])) |
| 71 | + |
| 72 | + if getv(from_object, ["config"]) is not None: |
| 73 | + setv( |
| 74 | + to_object, |
| 75 | + ["config"], |
| 76 | + _CancelQueryJobAgentEngineConfig_to_vertex( |
| 77 | + getv(from_object, ["config"]), to_object |
| 78 | + ), |
| 79 | + ) |
| 80 | + |
| 81 | + return to_object |
| 82 | + |
| 83 | + |
52 | 84 | def _CheckQueryJobAgentEngineConfig_to_vertex( |
53 | 85 | from_object: Union[dict[str, Any], object], |
54 | 86 | parent_object: Optional[dict[str, Any]] = None, |
@@ -410,6 +442,85 @@ def _UpdateAgentEngineRequestParameters_to_vertex( |
410 | 442 |
|
411 | 443 | class AgentEngines(_api_module.BaseModule): |
412 | 444 |
|
| 445 | + def cancel_query_job( |
| 446 | + self, |
| 447 | + *, |
| 448 | + name: str, |
| 449 | + config: Optional[types.CancelQueryJobAgentEngineConfigOrDict] = None, |
| 450 | + ) -> types.CancelQueryJobResult: |
| 451 | + """ |
| 452 | + Cancels a long-running query job on an Agent Engine. |
| 453 | +
|
| 454 | + Args: |
| 455 | + name (str): |
| 456 | + Required. The reasoning engine resource name. |
| 457 | + config (CancelQueryJobAgentEngineConfigOrDict): |
| 458 | + Optional. The configuration for the cancel_query_job. |
| 459 | +
|
| 460 | + """ |
| 461 | + |
| 462 | + parameter_model = types._CancelQueryJobAgentEngineRequestParameters( |
| 463 | + name=name, |
| 464 | + config=config, |
| 465 | + ) |
| 466 | + |
| 467 | + request_url_dict: Optional[dict[str, str]] |
| 468 | + if not self._api_client.vertexai: |
| 469 | + raise ValueError("This method is only supported in the Vertex AI client.") |
| 470 | + else: |
| 471 | + request_dict = _CancelQueryJobAgentEngineRequestParameters_to_vertex( |
| 472 | + parameter_model |
| 473 | + ) |
| 474 | + request_url_dict = request_dict.get("_url") |
| 475 | + if request_url_dict: |
| 476 | + path = "{name}:cancelAsyncQuery".format_map(request_url_dict) |
| 477 | + else: |
| 478 | + path = "{name}:cancelAsyncQuery" |
| 479 | + |
| 480 | + query_params = request_dict.get("_query") |
| 481 | + if query_params: |
| 482 | + path = f"{path}?{urlencode(query_params)}" |
| 483 | + # TODO: remove the hack that pops config. |
| 484 | + request_dict.pop("config", None) |
| 485 | + |
| 486 | + http_options: Optional[types.HttpOptions] = None |
| 487 | + if ( |
| 488 | + parameter_model.config is not None |
| 489 | + and parameter_model.config.http_options is not None |
| 490 | + ): |
| 491 | + http_options = parameter_model.config.http_options |
| 492 | + |
| 493 | + request_dict = _common.convert_to_dict(request_dict) |
| 494 | + request_dict = _common.encode_unserializable_types(request_dict) |
| 495 | + |
| 496 | + response = self._api_client.request("post", path, request_dict, http_options) |
| 497 | + |
| 498 | + response_dict = {} if not response.body else json.loads(response.body) |
| 499 | + |
| 500 | + return_value = types.CancelQueryJobResult._from_response( |
| 501 | + response=response_dict, |
| 502 | + kwargs=( |
| 503 | + { |
| 504 | + "config": { |
| 505 | + "response_schema": getattr( |
| 506 | + parameter_model.config, "response_schema", None |
| 507 | + ), |
| 508 | + "response_json_schema": getattr( |
| 509 | + parameter_model.config, "response_json_schema", None |
| 510 | + ), |
| 511 | + "include_all_fields": getattr( |
| 512 | + parameter_model.config, "include_all_fields", None |
| 513 | + ), |
| 514 | + } |
| 515 | + } |
| 516 | + if getattr(parameter_model, "config", None) |
| 517 | + else {} |
| 518 | + ), |
| 519 | + ) |
| 520 | + |
| 521 | + self._api_client._verify_response(return_value) |
| 522 | + return return_value |
| 523 | + |
413 | 524 | def _check_query_job( |
414 | 525 | self, |
415 | 526 | *, |
@@ -2643,6 +2754,87 @@ def list_session_events( |
2643 | 2754 |
|
2644 | 2755 | class AsyncAgentEngines(_api_module.BaseModule): |
2645 | 2756 |
|
| 2757 | + async def cancel_query_job( |
| 2758 | + self, |
| 2759 | + *, |
| 2760 | + name: str, |
| 2761 | + config: Optional[types.CancelQueryJobAgentEngineConfigOrDict] = None, |
| 2762 | + ) -> types.CancelQueryJobResult: |
| 2763 | + """ |
| 2764 | + Cancels a long-running query job on an Agent Engine. |
| 2765 | +
|
| 2766 | + Args: |
| 2767 | + name (str): |
| 2768 | + Required. The reasoning engine resource name. |
| 2769 | + config (CancelQueryJobAgentEngineConfigOrDict): |
| 2770 | + Optional. The configuration for the cancel_query_job. |
| 2771 | +
|
| 2772 | + """ |
| 2773 | + |
| 2774 | + parameter_model = types._CancelQueryJobAgentEngineRequestParameters( |
| 2775 | + name=name, |
| 2776 | + config=config, |
| 2777 | + ) |
| 2778 | + |
| 2779 | + request_url_dict: Optional[dict[str, str]] |
| 2780 | + if not self._api_client.vertexai: |
| 2781 | + raise ValueError("This method is only supported in the Vertex AI client.") |
| 2782 | + else: |
| 2783 | + request_dict = _CancelQueryJobAgentEngineRequestParameters_to_vertex( |
| 2784 | + parameter_model |
| 2785 | + ) |
| 2786 | + request_url_dict = request_dict.get("_url") |
| 2787 | + if request_url_dict: |
| 2788 | + path = "{name}:cancelAsyncQuery".format_map(request_url_dict) |
| 2789 | + else: |
| 2790 | + path = "{name}:cancelAsyncQuery" |
| 2791 | + |
| 2792 | + query_params = request_dict.get("_query") |
| 2793 | + if query_params: |
| 2794 | + path = f"{path}?{urlencode(query_params)}" |
| 2795 | + # TODO: remove the hack that pops config. |
| 2796 | + request_dict.pop("config", None) |
| 2797 | + |
| 2798 | + http_options: Optional[types.HttpOptions] = None |
| 2799 | + if ( |
| 2800 | + parameter_model.config is not None |
| 2801 | + and parameter_model.config.http_options is not None |
| 2802 | + ): |
| 2803 | + http_options = parameter_model.config.http_options |
| 2804 | + |
| 2805 | + request_dict = _common.convert_to_dict(request_dict) |
| 2806 | + request_dict = _common.encode_unserializable_types(request_dict) |
| 2807 | + |
| 2808 | + response = await self._api_client.async_request( |
| 2809 | + "post", path, request_dict, http_options |
| 2810 | + ) |
| 2811 | + |
| 2812 | + response_dict = {} if not response.body else json.loads(response.body) |
| 2813 | + |
| 2814 | + return_value = types.CancelQueryJobResult._from_response( |
| 2815 | + response=response_dict, |
| 2816 | + kwargs=( |
| 2817 | + { |
| 2818 | + "config": { |
| 2819 | + "response_schema": getattr( |
| 2820 | + parameter_model.config, "response_schema", None |
| 2821 | + ), |
| 2822 | + "response_json_schema": getattr( |
| 2823 | + parameter_model.config, "response_json_schema", None |
| 2824 | + ), |
| 2825 | + "include_all_fields": getattr( |
| 2826 | + parameter_model.config, "include_all_fields", None |
| 2827 | + ), |
| 2828 | + } |
| 2829 | + } |
| 2830 | + if getattr(parameter_model, "config", None) |
| 2831 | + else {} |
| 2832 | + ), |
| 2833 | + ) |
| 2834 | + |
| 2835 | + self._api_client._verify_response(return_value) |
| 2836 | + return return_value |
| 2837 | + |
2646 | 2838 | async def _check_query_job( |
2647 | 2839 | self, |
2648 | 2840 | *, |
|
0 commit comments