langfun 0.1.2.dev202412170805__tar.gz → 0.1.2.dev202412190804__tar.gz

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.
Files changed (160) hide show
  1. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/PKG-INFO +1 -1
  2. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/__init__.py +3 -0
  3. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/checkpointing.py +12 -3
  4. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/evaluation.py +73 -6
  5. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/evaluation_test.py +6 -0
  6. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/vertexai.py +1 -1
  7. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/logging.py +19 -0
  8. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/logging_test.py +19 -0
  9. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/__init__.py +2 -0
  10. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/parsing.py +24 -17
  11. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/parsing_test.py +25 -0
  12. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/querying.py +247 -68
  13. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/querying_test.py +87 -0
  14. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/schema.py +2 -12
  15. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun.egg-info/PKG-INFO +1 -1
  16. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/LICENSE +0 -0
  17. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/README.md +0 -0
  18. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/__init__.py +0 -0
  19. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/agentic/__init__.py +0 -0
  20. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/agentic/action.py +0 -0
  21. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/agentic/action_eval.py +0 -0
  22. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/agentic/action_eval_test.py +0 -0
  23. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/agentic/action_test.py +0 -0
  24. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/__init__.py +0 -0
  25. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/__init__.py +0 -0
  26. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/correction.py +0 -0
  27. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/correction_test.py +0 -0
  28. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/errors.py +0 -0
  29. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/errors_test.py +0 -0
  30. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/execution.py +0 -0
  31. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/execution_test.py +0 -0
  32. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/generation.py +0 -0
  33. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/generation_test.py +0 -0
  34. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/parsing.py +0 -0
  35. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/parsing_test.py +0 -0
  36. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/permissions.py +0 -0
  37. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/coding/python/permissions_test.py +0 -0
  38. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/component.py +0 -0
  39. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/component_test.py +0 -0
  40. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/concurrent.py +0 -0
  41. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/concurrent_test.py +0 -0
  42. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/console.py +0 -0
  43. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/console_test.py +0 -0
  44. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/__init__.py +0 -0
  45. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/base.py +0 -0
  46. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/base_test.py +0 -0
  47. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/matching.py +0 -0
  48. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/matching_test.py +0 -0
  49. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/patching.py +0 -0
  50. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/patching_test.py +0 -0
  51. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/scoring.py +0 -0
  52. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/scoring_test.py +0 -0
  53. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/__init__.py +0 -0
  54. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/checkpointing_test.py +0 -0
  55. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/example.py +0 -0
  56. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/example_test.py +0 -0
  57. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/experiment.py +0 -0
  58. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/experiment_test.py +0 -0
  59. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/metric_values.py +0 -0
  60. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/metric_values_test.py +0 -0
  61. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/metrics.py +0 -0
  62. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/metrics_test.py +0 -0
  63. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/progress.py +0 -0
  64. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/progress_test.py +0 -0
  65. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/progress_tracking.py +0 -0
  66. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/progress_tracking_test.py +0 -0
  67. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/reporting.py +0 -0
  68. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/reporting_test.py +0 -0
  69. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/runners.py +0 -0
  70. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/runners_test.py +0 -0
  71. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/eval/v2/test_helper.py +0 -0
  72. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/langfunc.py +0 -0
  73. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/langfunc_test.py +0 -0
  74. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/language_model.py +0 -0
  75. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/language_model_test.py +0 -0
  76. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/__init__.py +0 -0
  77. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/anthropic.py +0 -0
  78. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/anthropic_test.py +0 -0
  79. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/cache/__init__.py +0 -0
  80. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/cache/base.py +0 -0
  81. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/cache/in_memory.py +0 -0
  82. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/cache/in_memory_test.py +0 -0
  83. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/compositional.py +0 -0
  84. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/compositional_test.py +0 -0
  85. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/fake.py +0 -0
  86. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/fake_test.py +0 -0
  87. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/google_genai.py +0 -0
  88. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/google_genai_test.py +0 -0
  89. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/groq.py +0 -0
  90. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/groq_test.py +0 -0
  91. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/llama_cpp.py +0 -0
  92. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/llama_cpp_test.py +0 -0
  93. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/openai.py +0 -0
  94. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/openai_test.py +0 -0
  95. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/rest.py +0 -0
  96. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/rest_test.py +0 -0
  97. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/llms/vertexai_test.py +0 -0
  98. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/memories/__init__.py +0 -0
  99. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/memories/conversation_history.py +0 -0
  100. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/memories/conversation_history_test.py +0 -0
  101. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/memory.py +0 -0
  102. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/message.py +0 -0
  103. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/message_test.py +0 -0
  104. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/__init__.py +0 -0
  105. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/audio.py +0 -0
  106. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/audio_test.py +0 -0
  107. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/image.py +0 -0
  108. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/image_test.py +0 -0
  109. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/mime.py +0 -0
  110. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/mime_test.py +0 -0
  111. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/ms_office.py +0 -0
  112. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/ms_office_test.py +0 -0
  113. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/pdf.py +0 -0
  114. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/pdf_test.py +0 -0
  115. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/video.py +0 -0
  116. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modalities/video_test.py +0 -0
  117. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modality.py +0 -0
  118. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/modality_test.py +0 -0
  119. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/natural_language.py +0 -0
  120. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/natural_language_test.py +0 -0
  121. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/repr_utils.py +0 -0
  122. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/repr_utils_test.py +0 -0
  123. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/sampling.py +0 -0
  124. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/sampling_test.py +0 -0
  125. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/completion.py +0 -0
  126. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/completion_test.py +0 -0
  127. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/description.py +0 -0
  128. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/description_test.py +0 -0
  129. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/function_generation.py +0 -0
  130. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/function_generation_test.py +0 -0
  131. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/mapping.py +0 -0
  132. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/mapping_test.py +0 -0
  133. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/schema_generation.py +0 -0
  134. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/schema_generation_test.py +0 -0
  135. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/schema_test.py +0 -0
  136. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/scoring.py +0 -0
  137. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/scoring_test.py +0 -0
  138. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/tokenization.py +0 -0
  139. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/structured/tokenization_test.py +0 -0
  140. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/subscription.py +0 -0
  141. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/subscription_test.py +0 -0
  142. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/template.py +0 -0
  143. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/template_test.py +0 -0
  144. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/__init__.py +0 -0
  145. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/completion.py +0 -0
  146. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/completion_test.py +0 -0
  147. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/conversation.py +0 -0
  148. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/conversation_test.py +0 -0
  149. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/demonstration.py +0 -0
  150. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/demonstration_test.py +0 -0
  151. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/selfplay.py +0 -0
  152. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/templates/selfplay_test.py +0 -0
  153. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/text_formatting.py +0 -0
  154. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun/core/text_formatting_test.py +0 -0
  155. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun.egg-info/SOURCES.txt +0 -0
  156. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun.egg-info/dependency_links.txt +0 -0
  157. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun.egg-info/requires.txt +0 -0
  158. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/langfun.egg-info/top_level.txt +0 -0
  159. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/setup.cfg +0 -0
  160. {langfun-0.1.2.dev202412170805 → langfun-0.1.2.dev202412190804}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.1.2.dev202412170805
