langfun 0.1.2.dev202503200804__py3-none-any.whl → 0.1.2.dev202503210804__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
langfun/core/llms/rest.py CHANGED
@@ -89,11 +89,21 @@ class REST(lf.LanguageModel):
89
89
  timeout=self.timeout,
90
90
  )
91
91
  )
92
- except (requests.exceptions.ReadTimeout,
93
- requests.exceptions.ConnectTimeout) as e:
92
+ except (
93
+ requests.exceptions.Timeout,
94
+ requests.exceptions.ReadTimeout,
95
+ requests.exceptions.ConnectTimeout,
96
+ TimeoutError,
97
+ ) as e:
94
98
  raise lf.TemporaryLMError(str(e)) from e
95
- except ConnectionError as e:
96
- raise lf.LMError(str(e)) from e
99
+ except (
100
+ requests.exceptions.ConnectionError,
101
+ ConnectionError,
102
+ ) as e:
103
+ error_message = str(e)
104
+ if 'REJECTED_CLIENT_THROTTLED' in error_message:
105
+ raise lf.TemporaryLMError(error_message) from e
106
+ raise lf.LMError(error_message) from e
97
107
 
98
108
  def _error(self, status_code: int, content: str) -> lf.LMError:
99
109
  if status_code == 429:
@@ -38,6 +38,13 @@ def mock_requests_post(url: str, json: dict[str, Any], **kwargs):
38
38
  return response
39
39
 
40
40
 
41
+ def mock_requests_post_exception(error):
42
+ def _mock_requests(url: str, json: dict[str, Any], **kwargs):
43
+ del url, json, kwargs
44
+ raise error
45
+ return _mock_requests
46
+
47
+
41
48
  def mock_requests_post_error(status_code, error_type, error_message):
42
49
  def _mock_requests(url: str, json: dict[str, Any], **kwargs):
43
50
  del url, json, kwargs
@@ -106,6 +113,50 @@ class RestTest(unittest.TestCase):
106
113
  ):
107
114
  self._lm('hello', max_attempts=1)
108
115
 
116
+ for error, expected_lm_error_cls, expected_lm_error_msg in [
117
+ (
118
+ requests.exceptions.Timeout('Timeout.'),
119
+ lf.TemporaryLMError,
120
+ 'Timeout.',
121
+ ),
122
+ (
123
+ requests.exceptions.ReadTimeout('Read timeout.'),
124
+ lf.TemporaryLMError,
125
+ 'Read timeout.',
126
+ ),
127
+ (
128
+ requests.exceptions.ConnectTimeout('Connect timeout.'),
129
+ lf.TemporaryLMError,
130
+ 'Connect timeout.',
131
+ ),
132
+ (
133
+ TimeoutError('Timeout error.'),
134
+ lf.TemporaryLMError,
135
+ 'Timeout error.',
136
+ ),
137
+ (
138
+ requests.exceptions.ConnectionError('REJECTED_CLIENT_THROTTLED'),
139
+ lf.TemporaryLMError,
140
+ 'REJECTED_CLIENT_THROTTLED',
141
+ ),
142
+ (
143
+ requests.exceptions.ConnectionError('Connection error.'),
144
+ lf.LMError,
145
+ 'Connection error.',
146
+ ),
147
+ (
148
+ ConnectionError('Connection error.'),
149
+ lf.LMError,
150
+ 'Connection error.',
151
+ )
152
+ ]:
153
+ with mock.patch('requests.Session.post') as mock_post:
154
+ mock_post.side_effect = mock_requests_post_exception(error)
155
+ with self.assertRaisesRegex(
156
+ expected_lm_error_cls, expected_lm_error_msg
157
+ ):
158
+ self._lm._sample_single(lf.UserMessage('hello'))
159
+
109
160
 
110
161
  if __name__ == '__main__':
111
162
  unittest.main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langfun
3
- Version: 0.1.2.dev202503200804
3
+ Version: 0.1.2.dev202503210804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -96,8 +96,8 @@ langfun/core/llms/openai.py,sha256=zDi-wkV-r3vUZYoTFvU1gaNNVQVQytVuZ4CvTGLsRL8,3
96
96
  langfun/core/llms/openai_compatible.py,sha256=lhq9_XLVUoGa5AIPXTbqGqWvm2P3dkHFSUQ7XnyLozw,5442
97
97
  langfun/core/llms/openai_compatible_test.py,sha256=I5WWL3lRo-WXnSoUKLkIEjXfwjoiHRX9o0dj0j09jsk,17024
98
98
  langfun/core/llms/openai_test.py,sha256=gwuO6aoa296iM2welWV9ua4KF8gEVGsEPakgbtkWkFQ,2687
99
- langfun/core/llms/rest.py,sha256=xdR4ar4y7YkeZTs_BHUyNOdhqoghztMcqyz1f9kTXH8,4054
100
- langfun/core/llms/rest_test.py,sha256=zWGiI08f9gXsoQPJS9TlX1zD2uQLrJUB-1VpAJXRHfs,3475
99
+ langfun/core/llms/rest.py,sha256=ucMKHXlmg6pYSIMhQSktLmTSGMSIiqO8fp1r_GiEhaU,4333
100
+ langfun/core/llms/rest_test.py,sha256=_zM7nV8DEVyoXNiQOnuwJ917mWjki0614H88rNmDboE,5020
101
101
  langfun/core/llms/vertexai.py,sha256=Cf_QeFybIF-dALxdtwy7-ElepSv1ryd6im5-NijwUGE,17646
102
102
  langfun/core/llms/vertexai_test.py,sha256=dOprP_uLNmXHYxMoX_hMPMsjKR-e_B5nKHjhlMCQoOQ,4252
103
103
  langfun/core/llms/cache/__init__.py,sha256=QAo3InUMDM_YpteNnVCSejI4zOsnjSMWKJKzkb3VY64,993
@@ -148,8 +148,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
148
148
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
149
149
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
150
150
  langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
151
- langfun-0.1.2.dev202503200804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
- langfun-0.1.2.dev202503200804.dist-info/METADATA,sha256=8BKJHx56VyQtnyzj6x5f2Ef3j9xWxauu-QRtG5pXvoI,7692
153
- langfun-0.1.2.dev202503200804.dist-info/WHEEL,sha256=tTnHoFhvKQHCh4jz3yCn0WPTYIy7wXx3CJtJ7SJGV7c,91
154
- langfun-0.1.2.dev202503200804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
- langfun-0.1.2.dev202503200804.dist-info/RECORD,,
151
+ langfun-0.1.2.dev202503210804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
+ langfun-0.1.2.dev202503210804.dist-info/METADATA,sha256=_36kWlZZl_4YaLWnhLNWmGCzasqFmIzHLgQFg4jrJXw,7692
153
+ langfun-0.1.2.dev202503210804.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
154
+ langfun-0.1.2.dev202503210804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
+ langfun-0.1.2.dev202503210804.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.1)
2
+ Generator: setuptools (77.0.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5