langfun 0.1.2.dev202503200804__py3-none-any.whl → 0.1.2.dev202503220803__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/eval/base.py CHANGED
@@ -77,6 +77,7 @@ class Evaluable(lf.Component):
77
77
 
78
78
  @classmethod
79
79
  def link(cls, path: str) -> str:
80
+ assert path.startswith('/'), path
80
81
  return f'file://{path}'
81
82
 
82
83
  @property
@@ -28,6 +28,8 @@ from langfun.core.eval.v2.metric_values import Average
28
28
  from langfun.core.eval.v2.metrics import Metric
29
29
  from langfun.core.eval.v2 import metrics
30
30
 
31
+ from langfun.core.eval.v2.experiment import Run
32
+ from langfun.core.eval.v2.experiment import RunId
31
33
  from langfun.core.eval.v2.experiment import Plugin
32
34
  from langfun.core.eval.v2.experiment import Runner
33
35
  from langfun.core.eval.v2 import runners
@@ -425,7 +425,7 @@ class Evaluation(experiment_lib.Experiment):
425
425
  [
426
426
  pg.views.html.controls.Label(
427
427
  'Summary',
428
- link=run.experiment.output_link(run, 'summary.html'),
428
+ link=run.output_link('summary.html'),
429
429
  css_classes=['summary-link'],
430
430
  ),
431
431
  '|',
@@ -571,7 +571,7 @@ class Evaluation(experiment_lib.Experiment):
571
571
  pg.Html.element(
572
572
  'iframe', [],
573
573
  name='example-view',
574
- src='./1.html',
574
+ src='about:blank',
575
575
  title='Example view.',
576
576
  css_classes=['example-view'],
577
577
  ),
@@ -276,6 +276,7 @@ class Experiment(lf.Component, pg.views.HtmlTreeView.Extension):
276
276
 
277
277
  @classmethod
278
278
  def link(cls, path: str) -> str:
279
+ assert path.startswith('/'), path
279
280
  return f'file://{path}'
280
281
 
281
282
  #
@@ -887,6 +888,10 @@ class Run(pg.Object, pg.views.html.HtmlTreeView.Extension):
887
888
  return os.path.join(self.output_root, experiment.id.replace('@', '/'))
888
889
  return self.output_root
889
890
 
891
+ def output_link(self, relative_path: str):
892
+ """Returns the output link for the relative path."""
893
+ return Experiment.link(os.path.join(self.output_root, relative_path))
894
+
890
895
  def input_dir(self, experiment: Experiment) -> str:
891
896
  """Returns the input directory of the experiment."""
892
897
  if experiment.is_leaf:
@@ -218,6 +218,10 @@ class RunTest(unittest.TestCase):
218
218
  )
219
219
  self.assertEqual(run.output_root, '/root/run_20241102_0')
220
220
  self.assertEqual(run.input_root, '/root/run_20241102_0')
221
+ self.assertEqual(
222
+ run.output_link('summary.html'),
223
+ 'file:///root/run_20241102_0/summary.html'
224
+ )
221
225
  self.assertEqual(
222
226
  run.output_dir(run.experiment.leaf_nodes[0]),
223
227
  (
@@ -13,6 +13,7 @@
13
13
  # limitations under the License.
14
14
  """Reporting evaluation results."""
15
15
 
16
+ import os
16
17
  import threading
17
18
  import time
18
19
  import traceback
@@ -145,9 +146,7 @@ class HtmlReporter(experiment_lib.Plugin):
145
146
  )
146
147
  )
147
148
  with self._summary_lock:
148
- html.save(
149
- run.output_path_for(run.experiment, _SUMMARY_FILE)
150
- )
149
+ html.save(os.path.join(run.output_root, _SUMMARY_FILE))
151
150
 
152
151
  if force or (time.time() - self._last_summary_time > self.summary_interval):
153
152
  self._last_summary_time = time.time()
@@ -31,7 +31,7 @@ class ReportingTest(unittest.TestCase):
31
31
  reporter = reporting.HtmlReporter()
32
32
  run = experiment.run(root_dir, 'new', plugins=[checkpointer, reporter])
33
33
  self.assertTrue(
34
- pg.io.path_exists(run.output_path_for(experiment, 'summary.html'))
34
+ pg.io.path_exists(os.path.join(run.output_root, 'summary.html'))
35
35
  )
36
36
  for leaf in experiment.leaf_nodes:
37
37
  self.assertTrue(
@@ -56,7 +56,7 @@ class ReportingTest(unittest.TestCase):
56
56
  warm_start_from=run.output_root
57
57
  )
58
58
  self.assertTrue(
59
- pg.io.path_exists(run.output_path_for(experiment, 'summary.html'))
59
+ pg.io.path_exists(os.path.join(run.output_root, 'summary.html'))
60
60
  )
