langfun 0.1.2.dev202504260803__py3-none-any.whl → 0.1.2.dev202504280818__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.

Potentially problematic release.


This version of langfun might be problematic. Click here for more details.

@@ -1132,3 +1132,14 @@ class Session(pg.Object, pg.views.html.HtmlTreeView.Extension):
1132
1132
  enable_key_tooltip=False,
1133
1133
  )
1134
1134
  return config
1135
+
1136
+
1137
+ # Register the logging functions to skip the source of the logging functions.
1138
+ pg.logging.register_frame_to_skip([
1139
+ Session._log, # pylint: disable=protected-access
1140
+ Session.debug,
1141
+ Session.info,
1142
+ Session.warning,
1143
+ Session.error,
1144
+ Session.fatal
1145
+ ])
@@ -316,7 +316,9 @@ class Evaluation(experiment_lib.Experiment):
316
316
 
317
317
  def _log(self, log_func, level: lf.logging.LogLevel, message: str, **kwargs):
318
318
  # Write to external logging system.
319
- log_message = f'{self.id}: {message}'
319
+ log_message = message
320
+ if self.id not in log_message:
321
+ log_message = f'{self.id}: {log_message}'
320
322
  if kwargs:
321
323
  log_message = f'{log_message} (metadata: {kwargs!r})'
322
324
  log_func(log_message)
@@ -331,26 +333,6 @@ class Evaluation(experiment_lib.Experiment):
331
333
  with self._log_lock:
332
334
  self._log_entries.append(log_entry)
333
335
 
334
- # Also add system log.
335
- match level:
336
- case 'debug':
337
- sys_log_func = pg.logging.debug
338
- case 'info':
339
- sys_log_func = pg.logging.info
340
- case 'warning':
341
- sys_log_func = pg.logging.warning
342
- case 'error':
343
- sys_log_func = pg.logging.error
344
- case 'fatal':
345
- sys_log_func = pg.logging.error
346
- case _:
347
- raise ValueError(f'Unsupported log level: {level}')
348
-
349
- sys_log_func(
350
- '%s: %s\nMetadata: %s',
351
- self.id, message, pg.format(kwargs)
352
- )
353
-
354
336
  def debug(self, message: str, **kwargs):
355
337
  """Logs a debug message to the session."""
356
338
  self._log(pg.logging.debug, 'debug', message, **kwargs)
@@ -806,3 +788,13 @@ class EvaluationState:
806
788
  has_error=example.has_error,
807
789
  )
808
790
  )
791
+
792
+ # Register the logging functions to skip the source of the logging functions.
793
+ pg.logging.register_frame_to_skip([
794
+ Evaluation._log, # pylint: disable=protected-access
795
+ Evaluation.debug,
796
+ Evaluation.info,
797
+ Evaluation.warning,
798
+ Evaluation.error,
799
+ Evaluation.fatal
800
+ ])
langfun/core/logging.py CHANGED
@@ -335,3 +335,7 @@ def fatal(
335
335
  ) -> LogEntry:
336
336
  """Logs a fatal message to the session."""
337
337
  return log('fatal', message, indent=indent, console=console, **kwargs)
338
+
339
+
340
+ # Register the logging functions to skip the source of the logging functions.
341
+ pg.logging.register_frame_to_skip([log, debug, info, warning, error, fatal])
@@ -456,6 +456,11 @@ def class_definition(
456
456
  )
457
457
  continue
458
458
 
459
+ # Skip fields that are marked as excluded from the prompt sent to LLM
460
+ # for OOP.
461
+ if field.metadata.get('exclude_from_prompt', False):
462
+ continue
463
+
459
464
  # Write field doc string as comments before the field definition.
460
465
  if field.description:
461
466
  for line in field.description.split('\n'):
@@ -671,6 +676,7 @@ class ValuePythonRepr(ValueRepr):
671
676
  compact: bool = True,
672
677
  verbose: bool = False,
673
678
  markdown: bool = True,
679
+ assign_to_var: str | None = None,
674
680
  **kwargs) -> str:
675
681
  del schema
676
682
  if inspect.isclass(value):
@@ -694,6 +700,8 @@ class ValuePythonRepr(ValueRepr):
694
700
  object_code = pg.format(
695
701
  value, compact=compact, verbose=verbose, python_format=True
696
702
  )
703
+ if assign_to_var is not None:
704
+ object_code = f'{assign_to_var} = {object_code}'
697
705
  if markdown:
698
706
  return f'```python\n{ object_code }\n```'
699
707
  return object_code
