| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8b43add commit ad63bfe
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1505,6 +1505,9 @@ def _optimize( | |||
| 1505 | 1505 | self._api_client._verify_response(return_value) | |
| 1506 | 1506 | return return_value | |
| 1507 | 1507 | ||
| 1508 | + _DEFAULT_TIMEOUT = 90 | ||
| 1509 | + _DEFAULT_MAX_WAIT_TIME = 60 | ||
| 1510 | + | ||
| 1508 | 1511 | def create( | |
| 1509 | 1512 | self, | |
| 1510 | 1513 | *, | |
@@ -1564,7 +1567,16 @@ def create( | |||
| 1564 | 1567 | ) | |
| 1565 | 1568 | dataset_resource_name = self._wait_for_operation( | |
| 1566 | 1569 | operation=create_prompt_dataset_operation, | |
| 1567 | - timeout=config.timeout if config else 90, | ||
| 1570 | + timeout=( | ||
| 1571 | + config.timeout | ||
| 1572 | + if config and config.timeout is not None | ||
| 1573 | + else self._DEFAULT_TIMEOUT | ||
| 1574 | + ), | ||
| 1575 | + max_wait_time=( | ||
| 1576 | + config.max_wait_time | ||
| 1577 | + if config and config.max_wait_time is not None | ||
| 1578 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 1579 | + ), | ||
| 1568 | 1580 | ) | |
| 1569 | 1581 | dataset_id = dataset_resource_name.split("/")[-1] | |
| 1570 | 1582 | ||
@@ -1636,7 +1648,16 @@ def create_version( | |||
| 1636 | 1648 | ) | |
| 1637 | 1649 | dataset_resource_name = self._wait_for_operation( | |
| 1638 | 1650 | operation=create_prompt_dataset_operation, | |
| 1639 | - timeout=config.timeout if config else 90, | ||
| 1651 | + timeout=( | ||
| 1652 | + config.timeout | ||
| 1653 | + if config and config.timeout is not None | ||
| 1654 | + else self._DEFAULT_TIMEOUT | ||
| 1655 | + ), | ||
| 1656 | + max_wait_time=( | ||
| 1657 | + config.max_wait_time | ||
| 1658 | + if config and config.max_wait_time is not None | ||
| 1659 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 1660 | + ), | ||
| 1640 | 1661 | ) | |
| 1641 | 1662 | dataset_id = dataset_resource_name.split("/")[-1] | |
| 1642 | 1663 | ||
@@ -1660,7 +1681,16 @@ def create_version( | |||
| 1660 | 1681 | ) | |
| 1661 | 1682 | dataset_version_resource_name = self._wait_for_operation( | |
| 1662 | 1683 | operation=create_dataset_version_operation, | |
| 1663 | - timeout=config.timeout if config else 90, | ||
| 1684 | + timeout=( | ||
| 1685 | + config.timeout | ||
| 1686 | + if config and config.timeout is not None | ||
| 1687 | + else self._DEFAULT_TIMEOUT | ||
| 1688 | + ), | ||
| 1689 | + max_wait_time=( | ||
| 1690 | + config.max_wait_time | ||
| 1691 | + if config and config.max_wait_time is not None | ||
| 1692 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 1693 | + ), | ||
| 1664 | 1694 | ) | |
| 1665 | 1695 | ||
| 1666 | 1696 | # Step 4: Get the dataset version resource and return it with the prompt | |
@@ -1679,12 +1709,14 @@ def _wait_for_operation( | |||
| 1679 | 1709 | self, | |
| 1680 | 1710 | operation: types.DatasetOperation, | |
| 1681 | 1711 | timeout: int, | |
| 1712 | + max_wait_time: int = _DEFAULT_MAX_WAIT_TIME, | ||
| 1682 | 1713 | ) -> str: | |
| 1683 | 1714 | """Waits for a dataset operation to complete. | |
| 1684 | 1715 | ||
| 1685 | 1716 | Args: | |
| 1686 | 1717 | operation: The dataset operation to wait for. | |
| 1687 | 1718 | timeout: The maximum time to wait for the operation to complete. | |
| 1719 | + max_wait_time: The maximum interval between polling requests in seconds. | ||
| 1688 | 1720 | ||
| 1689 | 1721 | Returns: | |
| 1690 | 1722 | The name of the Dataset resource from the operation result. | |
@@ -1706,7 +1738,6 @@ def _wait_for_operation( | |||
| 1706 | 1738 | start_time = time.time() | |
| 1707 | 1739 | sleep_duration = 5 | |
| 1708 | 1740 | wait_multiplier = 2 | |
| 1709 | - max_wait_time = 60 | ||
| 1710 | 1741 | previous_time = time.time() | |
| 1711 | 1742 | ||
| 1712 | 1743 | while not done: | |
@@ -1923,6 +1954,7 @@ def _wait_for_project_operation( | |||
| 1923 | 1954 | self, | |
| 1924 | 1955 | operation: genai_types.ProjectOperation, | |
| 1925 | 1956 | timeout: int, | |
| 1957 | + max_wait_time: int = _DEFAULT_MAX_WAIT_TIME, | ||
| 1926 | 1958 | ) -> None: | |
| 1927 | 1959 | """Waits for a dataset deletion operation to complete. | |
| 1928 | 1960 | ||
@@ -1931,6 +1963,7 @@ def _wait_for_project_operation( | |||
| 1931 | 1963 | Args: | |
| 1932 | 1964 | operation: The project operation to wait for. | |
| 1933 | 1965 | timeout: The maximum time to wait for the operation to complete. | |
| 1966 | + max_wait_time: The maximum interval between polling requests in seconds. | ||
| 1934 | 1967 | Raises: | |
| 1935 | 1968 | TimeoutError: If the operation does not complete within the timeout. | |
| 1936 | 1969 | ValueError: If the operation fails. | |
@@ -1940,7 +1973,6 @@ def _wait_for_project_operation( | |||
| 1940 | 1973 | start_time = time.time() | |
| 1941 | 1974 | sleep_duration = 5 | |
| 1942 | 1975 | wait_multiplier = 2 | |
| 1943 | - max_wait_time = 60 | ||
| 1944 | 1976 | previous_time = time.time() | |
| 1945 | 1977 | while not done: | |
| 1946 | 1978 | if (time.time() - start_time) > timeout: | |
@@ -1985,7 +2017,17 @@ def delete( | |||
| 1985 | 2017 | config=config, | |
| 1986 | 2018 | ) | |
| 1987 | 2019 | self._wait_for_project_operation( | |
| 1988 | - operation=delete_prompt_operation, timeout=config.timeout if config else 90 | ||
| 2020 | + operation=delete_prompt_operation, | ||
| 2021 | + timeout=( | ||
| 2022 | + config.timeout | ||
| 2023 | + if config and config.timeout is not None | ||
| 2024 | + else self._DEFAULT_TIMEOUT | ||
| 2025 | + ), | ||
| 2026 | + max_wait_time=( | ||
| 2027 | + config.max_wait_time | ||
| 2028 | + if config and config.max_wait_time is not None | ||
| 2029 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 2030 | + ), | ||
| 1989 | 2031 | ) | |
| 1990 | 2032 | logger.info(f"Deleted prompt with id: {prompt_id}") | |
| 1991 | 2033 | ||
@@ -2013,7 +2055,17 @@ def delete_version( | |||
| 2013 | 2055 | ) | |
| 2014 | 2056 | ||
| 2015 | 2057 | self._wait_for_project_operation( | |
| 2016 | - operation=delete_version_operation, timeout=config.timeout if config else 90 | ||
| 2058 | + operation=delete_version_operation, | ||
| 2059 | + timeout=( | ||
| 2060 | + config.timeout | ||
| 2061 | + if config and config.timeout is not None | ||
| 2062 | + else self._DEFAULT_TIMEOUT | ||
| 2063 | + ), | ||
| 2064 | + max_wait_time=( | ||
| 2065 | + config.max_wait_time | ||
| 2066 | + if config and config.max_wait_time is not None | ||
| 2067 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 2068 | + ), | ||
| 2017 | 2069 | ) | |
| 2018 | 2070 | logger.info( | |
| 2019 | 2071 | f"Deleted prompt version {version_id} from prompt with id: {prompt_id}" | |
@@ -2040,10 +2092,20 @@ def restore_version( | |||
| 2040 | 2092 | restore_prompt_operation = self._restore_version( | |
| 2041 | 2093 | dataset_id=prompt_id, | |
| 2042 | 2094 | version_id=version_id, | |
| 2095 | + config=config, | ||
| 2043 | 2096 | ) | |
| 2044 | 2097 | self._wait_for_project_operation( | |
| 2045 | 2098 | operation=restore_prompt_operation, | |
| 2046 | - timeout=90, | ||
| 2099 | + timeout=( | ||
| 2100 | + config.timeout | ||
| 2101 | + if config and config.timeout is not None | ||
| 2102 | + else self._DEFAULT_TIMEOUT | ||
| 2103 | + ), | ||
| 2104 | + max_wait_time=( | ||
| 2105 | + config.max_wait_time | ||
| 2106 | + if config and config.max_wait_time is not None | ||
| 2107 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 2108 | + ), | ||
| 2047 | 2109 | ) | |
| 2048 | 2110 | dataset_version_resource = self._get_dataset_version_resource( | |
| 2049 | 2111 | dataset_id=prompt_id, | |
@@ -2070,7 +2132,7 @@ def _wait_for_completion(self, job_name: str) -> types.CustomJob: | |||
| 2070 | 2132 | ||
| 2071 | 2133 | log_wait = 5 | |
| 2072 | 2134 | wait_multiplier = 2 | |
| 2073 | - max_wait_time = 60 | ||
| 2135 | + max_wait_time = self._DEFAULT_MAX_WAIT_TIME | ||
| 2074 | 2136 | previous_time = time.time() | |
| 2075 | 2137 | ||
| 2076 | 2138 | job = self._get_custom_job(name=job_name) | |
@@ -2400,7 +2462,16 @@ def update( | |||
| 2400 | 2462 | ) | |
| 2401 | 2463 | dataset_version_resource_name = self._wait_for_operation( | |
| 2402 | 2464 | operation=create_dataset_version_operation, | |
| 2403 | - timeout=config.timeout if config else 90, | ||
| 2465 | + timeout=( | ||
| 2466 | + config.timeout | ||
| 2467 | + if config and config.timeout is not None | ||
| 2468 | + else self._DEFAULT_TIMEOUT | ||
| 2469 | + ), | ||
| 2470 | + max_wait_time=( | ||
| 2471 | + config.max_wait_time | ||
| 2472 | + if config and config.max_wait_time is not None | ||
| 2473 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 2474 | + ), | ||
| 2404 | 2475 | ) | |
| 2405 | 2476 | dataset_version_id = dataset_version_resource_name.split("/")[-1] | |
| 2406 | 2477 | ||
@@ -3499,6 +3570,9 @@ async def _optimize( | |||
| 3499 | 3570 | self._api_client._verify_response(return_value) | |
| 3500 | 3571 | return return_value | |
| 3501 | 3572 | ||
| 3573 | + _DEFAULT_TIMEOUT = 90 | ||
| 3574 | + _DEFAULT_MAX_WAIT_TIME = 60 | ||
| 3575 | + | ||
| 3502 | 3576 | async def create( | |
| 3503 | 3577 | self, | |
| 3504 | 3578 | *, | |
@@ -3558,7 +3632,16 @@ async def create( | |||
| 3558 | 3632 | ) | |
| 3559 | 3633 | dataset_resource_name = await self._wait_for_operation( | |
| 3560 | 3634 | operation=create_prompt_dataset_operation, | |
| 3561 | - timeout=config.timeout if config else 90, | ||
| 3635 | + timeout=( | ||
| 3636 | + config.timeout | ||
| 3637 | + if config and config.timeout is not None | ||
| 3638 | + else self._DEFAULT_TIMEOUT | ||
| 3639 | + ), | ||
| 3640 | + max_wait_time=( | ||
| 3641 | + config.max_wait_time | ||
| 3642 | + if config and config.max_wait_time is not None | ||
| 3643 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 3644 | + ), | ||
| 3562 | 3645 | ) | |
| 3563 | 3646 | dataset_id = dataset_resource_name.split("/")[-1] | |
| 3564 | 3647 | ||
@@ -3629,7 +3712,16 @@ async def create_version( | |||
| 3629 | 3712 | ) | |
| 3630 | 3713 | dataset_resource_name = await self._wait_for_operation( | |
| 3631 | 3714 | operation=create_prompt_dataset_operation, | |
| 3632 | - timeout=config.timeout if config else 90, | ||
| 3715 | + timeout=( | ||
| 3716 | + config.timeout | ||
| 3717 | + if config and config.timeout is not None | ||
| 3718 | + else self._DEFAULT_TIMEOUT | ||
| 3719 | + ), | ||
| 3720 | + max_wait_time=( | ||
| 3721 | + config.max_wait_time | ||
| 3722 | + if config and config.max_wait_time is not None | ||
| 3723 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 3724 | + ), | ||
| 3633 | 3725 | ) | |
| 3634 | 3726 | dataset_id = dataset_resource_name.split("/")[-1] | |
| 3635 | 3727 | ||
@@ -3653,7 +3745,16 @@ async def create_version( | |||
| 3653 | 3745 | ) | |
| 3654 | 3746 | dataset_version_resource_name = await self._wait_for_operation( | |
| 3655 | 3747 | operation=create_dataset_version_operation, | |
| 3656 | - timeout=config.timeout if config else 90, | ||
| 3748 | + timeout=( | ||
| 3749 | + config.timeout | ||
| 3750 | + if config and config.timeout is not None | ||
| 3751 | + else self._DEFAULT_TIMEOUT | ||
| 3752 | + ), | ||
| 3753 | + max_wait_time=( | ||
| 3754 | + config.max_wait_time | ||
| 3755 | + if config and config.max_wait_time is not None | ||
| 3756 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 3757 | + ), | ||
| 3657 | 3758 | ) | |
| 3658 | 3759 | ||
| 3659 | 3760 | # Step 4: Get the dataset version resource and return it with the prompt | |
@@ -3740,7 +3841,16 @@ async def update( | |||
| 3740 | 3841 | ) | |
| 3741 | 3842 | dataset_version_resource_name = await self._wait_for_operation( | |
| 3742 | 3843 | operation=create_dataset_version_operation, | |
| 3743 | - timeout=config.timeout if config else 90, | ||
| 3844 | + timeout=( | ||
| 3845 | + config.timeout | ||
| 3846 | + if config and config.timeout is not None | ||
| 3847 | + else self._DEFAULT_TIMEOUT | ||
| 3848 | + ), | ||
| 3849 | + max_wait_time=( | ||
| 3850 | + config.max_wait_time | ||
| 3851 | + if config and config.max_wait_time is not None | ||
| 3852 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 3853 | + ), | ||
| 3744 | 3854 | ) | |
| 3745 | 3855 | dataset_version_id = dataset_version_resource_name.split("/")[-1] | |
| 3746 | 3856 | ||
@@ -3760,12 +3870,14 @@ async def _wait_for_operation( | |||
| 3760 | 3870 | self, | |
| 3761 | 3871 | operation: types.DatasetOperation, | |
| 3762 | 3872 | timeout: int, | |
| 3873 | + max_wait_time: int = _DEFAULT_MAX_WAIT_TIME, | ||
| 3763 | 3874 | ) -> str: | |
| 3764 | 3875 | """Waits for a dataset operation to complete. | |
| 3765 | 3876 | ||
| 3766 | 3877 | Args: | |
| 3767 | 3878 | operation: The dataset operation to wait for. | |
| 3768 | 3879 | timeout: The maximum time to wait for the operation to complete. | |
| 3880 | + max_wait_time: The maximum interval between polling requests in seconds. | ||
| 3769 | 3881 | ||
| 3770 | 3882 | Returns: | |
| 3771 | 3883 | The name of the Dataset resource from the operation result. | |
@@ -3787,7 +3899,6 @@ async def _wait_for_operation( | |||
| 3787 | 3899 | start_time = time.time() | |
| 3788 | 3900 | sleep_duration = 5 | |
| 3789 | 3901 | wait_multiplier = 2 | |
| 3790 | - max_wait_time = 60 | ||
| 3791 | 3902 | previous_time = time.time() | |
| 3792 | 3903 | ||
| 3793 | 3904 | while not done: | |
@@ -3885,6 +3996,7 @@ async def _wait_for_project_operation( | |||
| 3885 | 3996 | self, | |
| 3886 | 3997 | operation: genai_types.ProjectOperation, | |
| 3887 | 3998 | timeout: int, | |
| 3999 | + max_wait_time: int = _DEFAULT_MAX_WAIT_TIME, | ||
| 3888 | 4000 | ) -> None: | |
| 3889 | 4001 | """Waits for a dataset deletion operation to complete. | |
| 3890 | 4002 | ||
@@ -3893,6 +4005,7 @@ async def _wait_for_project_operation( | |||
| 3893 | 4005 | Args: | |
| 3894 | 4006 | operation: The project operation to wait for. | |
| 3895 | 4007 | timeout: The maximum time to wait for the operation to complete. | |
| 4008 | + max_wait_time: The maximum interval between polling requests in seconds. | ||
| 3896 | 4009 | Raises: | |
| 3897 | 4010 | TimeoutError: If the operation does not complete within the timeout. | |
| 3898 | 4011 | ValueError: If the operation fails. | |
@@ -3902,7 +4015,6 @@ async def _wait_for_project_operation( | |||
| 3902 | 4015 | start_time = time.time() | |
| 3903 | 4016 | sleep_duration = 5 | |
| 3904 | 4017 | wait_multiplier = 2 | |
| 3905 | - max_wait_time = 60 | ||
| 3906 | 4018 | previous_time = time.time() | |
| 3907 | 4019 | while not done: | |
| 3908 | 4020 | if (time.time() - start_time) > timeout: | |
@@ -3947,7 +4059,17 @@ async def delete( | |||
| 3947 | 4059 | config=config, | |
| 3948 | 4060 | ) | |
| 3949 | 4061 | await self._wait_for_project_operation( | |
| 3950 | - operation=delete_prompt_operation, timeout=config.timeout if config else 90 | ||
| 4062 | + operation=delete_prompt_operation, | ||
| 4063 | + timeout=( | ||
| 4064 | + config.timeout | ||
| 4065 | + if config and config.timeout is not None | ||
| 4066 | + else self._DEFAULT_TIMEOUT | ||
| 4067 | + ), | ||
| 4068 | + max_wait_time=( | ||
| 4069 | + config.max_wait_time | ||
| 4070 | + if config and config.max_wait_time is not None | ||
| 4071 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 4072 | + ), | ||
| 3951 | 4073 | ) | |
| 3952 | 4074 | logger.info(f"Deleted prompt with id: {prompt_id}") | |
| 3953 | 4075 | ||
@@ -3975,7 +4097,17 @@ async def delete_version( | |||
| 3975 | 4097 | ) | |
| 3976 | 4098 | ||
| 3977 | 4099 | await self._wait_for_project_operation( | |
| 3978 | - operation=delete_version_operation, timeout=config.timeout if config else 90 | ||
| 4100 | + operation=delete_version_operation, | ||
| 4101 | + timeout=( | ||
| 4102 | + config.timeout | ||
| 4103 | + if config and config.timeout is not None | ||
| 4104 | + else self._DEFAULT_TIMEOUT | ||
| 4105 | + ), | ||
| 4106 | + max_wait_time=( | ||
| 4107 | + config.max_wait_time | ||
| 4108 | + if config and config.max_wait_time is not None | ||
| 4109 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 4110 | + ), | ||
| 3979 | 4111 | ) | |
| 3980 | 4112 | logger.info( | |
| 3981 | 4113 | f"Deleted prompt version {version_id} from prompt with id: {prompt_id}" | |
@@ -4111,10 +4243,20 @@ async def restore_version( | |||
| 4111 | 4243 | restore_prompt_operation = await self._restore_version( | |
| 4112 | 4244 | dataset_id=prompt_id, | |
| 4113 | 4245 | version_id=version_id, | |
| 4246 | + config=config, | ||
| 4114 | 4247 | ) | |
| 4115 | 4248 | await self._wait_for_project_operation( | |
| 4116 | 4249 | operation=restore_prompt_operation, | |
| 4117 | - timeout=90, | ||
| 4250 | + timeout=( | ||
| 4251 | + config.timeout | ||
| 4252 | + if config and config.timeout is not None | ||
| 4253 | + else self._DEFAULT_TIMEOUT | ||
| 4254 | + ), | ||
| 4255 | + max_wait_time=( | ||
| 4256 | + config.max_wait_time | ||
| 4257 | + if config and config.max_wait_time is not None | ||
| 4258 | + else self._DEFAULT_MAX_WAIT_TIME | ||
| 4259 | + ), | ||
| 4118 | 4260 | ) | |
| 4119 | 4261 | dataset_version_resource = await self._get_dataset_version_resource( | |
| 4120 | 4262 | dataset_id=prompt_id, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments