langfun 0.1.2.dev202508250805__py3-none-any.whl → 0.1.2.dev202511110805__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 (133) hide show
  1. langfun/__init__.py +1 -1
  2. langfun/core/__init__.py +6 -1
  3. langfun/core/agentic/__init__.py +4 -0
  4. langfun/core/agentic/action.py +412 -103
  5. langfun/core/agentic/action_eval.py +9 -2
  6. langfun/core/agentic/action_test.py +68 -6
  7. langfun/core/async_support.py +104 -5
  8. langfun/core/async_support_test.py +23 -0
  9. langfun/core/coding/python/correction.py +19 -9
  10. langfun/core/coding/python/execution.py +14 -12
  11. langfun/core/coding/python/generation.py +21 -16
  12. langfun/core/coding/python/sandboxing.py +23 -3
  13. langfun/core/component.py +42 -3
  14. langfun/core/concurrent.py +70 -6
  15. langfun/core/concurrent_test.py +9 -2
  16. langfun/core/console.py +1 -1
  17. langfun/core/data/conversion/anthropic.py +12 -3
  18. langfun/core/data/conversion/anthropic_test.py +8 -6
  19. langfun/core/data/conversion/gemini.py +9 -2
  20. langfun/core/data/conversion/gemini_test.py +12 -9
  21. langfun/core/data/conversion/openai.py +145 -31
  22. langfun/core/data/conversion/openai_test.py +161 -17
  23. langfun/core/eval/base.py +47 -43
  24. langfun/core/eval/base_test.py +4 -4
  25. langfun/core/eval/matching.py +5 -2
  26. langfun/core/eval/patching.py +3 -3
  27. langfun/core/eval/scoring.py +4 -3
  28. langfun/core/eval/v2/__init__.py +1 -0
  29. langfun/core/eval/v2/checkpointing.py +30 -4
  30. langfun/core/eval/v2/eval_test_helper.py +1 -1
  31. langfun/core/eval/v2/evaluation.py +60 -14
  32. langfun/core/eval/v2/example.py +22 -11
  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 +39 -4
  37. langfun/core/eval/v2/metrics_test.py +14 -0
  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 +6 -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.py +27 -7
  44. langfun/core/eval/v2/runners_test.py +3 -0
  45. langfun/core/langfunc.py +45 -130
  46. langfun/core/langfunc_test.py +6 -4
  47. langfun/core/language_model.py +151 -31
  48. langfun/core/language_model_test.py +9 -3
  49. langfun/core/llms/__init__.py +12 -1
  50. langfun/core/llms/anthropic.py +157 -2
  51. langfun/core/llms/azure_openai.py +29 -17
  52. langfun/core/llms/cache/base.py +25 -3
  53. langfun/core/llms/cache/in_memory.py +48 -7
  54. langfun/core/llms/cache/in_memory_test.py +14 -4
  55. langfun/core/llms/compositional.py +25 -1
  56. langfun/core/llms/deepseek.py +30 -2
  57. langfun/core/llms/fake.py +39 -1
  58. langfun/core/llms/fake_test.py +9 -0
  59. langfun/core/llms/gemini.py +43 -7
  60. langfun/core/llms/google_genai.py +34 -1
  61. langfun/core/llms/groq.py +28 -3
  62. langfun/core/llms/llama_cpp.py +23 -4
  63. langfun/core/llms/openai.py +93 -3
  64. langfun/core/llms/openai_compatible.py +148 -27
  65. langfun/core/llms/openai_compatible_test.py +207 -20
  66. langfun/core/llms/openai_test.py +0 -2
  67. langfun/core/llms/rest.py +16 -1
  68. langfun/core/llms/vertexai.py +59 -8
  69. langfun/core/logging.py +1 -1
  70. langfun/core/mcp/__init__.py +10 -0
  71. langfun/core/mcp/client.py +177 -0
  72. langfun/core/mcp/client_test.py +71 -0
  73. langfun/core/mcp/session.py +241 -0
  74. langfun/core/mcp/session_test.py +54 -0
  75. langfun/core/mcp/testing/simple_mcp_client.py +33 -0
  76. langfun/core/mcp/testing/simple_mcp_server.py +33 -0
  77. langfun/core/mcp/tool.py +256 -0
  78. langfun/core/mcp/tool_test.py +197 -0
  79. langfun/core/memory.py +1 -0
  80. langfun/core/message.py +160 -55
  81. langfun/core/message_test.py +65 -81
  82. langfun/core/modalities/__init__.py +8 -0
  83. langfun/core/modalities/audio.py +21 -1
  84. langfun/core/modalities/image.py +19 -1
  85. langfun/core/modalities/mime.py +62 -3
  86. langfun/core/modalities/pdf.py +19 -1
  87. langfun/core/modalities/video.py +21 -1
  88. langfun/core/modality.py +167 -29
  89. langfun/core/modality_test.py +42 -12
  90. langfun/core/natural_language.py +1 -1
  91. langfun/core/sampling.py +4 -4
  92. langfun/core/sampling_test.py +20 -4
  93. langfun/core/structured/completion.py +34 -44
  94. langfun/core/structured/completion_test.py +23 -43
  95. langfun/core/structured/description.py +54 -50
  96. langfun/core/structured/function_generation.py +29 -12
  97. langfun/core/structured/mapping.py +74 -28
  98. langfun/core/structured/parsing.py +90 -74
  99. langfun/core/structured/parsing_test.py +0 -3
  100. langfun/core/structured/querying.py +242 -156
  101. langfun/core/structured/querying_test.py +95 -64
  102. langfun/core/structured/schema.py +70 -10
  103. langfun/core/structured/schema_generation.py +33 -14
  104. langfun/core/structured/scoring.py +45 -34
  105. langfun/core/structured/tokenization.py +24 -9
  106. langfun/core/subscription.py +2 -2
  107. langfun/core/template.py +175 -50
  108. langfun/core/template_test.py +123 -17
  109. langfun/env/__init__.py +43 -0
  110. langfun/env/base_environment.py +827 -0
  111. langfun/env/base_environment_test.py +473 -0
  112. langfun/env/base_feature.py +304 -0
  113. langfun/env/base_feature_test.py +228 -0
  114. langfun/env/base_sandbox.py +842 -0
  115. langfun/env/base_sandbox_test.py +1235 -0
  116. langfun/env/event_handlers/__init__.py +14 -0
  117. langfun/env/event_handlers/chain.py +233 -0
  118. langfun/env/event_handlers/chain_test.py +253 -0
  119. langfun/env/event_handlers/event_logger.py +472 -0
  120. langfun/env/event_handlers/event_logger_test.py +304 -0
  121. langfun/env/event_handlers/metric_writer.py +726 -0
  122. langfun/env/event_handlers/metric_writer_test.py +214 -0
  123. langfun/env/interface.py +1640 -0
  124. langfun/env/interface_test.py +151 -0
  125. langfun/env/load_balancers.py +59 -0
  126. langfun/env/load_balancers_test.py +139 -0
  127. langfun/env/test_utils.py +497 -0
  128. {langfun-0.1.2.dev202508250805.dist-info → langfun-0.1.2.dev202511110805.dist-info}/METADATA +7 -3
  129. langfun-0.1.2.dev202511110805.dist-info/RECORD +200 -0
  130. langfun-0.1.2.dev202508250805.dist-info/RECORD +0 -172
  131. {langfun-0.1.2.dev202508250805.dist-info → langfun-0.1.2.dev202511110805.dist-info}/WHEEL +0 -0
  132. {langfun-0.1.2.dev202508250805.dist-info → langfun-0.1.2.dev202511110805.dist-info}/licenses/LICENSE +0 -0
  133. {langfun-0.1.2.dev202508250805.dist-info → langfun-0.1.2.dev202511110805.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,214 @@
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
+
15
+ import unittest
16
+
17
+ from langfun.env import interface
18
+ from langfun.env import test_utils
19
+ from langfun.env.event_handlers import metric_writer as metric_writer_lib
20
+
21
+
22
+ class MetricWriterTest(unittest.TestCase):
23
+
24
+ def test_write_metric(self):
25
+ writer = metric_writer_lib.MetricWriter(app='test_app')
26
+ env = test_utils.TestingEnvironment(
27
+ features={
28
+ 'test_feature1': test_utils.TestingFeature(housekeep_interval=0),
29
+ 'test_feature2': test_utils.TestingFeature(housekeep_interval=None),
30
+ },
31
+ pool_size=2,
32
+ outage_grace_period=0,
33
+ outage_retry_interval=0,
34
+ housekeep_interval=10.0,
35
+ sandbox_keepalive_interval=1.0,
36
+ event_handler=writer,
37
+ )
38
+ with env:
39
+ with env.sandbox(session_id='session1') as sb:
40
+ self.assertEqual(sb.test_feature1.num_shell_calls(), 4)
41
+
42
+ with self.assertRaises(interface.SandboxStateError):
43
+ with env.sandbox(session_id='session2') as sb:
44
+ sb.shell('echo "bar"', raise_error=RuntimeError)
45
+
46
+ self.assertIn(
47
+ writer._sandbox_start.value(
48
+ app='test_app',
49
+ environment_id='testing-env',
50
+ image_id='test_image',
51
+ error='Success'
52
+ ),
53
+ (2, 3)
54
+ )
55
+ self.assertGreater(
56
+ writer._sandbox_housekeep.value(
57
+ app='test_app',
58
+ environment_id='testing-env',
59
+ image_id='test_image',
60
+ error='Success'
61
+ ),
62
+ 0,
63
+ )
64
+ self.assertEqual(
65
+ writer._sandbox_shutdown.value(
66
+ app='test_app',
67
+ environment_id='testing-env',
68
+ image_id='test_image',
69
+ error='Success'
70
+ ),
71
+ 2
72
+ )
73
+ self.assertEqual(
74
+ writer._sandbox_count.value(
75
+ app='test_app',
76
+ environment_id='testing-env',
77
+ image_id='test_image',
78
+ status='ready',
79
+ ),
80
+ 0
81
+ )
82
+ self.assertEqual(
83
+ writer._sandbox_count.value(
84
+ app='test_app',
85
+ environment_id='testing-env',
86
+ image_id='test_image',
87
+ status='offline',
88
+ ),
89
+ 0
90
+ )
91
+ self.assertEqual(
92
+ writer._feature_setup.value(
93
+ app='test_app',
94
+ environment_id='testing-env',
95
+ image_id='test_image',
96
+ feature_name='test_feature1',
97
+ error='Success'
98
+ ),
99
+ 2,
100
+ )
101
+ self.assertEqual(
102
+ writer._feature_setup.value(
103
+ app='test_app',
104
+ environment_id='testing-env',
105
+ image_id='test_image',
106
+ feature_name='test_feature2',
107
+ error='Success'
108
+ ),
109
+ 2,
110
+ )
111
+ self.assertEqual(
112
+ writer._feature_setup_session.value(
113
+ app='test_app',
114
+ environment_id='testing-env',
115
+ image_id='test_image',
116
+ feature_name='test_feature1',
117
+ error='Success'
118
+ ),
119
+ 3,
120
+ )
121
+ self.assertEqual(
122
+ writer._feature_setup_session.value(
123
+ app='test_app',
124
+ environment_id='testing-env',
125
+ image_id='test_image',
126
+ feature_name='test_feature2',
127
+ error='Success'
128
+ ),
129
+ 3,
130
+ )
131
+ self.assertEqual(
132
+ writer._feature_teardown_session.value(
133
+ app='test_app',
134
+ environment_id='testing-env',
135
+ image_id='test_image',
136
+ feature_name='test_feature1',
137
+ error='Success'
138
+ ),
139
+ 2,
140
+ )
141
+ self.assertEqual(
142
+ writer._feature_teardown_session.value(
143
+ app='test_app',
144
+ environment_id='testing-env',
145
+ image_id='test_image',
146
+ feature_name='test_feature2',
147
+ error='Success'
148
+ ),
149
+ 2,
150
+ )
151
+ self.assertEqual(
152
+ writer._feature_teardown.value(
153
+ app='test_app',
154
+ environment_id='testing-env',
155
+ image_id='test_image',
156
+ feature_name='test_feature1',
157
+ error='Success'
158
+ ),
159
+ 2,
160
+ )
161
+ self.assertEqual(
162
+ writer._feature_teardown.value(
163
+ app='test_app',
164
+ environment_id='testing-env',
165
+ image_id='test_image',
166
+ feature_name='test_feature2',
167
+ error='Success'
168
+ ),
169
+ 2,
170
+ )
171
+ self.assertGreater(
172
+ writer._feature_housekeep.value(
173
+ app='test_app',
174
+ environment_id='testing-env',
175
+ image_id='test_image',
176
+ feature_name='test_feature1',
177
+ error='Success'
178
+ ),
179
+ 0,
180
+ )
181
+ self.assertEqual(
182
+ writer._feature_housekeep.value(
183
+ app='test_app',
184
+ environment_id='testing-env',
185
+ image_id='test_image',
186
+ feature_name='test_feature2',
187
+ error='Success'
188
+ ),
189
+ 0,
190
+ )
191
+ self.assertEqual(
192
+ writer._sandbox_activity.value(
193
+ app='test_app',
194
+ environment_id='testing-env',
195
+ image_id='test_image',
196
+ activity='shell',
197
+ error='Success'
198
+ ),
199
+ 18
200
+ )
201
+ self.assertEqual(
202
+ writer._sandbox_activity.value(
203
+ app='test_app',
204
+ environment_id='testing-env',
205
+ image_id='test_image',
206
+ activity='shell',
207
+ error='RuntimeError'
208
+ ),
209
+ 1
210
+ )
211
+
212
+
213
+ if __name__ == '__main__':
214
+ unittest.main()