langfun 0.1.2.dev202409230804__py3-none-any.whl → 0.1.2.dev202409250804__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
@@ -215,6 +215,7 @@ class Evaluable(lf.Component):
215
215
  summary: bool = True,
216
216
  pivot_field: str = 'lm',
217
217
  from_root: bool = True,
218
+ timeout: int | None = None,
218
219
  **kwargs,
219
220
  ) -> Union['Summary', pg.Dict]:
220
221
  """Run the evaluation, which fills and returns the result."""
@@ -265,6 +266,7 @@ class Evaluable(lf.Component):
265
266
  verbose=verbose,
266
267
  progress_bar=progress_bar,
267
268
  label=label,
269
+ timeout=timeout,
268
270
  **kwargs,
269
271
  )
270
272
 
@@ -398,6 +400,7 @@ class Evaluable(lf.Component):
398
400
  verbose: bool,
399
401
  progress_bar: int | None,
400
402
  label: str | None,
403
+ timeout: int | None = None,
401
404
  **kwargs,
402
405
  ) -> None:
403
406
  """Run the evaluate and fill `self.result`. Subclass to implement."""
@@ -1106,6 +1109,7 @@ class Evaluation(Evaluable):
1106
1109
  verbose: bool,
1107
1110
  progress_bar: int | None,
1108
1111
  label: str | None,
1112
+ timeout: int | None = None,
1109
1113
  **kwargs,
1110
1114
  ) -> None:
1111
1115
  # Setup examples.
@@ -1136,6 +1140,7 @@ class Evaluation(Evaluable):
1136
1140
  max_workers=self.max_workers,
1137
1141
  show_progress=progress_bar or False,
1138
1142
  status_fn=self._status,
1143
+ timeout=timeout,
1139
1144
  ):
1140
1145
  if error is not None:
1141
1146
  message = (
@@ -266,20 +266,27 @@ class Matching(base.Evaluation):
266
266
  '<td>Prompt/Response Chain</td>'
267
267
  '</tr>'
268
268
  )
269
+ def _maybe_html(v, root_indent: int):
270
+ del root_indent
271
+ if hasattr(v, '_repr_html_'):
272
+ return v._repr_html_() # pylint: disable=protected-access
273
+ # Fall back to the default format.
274
+ return None
275
+
269
276
  for i, (example, output, message) in enumerate(self.matches):
270
277
  bgcolor = 'white' if i % 2 == 0 else '#DDDDDD'
271
278
  s.write(f'<tr style="background-color: {bgcolor}"><td>{i + 1}</td>')
272
279
  input_str = lf.repr_utils.escape_quoted(
273
280
  pg.format(
274
281
  example, verbose=False, max_bytes_len=32,
275
- custom_format='_repr_html_'
282
+ custom_format=_maybe_html
276
283
  )
277
284
  )
278
285
  s.write(f'<td style="color:green;white-space:pre-wrap">{input_str}</td>')
279
286
  output_str = lf.repr_utils.escape_quoted(
280
287
  pg.format(
281
288
  output, verbose=False, max_bytes_len=32,
282
- custom_format='_repr_html_'
289
+ custom_format=_maybe_html
283
290
  )
284
291
  )
285
292
  s.write(f'<td style="color:blue;white-space:pre-wrap">{output_str}</td>')
@@ -237,6 +237,8 @@ class VertexAI(lf.LanguageModel):
237
237
  # API. We should revisit this later.