3
+ Version: 0.1.2.dev202412190804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -37,6 +37,9 @@ generate_class = structured.generate_class
37
37
 
38
38
  track_queries = structured.track_queries
39
39
 
40
+ # Helper function for map-reduce style querying.
41
+ query_and_reduce = structured.query_and_reduce
42
+
40
43
  # Helper functions for input/output transformations based on
41
44
  # `lf.query` (e.g. jax-on-beam could use these for batch processing)
42
45
  query_prompt = structured.query_prompt
@@ -92,7 +92,7 @@ class PerExampleCheckpointer(Checkpointer):
92
92
  )
93
93
  )
94
94
  writer.add(example)
95
- del writer
95
+ writer.close()
96
96
  runner.background_run(save_state, example)
97
97
 
98
98
  def _file_prefix_and_ext(self, filename: str) -> tuple[str, str]:
@@ -128,6 +128,8 @@ class BulkCheckpointer(Checkpointer):
128
128
  ) -> None:
129
129
  with self._lock:
130
130
  if self._sequence_writer is not None:
131
+ for writer in self._sequence_writer.values():
132
+ writer.close()
131
133
  self._sequence_writer.clear()
132
134
 
133
135
  def on_run_complete(
@@ -174,6 +176,9 @@ class BulkCheckpointer(Checkpointer):
174
176
  assert experiment.id in self._sequence_writer
175
177
  with self._lock:
176
178
  if self._sequence_writer is not None:
179
+ # Make sure the writer is closed without delay so the file will be
180
+ # available immediately.
181
+ self._sequence_writer[experiment.id].close()
177
182
  del self._sequence_writer[experiment.id]
178
183
 
179
184
  def on_example_complete(
@@ -207,9 +212,13 @@ class SequenceWriter:
207
212
  return
208
213
  self._sequence_writer.add(example_blob)
209
214
 
210
- def __del__(self):
215
+ def close(self):
211
216
  # Make sure there is no write in progress.
212
217
  with self._lock:
213
- assert self._sequence_writer is not None
218
+ if self._sequence_writer is None:
219
+ return
214
220
  self._sequence_writer.close()
215
221
  self._sequence_writer = None
222
+
223
+ def __del__(self):
224
+ self.close()
@@ -14,7 +14,9 @@
14
14
  """Base class for Langfun evaluation tasks."""
15
15
 
16
16
  import abc
17
+ import datetime
17
18
  import functools
19
+ import threading
18
20
  import time
19
21
 
20
22
  from typing import Annotated, Any, Callable, Iterable
@@ -63,6 +65,8 @@ class Evaluation(experiment_lib.Experiment):
63
65
  self.__dict__.pop('is_leaf', None)
64
66
  self.__dict__.pop('children', None)
65
67
  super()._on_bound()
68
+ self._log_entries = []
69
+ self._log_lock = threading.Lock()
66
70
 
67
71
  #
68
72
  # Handling evaluation hierarchy (materialized vs. hyper evaluations).
@@ -277,6 +281,41 @@ class Evaluation(experiment_lib.Experiment):
277
281
  for metric in self.metrics:
278
282
  metric.reset()
279
283
 
284
+ #
285
+ # Evaluation-level logging.
286
+ #
287
+
288
+ def _log(self, level: lf.logging.LogLevel, message: str, **kwargs):
289
+ with self._log_lock:
290
+ self._log_entries.append(
291
+ lf.logging.LogEntry(
292
+ level=level,
293
+ time=datetime.datetime.now(),
294
+ message=message,
295
+ metadata=kwargs,
296
+ )
297
+ )
298
+
299
+ def debug(self, message: str, **kwargs):
300
+ """Logs a debug message to the session."""
301
+ self._log('debug', message, **kwargs)
302
+
303
+ def info(self, message: str, **kwargs):
304
+ """Logs an info message to the session."""
305
+ self._log('info', message, **kwargs)
306
+
307
+ def warning(self, message: str, **kwargs):
308
+ """Logs a warning message to the session."""
309
+ self._log('warning', message, **kwargs)
310
+
311
+ def error(self, message: str, **kwargs):
312
+ """Logs an error message to the session."""
313
+ self._log('error', message, **kwargs)
314
+
315
+ def fatal(self, message: str, **kwargs):
316
+ """Logs a fatal message to the session."""
317
+ self._log('fatal', message, **kwargs)
318
+
280
319
  #
281
320
  # HTML views.
282
321
  #
@@ -465,6 +504,25 @@ class Evaluation(experiment_lib.Experiment):
465
504
  )
466
505
  )