@@ -538,6 +538,19 @@ class SchemaPythonReprTest(unittest.TestCase):
538
538
  """) + '\n'
539
539
  )
540
540
 
541
+ class E(pg.Object):
542
+ x: str
543
+ y: typing.Annotated[int, 'y', dict(exclude_from_prompt=True)]
544
+
545
+ self.assertEqual(
546
+ schema_lib.class_definition(E),
547
+ inspect.cleandoc(
548
+ """
549
+ class E(Object):
550
+ x: str
551
+ """) + '\n'
552
+ )
553
+
541
554
  def test_repr(self):
542
555
  class Foo(pg.Object):
543
556
  x: int
@@ -704,6 +717,30 @@ class ValuePythonReprTest(unittest.TestCase):
704
717
  ),
705
718
  "A(foo=[Foo(x=1), Foo(x=2)], y='bar')",
706
719
  )
720
+ self.assertEqual(
721
+ schema_lib.ValuePythonRepr().repr(
722
+ A([Foo(1), Foo(2)], 'bar'),
723
+ schema_lib.Schema(A),
724
+ markdown=True,
725
+ compact=False,
726
+ assign_to_var='output',
727
+ ),
728
+ inspect.cleandoc("""
729
+ ```python
730
+ output = A(
731
+ foo=[
732
+ Foo(
733
+ x=1
734
+ ),
735
+ Foo(
736
+ x=2
737
+ )
738
+ ],
739
+ y='bar'
740
+ )
741
+ ```
742
+ """),
743
+ )
707
744
  self.assertEqual(
708
745
  schema_lib.ValuePythonRepr().repr(A),
709
746
  inspect.cleandoc("""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langfun
3
- Version: 0.1.2.dev202504260803
3
+ Version: 0.1.2.dev202504280818
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -10,7 +10,7 @@ langfun/core/langfunc.py,sha256=G50YgoVZ0y1GFw2ev41MlOqr6qa8YakbvNC0h_E0PiA,1114
10
10
  langfun/core/langfunc_test.py,sha256=CDn-gJCa5EnjN7cotAVCfSCbuzddq2o-HzEt7kV8HbY,8882
11
11
  langfun/core/language_model.py,sha256=_hT8dGHw7CWQgMTQ-Ons5VTOwpF_j8k_gn2P0hoG-lE,46307
12
12
  langfun/core/language_model_test.py,sha256=iA5uo7rIj2jAtCYzMzhyNg1fWqE2Onn60bOO58q72C0,36454
13
- langfun/core/logging.py,sha256=ERTIE08dQ36K0qQ-6Vu-5uaEZIFWdHj9rVCXpEtc_7U,8959
13
+ langfun/core/logging.py,sha256=ypjSwGzQpIhadewEKkIH5VWS55rfU4e6mlni41PMHlw,9116
14
14
  langfun/core/logging_test.py,sha256=vbVGOQxwMmVSiFfbt2897gUt-8nqDpV64jCAeUG_q5U,6924
15
15
  langfun/core/memory.py,sha256=f-asN1F7Vehgdn_fK84v73GrEUOxRtaW934keutTKjk,2416
16
16
  langfun/core/message.py,sha256=qUJZ9NfrlYG3aU_K2ud236gdTnvZ7Qw2T4pv4hI9ivg,32817
@@ -26,7 +26,7 @@ langfun/core/subscription_test.py,sha256=Y4ZdbZEwm83YNZBxHff0QR4QUa4rdaNXA3_jfIc
26
26
  langfun/core/template.py,sha256=jNhYSrbLIn9kZOa03w5QZbyjgfnzJzE_ZrrMvvWY4t4,24929
27
27
  langfun/core/template_test.py,sha256=AQv_m9qE93WxhEhSlm1xaBgB4hu0UVtA53dljngkUW0,17090
28
28
  langfun/core/agentic/__init__.py,sha256=qR3jlfUO4rhIoYdRDLz-d22YZf3FvU4FW88vsjiGDQQ,1224
29
- langfun/core/agentic/action.py,sha256=zMFCyfG52pP_nDTZzJKw5BjMvREz4ER_wHLbhDzEA_g,33731
29
+ langfun/core/agentic/action.py,sha256=83zH_cj0s9mxq7mnaTZXbB0Uf-y8d0ip5TrF-mabeT8,34000
30
30
  langfun/core/agentic/action_eval.py,sha256=-ZcWt_eYqnTyOe9HFGyrLJkQRd4iG3hfN4IZ-NYAWwA,4534
31
31
  langfun/core/agentic/action_eval_test.py,sha256=tRUkWmOE9p0rpNOq19xAY2oDEnYsEEykjg6sUpAwJk0,2832
32
32
  langfun/core/agentic/action_test.py,sha256=ilirTICURoAR6LYjlg3oC3P1KSbLzJQDK4WaZONed2Q,5708