238
238
  retry_on_errors = [
239
239
  (Exception, 'InternalServerError'),
240
+ (Exception, 'ResourceExhausted'),
241
+ (Exception, '_InactiveRpcError'),
240
242
  (
241
243
  Exception,
242
244
  (
@@ -247,11 +249,9 @@ class VertexAI(lf.LanguageModel):
247
249
  (Exception, 'ValueError: Cannot get the Candidate text.'),
248
250
  ]
249
251
 
250
- return lf.concurrent_execute(
252
+ return self._parallel_execute_with_currency_control(
251
253
  self._sample_single,
252
254
  prompts,
253
- executor=self.resource_id,
254
- max_workers=self.max_concurrency,
255
255
  retry_on_errors=retry_on_errors,
256
256
  )
257
257
 
langfun/core/modality.py CHANGED
@@ -49,6 +49,13 @@ class Modality(component.Component):
49
49
  return super().format(*args, **kwargs)
50
50
  return Modality.text_marker(self.referred_name)
51
51
 
52
+ def __str_kwargs__(self) -> dict[str, Any]:
53
+ # For modality objects, we don't want to use markdown format when they
54
+ # are rendered as parts of the prompt.
55
+ kwargs = super().__str_kwargs__()
56
+ kwargs.pop('markdown', None)
57
+ return kwargs
58
+
52
59
  @abc.abstractmethod
53
60
  def to_bytes(self) -> bytes:
54
61
  """Returns content in bytes."""
@@ -121,8 +121,15 @@ def html_repr(
121
121
  s.write('<table style="border-top: 1px solid #EEEEEE;">')
122
122
  item_color = item_color or (lambda k, v: (None, '#F1C40F', None, None))
123
123
 
124
- with (pg.str_format(custom_format='_repr_html_'),
125
- pg.repr_format(custom_format='_repr_html_')):
124
+ def maybe_html_format(v: Any, root_indent: int) -> str | None:
125
+ del root_indent
126
+ if hasattr(v, '_repr_html_'):
127
+ return v._repr_html_() # pylint: disable=protected-access
128
+ # Fall back to the default format.
129
+ return None
130
+
131
+ with (pg.str_format(custom_format=maybe_html_format),
132
+ pg.repr_format(custom_format=maybe_html_format)):
126
133
  for k, v in pg.object_utils.flatten(value).items():
127
134
  if isinstance(v, pg.Ref):
128
135
  v = v.value
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.1.2.dev202409230804
3
+ Version: 0.1.2.dev202409250804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -15,11 +15,11 @@ langfun/core/logging_test.py,sha256=poSsNGKi6G9LWOcWnTY0BQjj0BtaQknH-NK6FcQrVT4,
15
15
  langfun/core/memory.py,sha256=f-asN1F7Vehgdn_fK84v73GrEUOxRtaW934keutTKjk,2416
16
16
  langfun/core/message.py,sha256=7UOxNMA1Le0ZGkleryqwXcWojZ-l_hku5Sc58BsIOGw,18586
17
17
  langfun/core/message_test.py,sha256=2o4WvE-WL67OsVY-O5g__67OIJ73vvg6MuojSc2uVRs,12504
18
- langfun/core/modality.py,sha256=g9wGx347oVofAJlMu_CpzTMIyTT9DJW8NfO4E-d-oNM,3879
18
+ langfun/core/modality.py,sha256=hC0LF8EGCU2GJxTNbfzR441oOk2-HnHnAVWbwkLG0bI,4133
19
19
  langfun/core/modality_test.py,sha256=7SwhixFME2Q1sIXRgJx97EZFiIyC31A9NVr6_nDtFv4,2441
20
20
  langfun/core/natural_language.py,sha256=3ynSnaYQnjE60LIPK5fyMgdIjubnPYZwzGq4rWPeloE,1177
21
21
  langfun/core/natural_language_test.py,sha256=LHGU_1ytbkGuSZQFIFP7vP3dBlcY4-A12fT6dbjUA0E,1424
22
- langfun/core/repr_utils.py,sha256=S2aZQllHuy2syduFiYKJm--GPoJWRGS5cXvbC1pdEUs,6243
22
+ langfun/core/repr_utils.py,sha256=yyc2xeK8sKQOOLcxwIV9E50Wf-B0TjXrnS07tSx_ea8,6491
23
23
  langfun/core/repr_utils_test.py,sha256=ULG7gvgoyqQFWi0m6g2-E0GorNEr1nnZ0J_sZVQKz80,3036
24
24
  langfun/core/sampling.py,sha256=vygWvgC8MFw0_AKNSmz-ywMXJYWf8cl0tI8QycvAmyI,5795
25
25
  langfun/core/sampling_test.py,sha256=U7PANpMsl9E_pa4_Y4FzesSjcwg-u-LKHGCWSgv-8FY,3663
@@ -44,9 +44,9 @@ langfun/core/coding/python/parsing_test.py,sha256=9vAWF484kWIm6JZq8NFiMgKUDhXV-d
44
44
  langfun/core/coding/python/permissions.py,sha256=1QWGHvzL8MM0Ok_auQ9tURqZHtdOfJaDpBzZ29GUE-c,2544
45
45
  langfun/core/coding/python/permissions_test.py,sha256=w5EDb8QxpxgJyZkojyzVWQvDfg366zn99-g__6TbPQ0,2699
46
46
  langfun/core/eval/__init__.py,sha256=Ogdr9OtTywhhLPHi3AZzOD2mXX2oyaHWflrSTMm96uA,1899
47
- langfun/core/eval/base.py,sha256=xDZQ3lu5oJaPDZCE5-QbBEajq--HRU64GVKb3xB64aI,74738
47
+ langfun/core/eval/base.py,sha256=4GX9kBbgzNPxa5G9n_b6tYSMqz4qFEdio-FMdd3q68A,74898
48
48
  langfun/core/eval/base_test.py,sha256=iL-EEGnBD_HigClBwo34HVyOycupgw9r4S61eIZMShI,26929
49
- langfun/core/eval/matching.py,sha256=124Y6pCb4fDmhICH728aeROZ6nNFitKyV6FFLklCe1k,9840
49
+ langfun/core/eval/matching.py,sha256=8p1W_sA0I3XpRgw7Rf8Jbko_Ym-JAALeM2wpSmu4jKQ,10063
50
50
  langfun/core/eval/matching_test.py,sha256=f7iVyXH5KGJBWt4Wp14Bt9J3X59A6Ayfog9MbuFvPew,5532
51
51
  langfun/core/eval/patching.py,sha256=R0s2eAd1m97exQt06dmUL0V_MBG0W2Hxg7fhNB7cXW0,3866
52
52
  langfun/core/eval/patching_test.py,sha256=8kCd54Egjju22FMgtJuxEsrXkW8ifs-UUBHtrCG1L6w,4775
@@ -67,7 +67,7 @@ langfun/core/llms/openai.py,sha256=vnDrKuD-pli0AtDIDq_TmlltOk7z7_PQ-xpU4K1ARdU,1
67
67
  langfun/core/llms/openai_test.py,sha256=UcBFW_7RkkMEo47Tn5RuVRK_DryTN7bb9ITphlzthE8,17762
68
68
  langfun/core/llms/rest.py,sha256=laopuq-zD8V-3Y6eFDngftHEbE66VlUkCD2-rvvRaLU,3388
69
69
  langfun/core/llms/rest_test.py,sha256=NZ3Nf0XQVpT9kLP5cBVo_yBHLI7vWTYhWQxYEJVMGs4,3472
70
- langfun/core/llms/vertexai.py,sha256=mEQVwO3Kf3rGRmsI-qKrV6vg0hYy6OH1lEVOM81cb3U,15134
70
+ langfun/core/llms/vertexai.py,sha256=hQR8eghtvPCH9l4fvuFkfV51UOiACH705Le5bmwEBDc,15164
71
71
  langfun/core/llms/vertexai_test.py,sha256=EPR-mB2hNUpvpf7E8m_k5bh04epdQTVUuYU6hPgZyu8,10321
72
72
  langfun/core/llms/cache/__init__.py,sha256=QAo3InUMDM_YpteNnVCSejI4zOsnjSMWKJKzkb3VY64,993
73
73
  langfun/core/llms/cache/base.py,sha256=rt3zwmyw0y9jsSGW-ZbV1vAfLxQ7_3AVk0l2EySlse4,3918
@@ -119,8 +119,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
119
119
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
120
120
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
121
121
  langfun/core/templates/selfplay_test.py,sha256=rBW2Qr8yi-aWYwoTwRR-n1peKyMX9QXPZXURjLgoiRs,2264
122
- langfun-0.1.2.dev202409230804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
123
- langfun-0.1.2.dev202409230804.dist-info/METADATA,sha256=volNIPva2x4lyFLL7h_HCv0bBiBOiAxhYcdGmvfdJUc,8890
124
- langfun-0.1.2.dev202409230804.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
125
- langfun-0.1.2.dev202409230804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
126
- langfun-0.1.2.dev202409230804.dist-info/RECORD,,
122
+ langfun-0.1.2.dev202409250804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
123
+ langfun-0.1.2.dev202409250804.dist-info/METADATA,sha256=lsO6y55zp6NzVTsJAUkn_Zb6n6G8Hh7Zt-sOIykhNmk,8890
124
+ langfun-0.1.2.dev202409250804.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
125
+ langfun-0.1.2.dev202409250804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
126
+ langfun-0.1.2.dev202409250804.dist-info/RECORD,,