467
506
 
507
+ def _logs_tab() -> pg.views.html.controls.Tab:
508
+ """Renders a tab for the logs of the evaluation."""
509
+ with self._log_lock:
510
+ log_history = '\n'.join(str(l) for l in self._log_entries)
511
+ return pg.views.html.controls.Tab(
512
+ label='Logs',
513
+ content=pg.Html.element(
514
+ 'div',
515
+ [
516
+ pg.Html.element(
517
+ 'textarea',
518
+ [pg.Html.escape(log_history)],
519
+ readonly=True,
520
+ css_classes=['logs-textarea'],
521
+ )
522
+ ]
523
+ )
524
+ )
525
+
468
526
  def _main_tabs() -> pg.Html:
469
527
  return pg.Html.element(
470
528
  'div',
@@ -474,6 +532,8 @@ class Evaluation(experiment_lib.Experiment):
474
532
  _definition_tab(),
475
533
  ] + [
476
534
  _metric_tab(m) for m in self.metrics
535
+ ] + [
536
+ _logs_tab()
477
537
  ],
478
538
  selected=1,
479
539
  )
@@ -593,6 +653,14 @@ class Evaluation(experiment_lib.Experiment):
593
653
  width:100%;
594
654
  height:100%;
595
655
  }
656
+ .logs-textarea {
657
+ width: 100%;
658
+ height: 500px;
659
+ padding: 5px;
660
+ border: 1px solid #DDD;
661
+ background-color: #EEE;
662
+ resize: vertical;
663
+ }
596
664
  """
597
665
  ]
598
666
 
@@ -615,6 +683,11 @@ class EvaluationState:
615
683
  assert isinstance(example, example_lib.Example), example
616
684
  self._evaluated_examples[example.id] = example
617
685
 
686
+ @property
687
+ def evaluated_examples(self) -> dict[int, example_lib.Example]:
688
+ """Returns the examples in the state."""
689
+ return self._evaluated_examples
690
+
618
691
  def get(self, example_id: int) -> example_lib.Example | None:
619
692
  """Returns the example with the given ID."""
620
693
  return self._evaluated_examples.get(example_id)
@@ -622,9 +695,3 @@ class EvaluationState:
622
695
  def update(self, example: example_lib.Example) -> None:
623
696
  """Updates the state with the given example."""
624
697
  self._evaluated_examples[example.id] = example
625
-
626
- @property
627
- def evaluated_examples(self) -> dict[int, example_lib.Example]:
628
- """Returns the examples in the state."""
629
- return self._evaluated_examples
630
-
@@ -133,6 +133,12 @@ class EvaluationTest(unittest.TestCase):
133
133
 
134
134
  def test_html_view(self):
135
135
  exp = test_helper.TestEvaluation()
136
+ exp.debug('debug message')
137
+ exp.info('info message')
138
+ exp.warning('warning message', x=1)
139
+ exp.error('error message', x=1)
140
+ exp.fatal('fatal message')
141
+
136
142
  self.assertIn(
137
143
  exp.id,
138
144
  exp.to_html(extra_flags=dict(card_view=True, current_run=None)).content
@@ -409,7 +409,7 @@ class VertexAIGemini2_0(VertexAI): # pylint: disable=invalid-name
409
409
  )
410
410
 
411
411
 
412
- class VertexAIGeminiFlash2_0Exp(VertexAI): # pylint: disable=invalid-name
412
+ class VertexAIGeminiFlash2_0Exp(VertexAIGemini2_0): # pylint: disable=invalid-name
413
413
  """Vertex AI Gemini 2.0 Flash model."""
414
414
 
415
415
  model = 'gemini-2.0-flash-exp'
@@ -54,6 +54,25 @@ class LogEntry(pg.Object, pg.views.HtmlTreeView.Extension):
54
54
  def should_output(self, min_log_level: LogLevel) -> bool:
55
55
  return _LOG_LEVELS.index(self.level) >= _LOG_LEVELS.index(min_log_level)
56
56
 
57
+ def format(self,
58
+ compact: bool = False,
59
+ verbose: bool = True,
60
+ root_indent: int = 0,
61
+ *,
62
+ text_format: bool = True,
63
+ **kwargs):
64
+ if text_format:
65
+ s = f"""{self.time.strftime('%H:%M:%S')} {self.level.upper()} - {self.message}"""
66
+ if self.metadata:
67
+ s += f' (metadata: {self.metadata!r})'
68
+ return s
69
+ return super().format(
70
+ compact=compact,
71
+ verbose=verbose,
72
+ root_indent=root_indent,
73
+ **kwargs
74
+ )
75
+
57
76
  def _html_tree_view_summary(
58
77
  self,
59
78
  view: pg.views.HtmlTreeView,
@@ -61,6 +61,25 @@ class LoggingTest(unittest.TestCase):
61
61
  print(actual)
62
62
  self.assertEqual(actual, expected)
63
63
 
64
+ def test_format(self):
65
+ time = datetime.datetime(2024, 10, 10, 12, 30, 45)
66
+ self.assertEqual(
67
+ str(
68
+ logging.LogEntry(
69
+ level='info', message='hello\nworld',
70
+ time=time, metadata=dict(x=1),
71
+ )
72
+ ),
73
+ '12:30:45 INFO - hello\nworld (metadata: {x=1})',
74
+ )
75
+ self.assertIn(
76
+ 'LogEntry(',
77
+ logging.LogEntry(
78
+ level='info', message='hello\nworld',
79
+ time=time, metadata=dict(x=1),
80
+ ).format(text_format=False),
81
+ )
82
+
64
83
  def test_html(self):
65
84
  time = datetime.datetime(2024, 10, 10, 12, 30, 45)
66
85
  self.assert_html_content(
@@ -56,6 +56,8 @@ from langfun.core.structured.parsing import call
56
56
  from langfun.core.structured.querying import track_queries
57
57
  from langfun.core.structured.querying import QueryInvocation
58
58
  from langfun.core.structured.querying import query
59
+ from langfun.core.structured.querying import query_and_reduce
60
+
59
61
  from langfun.core.structured.querying import query_prompt
60
62
  from langfun.core.structured.querying import query_output
61
63
  from langfun.core.structured.querying import query_reward
@@ -270,24 +270,31 @@ def call(
270
270
  if schema in (str, None):
271
271
  return lm_output if returns_message else lm_output.text
272
272
 
273
+ def _chain_nl_output_message(parsing_message: lf.Message):
274
+ """Chain the source of the parsed output to the LM output."""
275
+ parsing_message.root.source = lm_output
276
+ parsing_message.tag('parsing-lm-output')
277
+ parsing_message.lm_input.tag('parsing-lm-input')
278
+
273
279
  # Call `parsing_lm` for structured parsing.
274
- parsing_message = querying.query(
275
- lm_output.text,
276
- schema,
277
- examples=parsing_examples,
278
- lm=parsing_lm or lm,
279
- include_context=parsing_include_context,
280
- cache_seed=cache_seed,
281
- autofix=autofix,
282
- autofix_lm=autofix_lm or lm,
283
- protocol=protocol,
284
- returns_message=True,
285
- **kwargs,
286
- )
287
- # Chain the source of the parsed output to the LM output.
288
- parsing_message.root.source = lm_output
289
- parsing_message.tag('parsing-lm-output')
290
- parsing_message.lm_input.tag('parsing-lm-input')
280
+ try:
281
+ parsing_message = querying.query(
282
+ lm_output.text,
283
+ schema,
284
+ examples=parsing_examples,
285
+ lm=parsing_lm or lm,
286
+ include_context=parsing_include_context,
287
+ cache_seed=cache_seed,
288
+ autofix=autofix,
289
+ autofix_lm=autofix_lm or lm,
290
+ protocol=protocol,
291
+ returns_message=True,
292
+ **kwargs,
293
+ )
294
+ _chain_nl_output_message(parsing_message)
295
+ except mapping.MappingError as e:
296
+ _chain_nl_output_message(e.lm_response)
297
+ raise e
291
298
  return parsing_message if returns_message else parsing_message.result
292
299
 
293
300
 
@@ -686,6 +686,31 @@ class CallTest(unittest.TestCase):
686
686
  ],
687
687
  returns_message=True,
688
688
  )
689
+ self.assertIn('parsing-lm-output', output.tags)
690
+ self.assertIn('parsing-lm-input', output.source.tags)
691
+ self.assertEqual(output.root.text, 'Compute 1 + 2')
692
+
693
+ def test_call_with_parsing_message_chaining_on_parsing_error(self):
694
+ try:
695
+ output = parsing.call(
696
+ 'Compute 1 + 2',
697
+ int,
698
+ lm=fake.StaticSequence(['three']),
699
+ parsing_lm=fake.StaticSequence(['abc']),
700
+ parsing_examples=[
701
+ mapping.MappingExample(
702
+ context='Multiple four and five',
703
+ input='twenty',
704
+ schema=int,
705
+ output=20,
706
+ )
707
+ ],
708
+ returns_message=True,
709
+ )
710
+ except mapping.MappingError as e:
711
+ output = e.lm_response
712
+ self.assertIn('parsing-lm-output', output.tags)
713
+ self.assertIn('parsing-lm-input', output.source.tags)
689
714
  self.assertEqual(output.root.text, 'Compute 1 + 2')
690
715
 
691
716
  def test_call_with_autofix(self):