langfun 0.1.2.dev202509290805__py3-none-any.whl → 0.1.2.dev202510010805__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.
- langfun/core/llms/gemini.py +5 -0
- langfun/core/llms/rest.py +4 -0
- langfun/env/base_environment.py +99 -53
- langfun/env/base_feature.py +3 -2
- langfun/env/base_sandbox.py +34 -11
- langfun/env/base_test.py +140 -103
- langfun/env/event_handlers/__init__.py +2 -0
- langfun/env/event_handlers/base.py +88 -9
- langfun/env/event_handlers/event_logger.py +75 -15
- langfun/env/event_handlers/event_logger_test.py +15 -0
- langfun/env/event_handlers/metric_writer.py +607 -0
- langfun/env/event_handlers/metric_writer_test.py +170 -0
- langfun/env/test_utils.py +12 -6
- {langfun-0.1.2.dev202509290805.dist-info → langfun-0.1.2.dev202510010805.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202509290805.dist-info → langfun-0.1.2.dev202510010805.dist-info}/RECORD +18 -16
- {langfun-0.1.2.dev202509290805.dist-info → langfun-0.1.2.dev202510010805.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202509290805.dist-info → langfun-0.1.2.dev202510010805.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202509290805.dist-info → langfun-0.1.2.dev202510010805.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
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=0.0,
|
|
35
|
+
sandbox_keepalive_interval=1.0,
|
|
36
|
+
event_handlers=[writer],
|
|
37
|
+
)
|
|
38
|
+
with env:
|
|
39
|
+
with env.sandbox('session1') as sb:
|
|
40
|
+
self.assertEqual(sb.test_feature1.num_shell_calls(), 4)
|
|
41
|
+
|
|
42
|
+
with self.assertRaises(interface.SandboxStateError):
|
|
43
|
+
with env.sandbox('session2') as sb:
|
|
44
|
+
sb.shell('echo "bar"', raise_error=RuntimeError)
|
|
45
|
+
|
|
46
|
+
self.assertEqual(
|
|
47
|
+
writer._sandbox_start.value(
|
|
48
|
+
app='test_app',
|
|
49
|
+
environment_id='testing-env',
|
|
50
|
+
error=''
|
|
51
|
+
),
|
|
52
|
+
2
|
|
53
|
+
)
|
|
54
|
+
self.assertGreater(
|
|
55
|
+
writer._sandbox_housekeep.value(
|
|
56
|
+
app='test_app',
|
|
57
|
+
environment_id='testing-env',
|
|
58
|
+
error=''
|
|
59
|
+
),
|
|
60
|
+
0,
|
|
61
|
+
)
|
|
62
|
+
self.assertEqual(
|
|
63
|
+
writer._sandbox_shutdown.value(
|
|
64
|
+
app='test_app',
|
|
65
|
+
environment_id='testing-env',
|
|
66
|
+
error=''
|
|
67
|
+
),
|
|
68
|
+
2
|
|
69
|
+
)
|
|
70
|
+
self.assertEqual(
|
|
71
|
+
writer._feature_setup.value(
|
|
72
|
+
app='test_app',
|
|
73
|
+
environment_id='testing-env',
|
|
74
|
+
feature_name='test_feature1', error=''
|
|
75
|
+
),
|
|
76
|
+
2,
|
|
77
|
+
)
|
|
78
|
+
self.assertEqual(
|
|
79
|
+
writer._feature_setup.value(
|
|
80
|
+
app='test_app',
|
|
81
|
+
environment_id='testing-env',
|
|
82
|
+
feature_name='test_feature2', error=''
|
|
83
|
+
),
|
|
84
|
+
2,
|
|
85
|
+
)
|
|
86
|
+
self.assertEqual(
|
|
87
|
+
writer._feature_setup_session.value(
|
|
88
|
+
app='test_app',
|
|
89
|
+
environment_id='testing-env',
|
|
90
|
+
feature_name='test_feature1', error=''
|
|
91
|
+
),
|
|
92
|
+
3,
|
|
93
|
+
)
|
|
94
|
+
self.assertEqual(
|
|
95
|
+
writer._feature_setup_session.value(
|
|
96
|
+
app='test_app',
|
|
97
|
+
environment_id='testing-env',
|
|
98
|
+
feature_name='test_feature2', error=''
|
|
99
|
+
),
|
|
100
|
+
3,
|
|
101
|
+
)
|
|
102
|
+
self.assertEqual(
|
|
103
|
+
writer._feature_teardown_session.value(
|
|
104
|
+
app='test_app',
|
|
105
|
+
environment_id='testing-env',
|
|
106
|
+
feature_name='test_feature1', error=''
|
|
107
|
+
),
|
|
108
|
+
2,
|
|
109
|
+
)
|
|
110
|
+
self.assertEqual(
|
|
111
|
+
writer._feature_teardown_session.value(
|
|
112
|
+
app='test_app',
|
|
113
|
+
environment_id='testing-env',
|
|
114
|
+
feature_name='test_feature2', error=''
|
|
115
|
+
),
|
|
116
|
+
2,
|
|
117
|
+
)
|
|
118
|
+
self.assertEqual(
|
|
119
|
+
writer._feature_teardown.value(
|
|
120
|
+
app='test_app',
|
|
121
|
+
environment_id='testing-env',
|
|
122
|
+
feature_name='test_feature1', error=''
|
|
123
|
+
),
|
|
124
|
+
2,
|
|
125
|
+
)
|
|
126
|
+
self.assertEqual(
|
|
127
|
+
writer._feature_teardown.value(
|
|
128
|
+
app='test_app',
|
|
129
|
+
environment_id='testing-env',
|
|
130
|
+
feature_name='test_feature2', error=''
|
|
131
|
+
),
|
|
132
|
+
2,
|
|
133
|
+
)
|
|
134
|
+
self.assertGreater(
|
|
135
|
+
writer._feature_housekeep.value(
|
|
136
|
+
app='test_app',
|
|
137
|
+
environment_id='testing-env',
|
|
138
|
+
feature_name='test_feature1', error=''
|
|
139
|
+
),
|
|
140
|
+
0,
|
|
141
|
+
)
|
|
142
|
+
self.assertEqual(
|
|
143
|
+
writer._feature_housekeep.value(
|
|
144
|
+
app='test_app',
|
|
145
|
+
environment_id='testing-env',
|
|
146
|
+
feature_name='test_feature2', error=''
|
|
147
|
+
),
|
|
148
|
+
0,
|
|
149
|
+
)
|
|
150
|
+
self.assertEqual(
|
|
151
|
+
writer._sandbox_activity.value(
|
|
152
|
+
app='test_app',
|
|
153
|
+
environment_id='testing-env',
|
|
154
|
+
activity='shell', error=''
|
|
155
|
+
),
|
|
156
|
+
18
|
|
157
|
+
)
|
|
158
|
+
self.assertEqual(
|
|
159
|
+
writer._sandbox_activity.value(
|
|
160
|
+
app='test_app',
|
|
161
|
+
environment_id='testing-env',
|
|
162
|
+
activity='shell',
|
|
163
|
+
error='RuntimeError'
|
|
164
|
+
),
|
|
165
|
+
1
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
if __name__ == '__main__':
|
|
170
|
+
unittest.main()
|
langfun/env/test_utils.py
CHANGED
|
@@ -258,7 +258,8 @@ class TestingEventHandler(
|
|
|
258
258
|
environment: interface.Environment,
|
|
259
259
|
counter: int,
|
|
260
260
|
duration: float,
|
|
261
|
-
error: BaseException | None
|
|
261
|
+
error: BaseException | None,
|
|
262
|
+
**kwargs
|
|
262
263
|
) -> None:
|
|
263
264
|
"""Called when the environment finishes a round of housekeeping."""
|
|
264
265
|
assert duration > 0
|
|
@@ -270,11 +271,12 @@ class TestingEventHandler(
|
|
|
270
271
|
def on_environment_shutdown(
|
|
271
272
|
self,
|
|
272
273
|
environment: interface.Environment,
|
|
274
|
+
duration: float,
|
|
273
275
|
lifetime: float,
|
|
274
276
|
error: BaseException | None
|
|
275
277
|
) -> None:
|
|
276
278
|
"""Called when the environment is shutdown."""
|
|
277
|
-
assert lifetime is not None
|
|
279
|
+
assert duration > 0 and lifetime is not None
|
|
278
280
|
self._add_message(f'[{environment.id}] environment shutdown', error)
|
|
279
281
|
|
|
280
282
|
def on_sandbox_start(
|
|
@@ -306,10 +308,11 @@ class TestingEventHandler(
|
|
|
306
308
|
self,
|
|
307
309
|
environment: interface.Environment,
|
|
308
310
|
sandbox: interface.Sandbox,
|
|
311
|
+
duration: float,
|
|
309
312
|
lifetime: float,
|
|
310
313
|
error: BaseException | None
|
|
311
314
|
) -> None:
|
|
312
|
-
assert lifetime is not None
|
|
315
|
+
assert duration > 0 and lifetime is not None
|
|
313
316
|
self._add_message(f'[{sandbox.id}] sandbox shutdown', error)
|
|
314
317
|
|
|
315
318
|
def on_sandbox_housekeep(
|
|
@@ -318,7 +321,8 @@ class TestingEventHandler(
|
|
|
318
321
|
sandbox: interface.Sandbox,
|
|
319
322
|
counter: int,
|
|
320
323
|
duration: float,
|
|
321
|
-
error: BaseException | None
|
|
324
|
+
error: BaseException | None,
|
|
325
|
+
**kwargs
|
|
322
326
|
) -> None:
|
|
323
327
|
assert duration > 0
|
|
324
328
|
if self.log_housekeep:
|
|
@@ -395,7 +399,8 @@ class TestingEventHandler(
|
|
|
395
399
|
feature: interface.Feature,
|
|
396
400
|
counter: int,
|
|
397
401
|
duration: float,
|
|
398
|
-
error: BaseException | None
|
|
402
|
+
error: BaseException | None,
|
|
403
|
+
**kwargs
|
|
399
404
|
) -> None:
|
|
400
405
|
"""Called when a sandbox feature is housekeeping."""
|
|
401
406
|
assert duration > 0
|
|
@@ -423,11 +428,12 @@ class TestingEventHandler(
|
|
|
423
428
|
environment: interface.Environment,
|
|
424
429
|
sandbox: interface.Sandbox,
|
|
425
430
|
session_id: str,
|
|
431
|
+
duration: float,
|
|
426
432
|
lifetime: float,
|
|
427
433
|
error: BaseException | None
|
|
428
434
|
) -> None:
|
|
429
435
|
"""Called when a sandbox session ends."""
|
|
430
|
-
assert lifetime > 0
|
|
436
|
+
assert duration > 0 and lifetime > 0
|
|
431
437
|
self._add_message(
|
|
432
438
|
f'[{sandbox.id}] session {session_id!r} ended', error
|
|
433
439
|
)
|
|
@@ -101,7 +101,7 @@ langfun/core/llms/deepseek.py,sha256=jvTxdXPr-vH6HNakn_Ootx1heDg8Fen2FUkUW36bpCs
|
|
|
101
101
|
langfun/core/llms/deepseek_test.py,sha256=DvROWPlDuow5E1lfoSkhyGt_ELA19JoQoDsTnRgDtTg,1847
|
|
102
102
|
langfun/core/llms/fake.py,sha256=bDk_4u7V2LmYUotyOaicwzi0-lnWOIIBbR3-Bil1P3o,3481
|
|
103
103
|
langfun/core/llms/fake_test.py,sha256=lC-C2TpEsnf2kmZpa3OiH2H944I4hMWTAaHEXzRj1DU,7855
|
|
104
|
-
langfun/core/llms/gemini.py,sha256=
|
|
104
|
+
langfun/core/llms/gemini.py,sha256=qR_rBdkFO6z9MRFoXhq3jiJjKo1tFi4yLkcD2wXzJlY,30337
|
|
105
105
|
langfun/core/llms/gemini_test.py,sha256=y1s0W65SrdepbZxzgIeoTB2MI7sXnfBDf1NsGn57LbM,7617
|
|
106
106
|
langfun/core/llms/google_genai.py,sha256=ogyoOUK4s1OcSFKun0YK5xBRDVyxmvz9WsYNKAwuB0g,5918
|
|
107
107
|
langfun/core/llms/google_genai_test.py,sha256=NKNtpebArQ9ZR7Qsnhd2prFIpMjleojy6o6VMXkJ1zY,1502
|
|
@@ -113,7 +113,7 @@ langfun/core/llms/openai.py,sha256=UZM0j3BHRz5NVLs8q7YYRkneM1CwuGQSt7sFaM4IAPU,4
|
|
|
113
113
|
langfun/core/llms/openai_compatible.py,sha256=JlFUTiK4e3ox2DGeGBcAD-cXkxmBdx5g6LrYkyMIaps,5777
|
|
114
114
|
langfun/core/llms/openai_compatible_test.py,sha256=KwOMA7tsmOxFBjezltkBDSU77AvOQkI23dO2nHLAlB4,17689
|
|
115
115
|
langfun/core/llms/openai_test.py,sha256=gwuO6aoa296iM2welWV9ua4KF8gEVGsEPakgbtkWkFQ,2687
|
|
116
|
-
langfun/core/llms/rest.py,sha256=
|
|
116
|
+
langfun/core/llms/rest.py,sha256=YXzSjr7YgtZ5zKDgjA-3D-sabo5wTjpLQDHUIcEPPgg,4773
|
|
117
117
|
langfun/core/llms/rest_test.py,sha256=_zM7nV8DEVyoXNiQOnuwJ917mWjki0614H88rNmDboE,5020
|
|
118
118
|
langfun/core/llms/vertexai.py,sha256=M0GySUbTukyfc6Pwo7i6AX4uapYyshY49VfPsTU8xac,20245
|
|
119
119
|
langfun/core/llms/vertexai_test.py,sha256=_e-acnNBAf9C3WO6i1b2J_mhRzdDdYQTorD9hIVZKOg,5034
|
|
@@ -166,21 +166,23 @@ langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3AB
|
|
|
166
166
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
|
167
167
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
|
168
168
|
langfun/env/__init__.py,sha256=m6Y8y16ms9lytvO_r-Br8HmTp2rNDhb3R6JJaH5dEEk,1491
|
|
169
|
-
langfun/env/base_environment.py,sha256=
|
|
170
|
-
langfun/env/base_feature.py,sha256=
|
|
171
|
-
langfun/env/base_sandbox.py,sha256=
|
|
172
|
-
langfun/env/base_test.py,sha256=
|
|
169
|
+
langfun/env/base_environment.py,sha256=m7IJNHqt4dlgBRwv0E8BxKtARvcNJis9FrrALguzX1E,19472
|
|
170
|
+
langfun/env/base_feature.py,sha256=gGUCWLcSaQZ7MoXNKogXEdcpfoqJxcfnoXhWQjqi8jk,6462
|
|
171
|
+
langfun/env/base_sandbox.py,sha256=6AqTvMf9U-Gl8fQ_o7lPkHgcOnBLWcORnasr_D9EcF8,37263
|
|
172
|
+
langfun/env/base_test.py,sha256=DrBtyweO4v8Fz3Oz-gnpJ4W_9hRhuVXA1CTLvXJDa9s,61099
|
|
173
173
|
langfun/env/interface.py,sha256=2Amf-_op7dGRF8c4-wYxcFxs1UCBYz1AB20Lk7__V4E,25724
|
|
174
174
|
langfun/env/interface_test.py,sha256=hfQn4RRTEo1YfVHXTPzH1puzD14BTo8R_5v1IpXVZ90,1398
|
|
175
175
|
langfun/env/load_balancers.py,sha256=qRhCthqzjZIQBwta8qC1C0s0J-VQAVomJQqI7Nqv-r4,1948
|
|
176
176
|
langfun/env/load_balancers_test.py,sha256=KIDIwZeQHcW0fCL5ScZD0lm0QV4_X2y-rMqdd6R1gLc,3737
|
|
177
|
-
langfun/env/test_utils.py,sha256=
|
|
178
|
-
langfun/env/event_handlers/__init__.py,sha256=
|
|
179
|
-
langfun/env/event_handlers/base.py,sha256=
|
|
180
|
-
langfun/env/event_handlers/event_logger.py,sha256=
|
|
181
|
-
langfun/env/event_handlers/event_logger_test.py,sha256=
|
|
182
|
-
langfun
|
|
183
|
-
langfun
|
|
184
|
-
langfun-0.1.2.
|
|
185
|
-
langfun-0.1.2.
|
|
186
|
-
langfun-0.1.2.
|
|
177
|
+
langfun/env/test_utils.py,sha256=rnIQZ2ZpiFuB7yfl5ckGtacBoySAwguzBzXzqhyo8jw,14042
|
|
178
|
+
langfun/env/event_handlers/__init__.py,sha256=H34n-TbKSgtxqBhE-yAti8fY6weF2_v3yw59M9_zmGM,443
|
|
179
|
+
langfun/env/event_handlers/base.py,sha256=eGdJ6N5em9kX-c9wzm1TdnRP5_5IAltX5JTHILdjzLM,10124
|
|
180
|
+
langfun/env/event_handlers/event_logger.py,sha256=3dbPjBe53dBgntYHlyLlj_77hVecPSXkmKeiGXMxlO0,12699
|
|
181
|
+
langfun/env/event_handlers/event_logger_test.py,sha256=PGof3rPllNnyzs3Yp8kaOHLeTkVrzUgCJwlODTrVRKI,9111
|
|
182
|
+
langfun/env/event_handlers/metric_writer.py,sha256=cnJe0BeWntUZ56NlwB8lkv2udcldds9GNyMg71Zz-II,16994
|
|
183
|
+
langfun/env/event_handlers/metric_writer_test.py,sha256=4tI7s3o1Gw1bawXewaEZ65EPPOcr8A4m1bLK7uUcJY4,4735
|
|
184
|
+
langfun-0.1.2.dev202510010805.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
185
|
+
langfun-0.1.2.dev202510010805.dist-info/METADATA,sha256=RzMf3Out519JCUoptVdAxzqmPL2j-we1L2YNLuu9Yf4,7380
|
|
186
|
+
langfun-0.1.2.dev202510010805.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
187
|
+
langfun-0.1.2.dev202510010805.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
|
188
|
+
langfun-0.1.2.dev202510010805.dist-info/RECORD,,
|
|
File without changes
|
{langfun-0.1.2.dev202509290805.dist-info → langfun-0.1.2.dev202510010805.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{langfun-0.1.2.dev202509290805.dist-info → langfun-0.1.2.dev202510010805.dist-info}/top_level.txt
RENAMED
|
File without changes
|