langfun 0.1.2.dev202510230805__py3-none-any.whl → 0.1.2.dev202511160804__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.

Files changed (146) hide show
  1. langfun/core/__init__.py +1 -0
  2. langfun/core/agentic/action.py +107 -12
  3. langfun/core/agentic/action_eval.py +9 -2
  4. langfun/core/agentic/action_test.py +25 -0
  5. langfun/core/async_support.py +32 -3
  6. langfun/core/coding/python/correction.py +19 -9
  7. langfun/core/coding/python/execution.py +14 -12
  8. langfun/core/coding/python/generation.py +21 -16
  9. langfun/core/coding/python/sandboxing.py +23 -3
  10. langfun/core/component.py +42 -3
  11. langfun/core/concurrent.py +70 -6
  12. langfun/core/concurrent_test.py +1 -0
  13. langfun/core/console.py +1 -1
  14. langfun/core/data/conversion/anthropic.py +12 -3
  15. langfun/core/data/conversion/anthropic_test.py +8 -6
  16. langfun/core/data/conversion/gemini.py +9 -2
  17. langfun/core/data/conversion/gemini_test.py +12 -9
  18. langfun/core/data/conversion/openai.py +145 -31
  19. langfun/core/data/conversion/openai_test.py +161 -17
  20. langfun/core/eval/base.py +47 -43
  21. langfun/core/eval/base_test.py +4 -4
  22. langfun/core/eval/matching.py +5 -2
  23. langfun/core/eval/patching.py +3 -3
  24. langfun/core/eval/scoring.py +4 -3
  25. langfun/core/eval/v2/__init__.py +1 -0
  26. langfun/core/eval/v2/checkpointing.py +39 -5
  27. langfun/core/eval/v2/checkpointing_test.py +1 -1
  28. langfun/core/eval/v2/eval_test_helper.py +96 -0
  29. langfun/core/eval/v2/evaluation.py +87 -15
  30. langfun/core/eval/v2/evaluation_test.py +9 -3
  31. langfun/core/eval/v2/example.py +45 -39
  32. langfun/core/eval/v2/example_test.py +3 -3
  33. langfun/core/eval/v2/experiment.py +51 -8
  34. langfun/core/eval/v2/metric_values.py +31 -3
  35. langfun/core/eval/v2/metric_values_test.py +32 -0
  36. langfun/core/eval/v2/metrics.py +157 -44
  37. langfun/core/eval/v2/metrics_test.py +39 -18
  38. langfun/core/eval/v2/progress.py +30 -1
  39. langfun/core/eval/v2/progress_test.py +27 -0
  40. langfun/core/eval/v2/progress_tracking_test.py +3 -0
  41. langfun/core/eval/v2/reporting.py +90 -71
  42. langfun/core/eval/v2/reporting_test.py +20 -6
  43. langfun/core/eval/v2/runners/__init__.py +26 -0
  44. langfun/core/eval/v2/{runners.py → runners/base.py} +22 -124
  45. langfun/core/eval/v2/runners/debug.py +40 -0
  46. langfun/core/eval/v2/runners/debug_test.py +79 -0
  47. langfun/core/eval/v2/runners/parallel.py +100 -0
  48. langfun/core/eval/v2/runners/parallel_test.py +98 -0
  49. langfun/core/eval/v2/runners/sequential.py +47 -0
  50. langfun/core/eval/v2/runners/sequential_test.py +175 -0
  51. langfun/core/langfunc.py +45 -130
  52. langfun/core/langfunc_test.py +6 -4
  53. langfun/core/language_model.py +103 -16
  54. langfun/core/language_model_test.py +9 -3
  55. langfun/core/llms/__init__.py +7 -1
  56. langfun/core/llms/anthropic.py +157 -2
  57. langfun/core/llms/azure_openai.py +29 -17
  58. langfun/core/llms/cache/base.py +25 -3
  59. langfun/core/llms/cache/in_memory.py +48 -7
  60. langfun/core/llms/cache/in_memory_test.py +14 -4
  61. langfun/core/llms/compositional.py +25 -1
  62. langfun/core/llms/deepseek.py +30 -2
  63. langfun/core/llms/fake.py +32 -1
  64. langfun/core/llms/gemini.py +14 -9
  65. langfun/core/llms/google_genai.py +29 -1
  66. langfun/core/llms/groq.py +28 -3
  67. langfun/core/llms/llama_cpp.py +23 -4
  68. langfun/core/llms/openai.py +36 -3
  69. langfun/core/llms/openai_compatible.py +148 -27
  70. langfun/core/llms/openai_compatible_test.py +207 -20
  71. langfun/core/llms/openai_test.py +0 -2
  72. langfun/core/llms/rest.py +12 -1
  73. langfun/core/llms/vertexai.py +51 -8
  74. langfun/core/logging.py +1 -1
  75. langfun/core/mcp/client.py +77 -22
  76. langfun/core/mcp/client_test.py +8 -35
  77. langfun/core/mcp/session.py +94 -29
  78. langfun/core/mcp/session_test.py +54 -0
  79. langfun/core/mcp/tool.py +151 -22
  80. langfun/core/mcp/tool_test.py +197 -0
  81. langfun/core/memory.py +1 -0
  82. langfun/core/message.py +160 -55
  83. langfun/core/message_test.py +65 -81
  84. langfun/core/modalities/__init__.py +8 -0
  85. langfun/core/modalities/audio.py +21 -1
  86. langfun/core/modalities/image.py +19 -1
  87. langfun/core/modalities/mime.py +62 -3
  88. langfun/core/modalities/pdf.py +19 -1
  89. langfun/core/modalities/video.py +21 -1
  90. langfun/core/modality.py +167 -29
  91. langfun/core/modality_test.py +42 -12
  92. langfun/core/natural_language.py +1 -1
  93. langfun/core/sampling.py +4 -4
  94. langfun/core/sampling_test.py +20 -4
  95. langfun/core/structured/__init__.py +2 -24
  96. langfun/core/structured/completion.py +34 -44
  97. langfun/core/structured/completion_test.py +23 -43
  98. langfun/core/structured/description.py +54 -50
  99. langfun/core/structured/function_generation.py +29 -12
  100. langfun/core/structured/mapping.py +81 -37
  101. langfun/core/structured/parsing.py +95 -79
  102. langfun/core/structured/parsing_test.py +0 -3
  103. langfun/core/structured/querying.py +215 -142
  104. langfun/core/structured/querying_test.py +65 -29
  105. langfun/core/structured/schema/__init__.py +48 -0
  106. langfun/core/structured/schema/base.py +664 -0
  107. langfun/core/structured/schema/base_test.py +531 -0
  108. langfun/core/structured/schema/json.py +174 -0
  109. langfun/core/structured/schema/json_test.py +121 -0
  110. langfun/core/structured/schema/python.py +316 -0
  111. langfun/core/structured/schema/python_test.py +410 -0
  112. langfun/core/structured/schema_generation.py +33 -14
  113. langfun/core/structured/scoring.py +47 -36
  114. langfun/core/structured/tokenization.py +26 -11
  115. langfun/core/subscription.py +2 -2
  116. langfun/core/template.py +174 -49
  117. langfun/core/template_test.py +123 -17
  118. langfun/env/__init__.py +8 -2
  119. langfun/env/base_environment.py +320 -128
  120. langfun/env/base_environment_test.py +473 -0
  121. langfun/env/base_feature.py +92 -15
  122. langfun/env/base_feature_test.py +228 -0
  123. langfun/env/base_sandbox.py +84 -361
  124. langfun/env/base_sandbox_test.py +1235 -0
  125. langfun/env/event_handlers/__init__.py +1 -1
  126. langfun/env/event_handlers/chain.py +233 -0
  127. langfun/env/event_handlers/chain_test.py +253 -0
  128. langfun/env/event_handlers/event_logger.py +95 -98
  129. langfun/env/event_handlers/event_logger_test.py +21 -21
  130. langfun/env/event_handlers/metric_writer.py +225 -140
  131. langfun/env/event_handlers/metric_writer_test.py +23 -6
  132. langfun/env/interface.py +854 -40
  133. langfun/env/interface_test.py +112 -2
  134. langfun/env/load_balancers_test.py +23 -2
  135. langfun/env/test_utils.py +126 -84
  136. {langfun-0.1.2.dev202510230805.dist-info → langfun-0.1.2.dev202511160804.dist-info}/METADATA +1 -1
  137. langfun-0.1.2.dev202511160804.dist-info/RECORD +211 -0
  138. langfun/core/eval/v2/runners_test.py +0 -343
  139. langfun/core/structured/schema.py +0 -987
  140. langfun/core/structured/schema_test.py +0 -982
  141. langfun/env/base_test.py +0 -1481
  142. langfun/env/event_handlers/base.py +0 -350
  143. langfun-0.1.2.dev202510230805.dist-info/RECORD +0 -195
  144. {langfun-0.1.2.dev202510230805.dist-info → langfun-0.1.2.dev202511160804.dist-info}/WHEEL +0 -0
  145. {langfun-0.1.2.dev202510230805.dist-info → langfun-0.1.2.dev202511160804.dist-info}/licenses/LICENSE +0 -0
  146. {langfun-0.1.2.dev202510230805.dist-info → langfun-0.1.2.dev202511160804.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,228 @@
1
+ # Copyright 2025 The Langfun Authors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ import unittest
15
+
16
+ from langfun.env import test_utils
17
+
18
+ TestingEnvironment = test_utils.TestingEnvironment
19
+ TestingNonSandboxBasedFeature = test_utils.TestingNonSandboxBasedFeature
20
+ TestingEventHandler = test_utils.TestingEventHandler
21
+
22
+
23
+ class NonSandboxBasedFeatureTests(unittest.TestCase):
24
+
25
+ def test_basics(self):
26
+ feature = TestingNonSandboxBasedFeature()
27
+ event_handler = TestingEventHandler(
28
+ log_session_setup=True,
29
+ log_feature_setup=True,
30
+ log_sandbox_status=True
31
+ )
32
+ env = TestingEnvironment(
33
+ image_ids=[],
34
+ features={'test_feature': feature},
35
+ event_handler=event_handler,
36
+ )
37
+ self.assertFalse(env.is_online)
38
+ self.assertEqual(len(list(env.non_sandbox_based_features())), 1)
39
+ with env:
40
+ self.assertTrue(env.is_online)
41
+ with env.test_feature('session1') as feature:
42
+ self.assertIsNone(feature.sandbox)
43
+ self.assertEqual(feature.session_id, 'session1')
44
+
45
+ self.assertEqual(
46
+ event_handler.logs,
47
+ [
48
+ '[testing-env/test_feature] feature setup',
49
+ '[testing-env] environment started',
50
+ '[testing-env/test_feature@session1] feature setup session',
51
+ '[testing-env/test_feature@session1] feature teardown session',
52
+ '[testing-env/test_feature] feature teardown',
53
+ '[testing-env] environment shutdown'
54
+ ]
55
+ )
56
+
57
+ def test_feature_setup_error(self):
58
+ event_handler = TestingEventHandler(
59
+ log_session_setup=True,
60
+ log_feature_setup=True,
61
+ log_sandbox_status=True
62
+ )
63
+ env = TestingEnvironment(
64
+ image_ids=[],
65
+ features={
66
+ 'test_feature': TestingNonSandboxBasedFeature(
67
+ simulate_setup_error=ValueError
68
+ )
69
+ },
70
+ event_handler=event_handler,
71
+ )
72
+ with self.assertRaises(ValueError):
73
+ with env:
74
+ pass
75
+ self.assertEqual(
76
+ event_handler.logs,
77
+ [
78
+ '[testing-env/test_feature] feature setup with ValueError',
79
+ '[testing-env] environment started with ValueError',
80
+ '[testing-env/test_feature] feature teardown',
81
+ '[testing-env] environment shutdown'
82
+ ]
83
+ )
84
+
85
+ def test_feature_teardown_error(self):
86
+ event_handler = TestingEventHandler(
87
+ log_session_setup=True,
88
+ log_feature_setup=True,
89
+ log_sandbox_status=True
90
+ )
91
+ env = TestingEnvironment(
92
+ image_ids=[],
93
+ features={
94
+ 'test_feature': TestingNonSandboxBasedFeature(
95
+ simulate_teardown_error=ValueError
96
+ )
97
+ },
98
+ event_handler=event_handler,
99
+ )
100
+ with env:
101
+ pass
102
+ self.assertEqual(
103
+ event_handler.logs,
104
+ [
105
+ '[testing-env/test_feature] feature setup',
106
+ '[testing-env] environment started',
107
+ '[testing-env/test_feature] feature teardown with ValueError',
108
+ '[testing-env] environment shutdown'
109
+ ]
110
+ )
111
+
112
+ def test_feature_setup_session_error(self):
113
+ event_handler = TestingEventHandler(
114
+ log_session_setup=True,
115
+ log_feature_setup=True,
116
+ log_sandbox_status=True
117
+ )
118
+ env = TestingEnvironment(
119
+ image_ids=[],
120
+ features={
121
+ 'test_feature': TestingNonSandboxBasedFeature(
122
+ simulate_setup_session_error=ValueError
123
+ )
124
+ },
125
+ event_handler=event_handler,
126
+ )
127
+ with env:
128
+ with self.assertRaises(ValueError):
129
+ with env.test_feature('session1'):
130
+ pass
131
+ self.assertEqual(
132
+ event_handler.logs,
133
+ [
134
+ # pylint: disable=line-too-long
135
+ '[testing-env/test_feature] feature setup',
136
+ '[testing-env] environment started',
137
+ '[testing-env/test_feature@session1] feature setup session with ValueError',
138
+ '[testing-env/test_feature@session1] feature teardown session',
139
+ '[testing-env/test_feature] feature teardown',
140
+ '[testing-env] environment shutdown',
141
+ # pylint: enable=line-too-long
142
+ ]
143
+ )
144
+
145
+ def test_feature_teardown_session_error(self):
146
+ event_handler = TestingEventHandler(
147
+ log_session_setup=True,
148
+ log_feature_setup=True,
149
+ log_sandbox_status=True
150
+ )
151
+ env = TestingEnvironment(
152
+ image_ids=[],
153
+ features={
154
+ 'test_feature': TestingNonSandboxBasedFeature(
155
+ simulate_teardown_session_error=ValueError
156
+ )
157
+ },
158
+ event_handler=event_handler,
159
+ )
160
+ with env:
161
+ with env.test_feature('session1'):
162
+ pass
163
+ self.assertEqual(
164
+ event_handler.logs,
165
+ [
166
+ # pylint: disable=line-too-long
167
+ '[testing-env/test_feature] feature setup',
168
+ '[testing-env] environment started',
169
+ '[testing-env/test_feature@session1] feature setup session',
170
+ '[testing-env/test_feature@session1] feature teardown session with ValueError',
171
+ '[testing-env/test_feature] feature teardown',
172
+ '[testing-env] environment shutdown',
173
+ # pylint: enable=line-too-long
174
+ ]
175
+ )
176
+
177
+ def test_feature_housekeeping(self):
178
+ event_handler = TestingEventHandler(
179
+ log_sandbox_status=False,
180
+ log_feature_setup=False,
181
+ log_housekeep=True
182
+ )
183
+ env = TestingEnvironment(
184
+ image_ids=[],
185
+ features={
186
+ 'test_feature': TestingNonSandboxBasedFeature(
187
+ housekeep_interval=0.1
188
+ )
189
+ },
190
+ event_handler=event_handler,
191
+ housekeep_interval=0.2
192
+ )
193
+ with env:
194
+ env.wait_for_housekeeping()
195
+ self.assertIn(
196
+ '[testing-env/test_feature] feature housekeeping 0',
197
+ event_handler.logs
198
+ )
199
+
200
+ def test_feature_housekeeping_error(self):
201
+ event_handler = TestingEventHandler(
202
+ log_sandbox_status=False,
203
+ log_feature_setup=False,
204
+ log_housekeep=True
205
+ )
206
+ env = TestingEnvironment(
207
+ image_ids=[],
208
+ features={
209
+ 'test_feature': TestingNonSandboxBasedFeature(
210
+ simulate_housekeep_error=ValueError,
211
+ housekeep_interval=0.1
212
+ )
213
+ },
214
+ event_handler=event_handler,
215
+ housekeep_interval=0.2
216
+ )
217
+ with env:
218
+ env.wait_for_housekeeping()
219
+ self.assertFalse(env.is_online)
220
+ self.assertIn(
221
+ '[testing-env/test_feature] feature housekeeping 0 with ValueError',
222
+ event_handler.logs
223
+ )
224
+
225
+
226
+ if __name__ == '__main__':
227
+ unittest.main()
228
+