61
61
  for leaf in experiment.leaf_nodes:
62
62
  self.assertTrue(
@@ -83,7 +83,7 @@ class ReportingTest(unittest.TestCase):
83
83
  reporter = reporting.HtmlReporter()
84
84
  run = experiment.run(root_dir, 'new', plugins=[reporter])
85
85
  self.assertFalse(
86
- pg.io.path_exists(run.output_path_for(experiment, 'summary.html'))
86
+ pg.io.path_exists(os.path.join(run.output_root, 'summary.html'))
87
87
  )
88
88
  for leaf in experiment.leaf_nodes:
89
89
  self.assertFalse(
@@ -107,7 +107,7 @@ class ReportingTest(unittest.TestCase):
107
107
  reporter = reporting.HtmlReporter()
108
108
  run = experiment.run(root_dir, 'new', plugins=[checkpointer, reporter])
109
109
  self.assertTrue(
110
- pg.io.path_exists(run.output_path_for(experiment, 'summary.html'))
110
+ pg.io.path_exists(os.path.join(run.output_root, 'summary.html'))
111
111
  )
112
112
  for leaf in experiment.leaf_nodes:
113
113
  self.assertTrue(
@@ -136,7 +136,7 @@ class ReportingTest(unittest.TestCase):
136
136
  warm_start_from=run.output_root
137
137
  )
138
138
  self.assertTrue(
139
- pg.io.path_exists(run.output_path_for(experiment, 'summary.html'))
139
+ pg.io.path_exists(os.path.join(run.output_root, 'summary.html'))
140
140
  )
141
141
  for leaf in experiment.leaf_nodes:
142
142
  self.assertTrue(
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.dev202503220803
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -43,7 +43,7 @@ langfun/core/coding/python/parsing_test.py,sha256=PIexYpSEhgNaSd4T6QYWzWHzm3sL4V
43
43
  langfun/core/coding/python/sandboxing.py,sha256=yeEdydMkfHk3Hj3-5ykeROpYyLbRfZ4BwGWJYvFBmSI,4001
44
44
  langfun/core/coding/python/sandboxing_test.py,sha256=H_0_pd-_uS-ci5yYhmDTR6-hyzosAFkExziAHndfdDo,2023
45
45
  langfun/core/eval/__init__.py,sha256=OEXr1ZRuvLuhJJfuQ1ZWQ-SvYzjyrtiAAEogYaB7E6o,1933
46
- langfun/core/eval/base.py,sha256=XXerMVkK4wREo7K1_aCyay6vDjw3mfs389XThAdzv50,75768
46
+ langfun/core/eval/base.py,sha256=qIJnrO1jX5pzY8yoQTtcTn5lGdD9adz5U6C_jla1BV4,75806
47
47
  langfun/core/eval/base_test.py,sha256=UJBsfsXNAfZpSSI6oEF7_VxPp13SzRRLRfuCnU7a4JM,27189
48
48
  langfun/core/eval/matching.py,sha256=AVKkGoc-BaHEzgSBamaAk3194TgqckDe_dinpS6LrXI,9323
49
49
  langfun/core/eval/matching_test.py,sha256=rdawe6q3pWfKyW6Qk67b3LBN_zYTa7OfDYjl9mJj5P8,5249
@@ -51,16 +51,16 @@ langfun/core/eval/patching.py,sha256=R0s2eAd1m97exQt06dmUL0V_MBG0W2Hxg7fhNB7cXW0
51
51
  langfun/core/eval/patching_test.py,sha256=8kCd54Egjju22FMgtJuxEsrXkW8ifs-UUBHtrCG1L6w,4775
52
52
  langfun/core/eval/scoring.py,sha256=_DvnlgI1SdRVaOojao_AkV3pnenfCPOqyhvlg-Sw-5M,6322
53
53
  langfun/core/eval/scoring_test.py,sha256=adQEeuDux11dt9lkJIzLYNmqYSi9h-Mi2Cr0lUUTx9I,4546
54
- langfun/core/eval/v2/__init__.py,sha256=qoa6zKdFXOFyCX6vay6OdgPf1eUhYGoHYAxe35qECGk,1628
54
+ langfun/core/eval/v2/__init__.py,sha256=9lNKJwbvl0lcFblAXYT_OHI8fOubJsTOdSkxEqsP1xU,1726
55
55
  langfun/core/eval/v2/checkpointing.py,sha256=t47rBfzGZYgIqWW1N1Ak9yQnNtHd-IRbEO0cZjG2VRo,11755
56
56
  langfun/core/eval/v2/checkpointing_test.py,sha256=NggOSJ_6XSa4cNP6nGIu9wLsK59dUwe8SPWDiXtGGDE,9197
57
57
  langfun/core/eval/v2/eval_test_helper.py,sha256=sKFi_wPYCNmr96WyTduuXY0KnxjFxcJyEhXey-_nGX8,3962
58
- langfun/core/eval/v2/evaluation.py,sha256=qiM1z8xLEDU1381woIkcJmFkfF2oaRKG2NrixW2UNZ0,24042
58
+ langfun/core/eval/v2/evaluation.py,sha256=faL-G98rdGBW9hMSlzZJtkGMytBqvTZRue1k9m_BWRQ,24029
59
59
  langfun/core/eval/v2/evaluation_test.py,sha256=TKbeyeenoaUDH23E3TXXJ4otuq3VZBuWkWdV7c5vMk4,6804
60
60
  langfun/core/eval/v2/example.py,sha256=4-LNr8Ke-fhaF6gyeXX4JMyw0s8YkVTC63pXZ-CXKrE,10144
61
61
  langfun/core/eval/v2/example_test.py,sha256=1DNm6EuyZOq827DKvf3oTRVFkMNM_qTnLUpvOjpgz5I,3419
62
- langfun/core/eval/v2/experiment.py,sha256=qYWx22KMfoUa4ieSq1bt7NE8L9dgoiJpuNOQGT1IBQw,32723
63
- langfun/core/eval/v2/experiment_test.py,sha256=CqpDsDai2DiIU-SzpVmqFzM_ZxxkVYKd0Gr1Uvcvkuw,13546
62
+ langfun/core/eval/v2/experiment.py,sha256=hHNyIw1uSV-hW2nMMx4hV-uul7KwXCmp7jAWNRyT5fU,32938
63
+ langfun/core/eval/v2/experiment_test.py,sha256=UmCobeS6ifPcaGkTJp0WPISolXrVFbeFCBiyJeA0Lt4,13666
64
64
  langfun/core/eval/v2/metric_values.py,sha256=_B905bC-jxrYPLSEcP2M8MaHZOVMz_bVrUw8YC4arCE,4660
65
65
  langfun/core/eval/v2/metric_values_test.py,sha256=ab2oF_HsIwrSy459108ggyjgefHSPn8UVILR4dRwx14,2634
66
66
  langfun/core/eval/v2/metrics.py,sha256=bl8i6u-ZHRBz4hAc3LzsZ2Dc7ZRQcuTYeUhhH-GxfF0,10628
@@ -69,8 +69,8 @@ langfun/core/eval/v2/progress.py,sha256=azZgssQgNdv3IgjKEaQBuGI5ucFDNbdi02P4z_nQ
69
69
  langfun/core/eval/v2/progress_test.py,sha256=YU7VHzmy5knPZwj9vpBN3rQQH2tukj9eKHkuBCI62h8,2540
70
70
  langfun/core/eval/v2/progress_tracking.py,sha256=l9fEkz4oP5McpZzf72Ua7PYm3lAWtRru7gRWNf8H0ms,6083
71
71
  langfun/core/eval/v2/progress_tracking_test.py,sha256=fouMVJkFJqHjbhQJngGLGCmA9x3n0dU4USI2dY163mg,2291
72
- langfun/core/eval/v2/reporting.py,sha256=7rL9LLmGYnQ5HIjqRqsOMkUlBl4BmFPEL6Vlofqi2Hk,8353
73
- langfun/core/eval/v2/reporting_test.py,sha256=UmYSAQvD3AIXsSyWQ-WD2uLtEISYpmBeoKY5u5Qwc8E,5696
72
+ langfun/core/eval/v2/reporting.py,sha256=yUIPCAMnp7InIzpv1DDWrcLO-75iiOUTpscj7smkfrA,8335
73
+ langfun/core/eval/v2/reporting_test.py,sha256=hcPJJaMtPulqERvHYTpId83WXdqDKnnexmULtK7WKwk,5686
74
74
  langfun/core/eval/v2/runners.py,sha256=De4d5QQ-Tpw0nPDODQexDPy0ti-FEgzHBvfH78zqdtg,15945
75
75
  langfun/core/eval/v2/runners_test.py,sha256=A37fKK2MvAVTiShsg_laluJzJ9AuAQn52k7HPbfD0Ks,11666
76
76
  langfun/core/llms/__init__.py,sha256=F2nqEv9Cc-1QALrlPnIEp-TZiSVTi6U8WWb1YwDt1w0,8038
@@ -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.dev202503220803.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
+ langfun-0.1.2.dev202503220803.dist-info/METADATA,sha256=z8c-QQRstr1soNbtJeSrzitjRg0XSYkaDXeF01SoRpw,7692
153
+ langfun-0.1.2.dev202503220803.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
154
+ langfun-0.1.2.dev202503220803.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
+ langfun-0.1.2.dev202503220803.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