@@ -63,7 +63,7 @@ langfun/core/eval/v2/__init__.py,sha256=9lNKJwbvl0lcFblAXYT_OHI8fOubJsTOdSkxEqsP
63
63
  langfun/core/eval/v2/checkpointing.py,sha256=t47rBfzGZYgIqWW1N1Ak9yQnNtHd-IRbEO0cZjG2VRo,11755
64
64
  langfun/core/eval/v2/checkpointing_test.py,sha256=NggOSJ_6XSa4cNP6nGIu9wLsK59dUwe8SPWDiXtGGDE,9197
65
65
  langfun/core/eval/v2/eval_test_helper.py,sha256=sKFi_wPYCNmr96WyTduuXY0KnxjFxcJyEhXey-_nGX8,3962
66
- langfun/core/eval/v2/evaluation.py,sha256=kdhou304i74LSjvCPuY4jeF7HpkQGZsKVFEhZCn1FUU,25105
66
+ langfun/core/eval/v2/evaluation.py,sha256=07ebNx3bYlN25sg4Nam_QJRuikKVt9Pc0oXmSG6IS-k,24937
67
67
  langfun/core/eval/v2/evaluation_test.py,sha256=TKbeyeenoaUDH23E3TXXJ4otuq3VZBuWkWdV7c5vMk4,6804
68
68
  langfun/core/eval/v2/example.py,sha256=Jegt-viQSNYzPVkOZE_M19GON2TYGTct4Cp9HnJ7DGo,10861
69
69
  langfun/core/eval/v2/example_test.py,sha256=1DNm6EuyZOq827DKvf3oTRVFkMNM_qTnLUpvOjpgz5I,3419
@@ -139,10 +139,10 @@ langfun/core/structured/parsing.py,sha256=MGvI7ypXlwfzr5XB8_TFU9Ei0_5reYqkWkv64e
139
139
  langfun/core/structured/parsing_test.py,sha256=kNPrhpdPY3iWhUld0TFYU-Zgn44wC0d6YuQ9XdVbQ8o,22346
140
140
  langfun/core/structured/querying.py,sha256=GGNtHtJcKh8rzLBNx_Df1ATvsPZzyfZuGkzSQVabdpo,24885
141
141
  langfun/core/structured/querying_test.py,sha256=vUuVUClYBFGEaO9KuD60huPE1dmP6RCRLeRnBv67NmQ,34263
142
- langfun/core/structured/schema.py,sha256=_iqhHEGDQsHk0AsybWnK44sOspTWkKJjci781PWD7x0,27988
142
+ langfun/core/structured/schema.py,sha256=pGiAjez-ON2nKLUSeAls27gJsMto5aJnCXLVwH3pUKM,28296
143
143
  langfun/core/structured/schema_generation.py,sha256=3AcuKvv3VOtKY5zMVqODrxfOuDxzoZtGeBxHlOWDOWw,5308
144
144
  langfun/core/structured/schema_generation_test.py,sha256=RM9s71kMNg2jTePwInkiW9fK1ACN37eyPeF8OII-0zw,2950
145
- langfun/core/structured/schema_test.py,sha256=ntgPzhoVhTRzT_QKn7ipXDIc6CZmz_zCpCzZnGKc_WQ,25193
145
+ langfun/core/structured/schema_test.py,sha256=N8qNVA2hrHlxmHIoKtpzhBASa2RMVoPowF_noAfgPME,26035
146
146
  langfun/core/structured/scoring.py,sha256=Y7Jqs5VVjUQLF_9Z1uIY_dw5zasv2FF52Cz-cxGMsro,5857
147
147
  langfun/core/structured/scoring_test.py,sha256=QvlwDAzwuamKL5tCotm1L3Sx0cs3idoNK4aIEhaO4Yk,2272
148
148
  langfun/core/structured/tokenization.py,sha256=-b4_693quHeYn2AqndwucuXNmhd5NVXVTU3mmDane98,2189
@@ -156,8 +156,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
156
156
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
157
157
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
158
158
  langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
159
- langfun-0.1.2.dev202504260803.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
160
- langfun-0.1.2.dev202504260803.dist-info/METADATA,sha256=QUbCmM8v2vdPPyI7qvlJ47cvgUyQ5Z-gyRRbjLjJi8w,7692
161
- langfun-0.1.2.dev202504260803.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
162
- langfun-0.1.2.dev202504260803.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
163
- langfun-0.1.2.dev202504260803.dist-info/RECORD,,
159
+ langfun-0.1.2.dev202504280818.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
160
+ langfun-0.1.2.dev202504280818.dist-info/METADATA,sha256=plAMucug-VTFRA1dV85tEMMxAzexbS7Oro6dvINtLHA,7692
161
+ langfun-0.1.2.dev202504280818.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
162
+ langfun-0.1.2.dev202504280818.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
163
+ langfun-0.1.2.dev202504280818.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (79.0.1)
2
+ Generator: setuptools (80.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5