langfun 0.1.2.dev202511010804__py3-none-any.whl → 0.1.2.dev202511020804__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/eval/v2/runners_test.py +3 -0
- langfun/env/__init__.py +1 -1
- langfun/env/base_environment.py +62 -5
- langfun/env/base_environment_test.py +5 -5
- langfun/env/base_feature.py +38 -20
- langfun/env/base_feature_test.py +228 -0
- langfun/env/base_sandbox.py +27 -33
- langfun/env/base_sandbox_test.py +258 -251
- langfun/env/event_handlers/chain.py +58 -80
- langfun/env/event_handlers/chain_test.py +83 -111
- langfun/env/event_handlers/event_logger.py +77 -80
- langfun/env/event_handlers/event_logger_test.py +18 -18
- langfun/env/event_handlers/metric_writer.py +176 -140
- langfun/env/interface.py +493 -199
- langfun/env/interface_test.py +30 -1
- langfun/env/test_utils.py +110 -78
- {langfun-0.1.2.dev202511010804.dist-info → langfun-0.1.2.dev202511020804.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202511010804.dist-info → langfun-0.1.2.dev202511020804.dist-info}/RECORD +21 -20
- {langfun-0.1.2.dev202511010804.dist-info → langfun-0.1.2.dev202511020804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202511010804.dist-info → langfun-0.1.2.dev202511020804.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202511010804.dist-info → langfun-0.1.2.dev202511020804.dist-info}/top_level.txt +0 -0
|
@@ -210,7 +210,6 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
210
210
|
|
|
211
211
|
def on_sandbox_start(
|
|
212
212
|
self,
|
|
213
|
-
environment: interface.Environment,
|
|
214
213
|
sandbox: interface.Sandbox,
|
|
215
214
|
duration: float,
|
|
216
215
|
error: BaseException | None
|
|
@@ -226,7 +225,6 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
226
225
|
|
|
227
226
|
def on_sandbox_status_change(
|
|
228
227
|
self,
|
|
229
|
-
environment: interface.Environment,
|
|
230
228
|
sandbox: interface.Sandbox,
|
|
231
229
|
old_status: interface.Sandbox.Status,
|
|
232
230
|
new_status: interface.Sandbox.Status,
|
|
@@ -242,7 +240,6 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
242
240
|
|
|
243
241
|
def on_sandbox_shutdown(
|
|
244
242
|
self,
|
|
245
|
-
environment: interface.Environment,
|
|
246
243
|
sandbox: interface.Sandbox,
|
|
247
244
|
duration: float,
|
|
248
245
|
lifetime: float,
|
|
@@ -258,9 +255,61 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
258
255
|
styles=['bold'],
|
|
259
256
|
)
|
|
260
257
|
|
|
258
|
+
def on_sandbox_session_start(
|
|
259
|
+
self,
|
|
260
|
+
sandbox: interface.Sandbox,
|
|
261
|
+
session_id: str,
|
|
262
|
+
duration: float,
|
|
263
|
+
error: BaseException | None
|
|
264
|
+
) -> None:
|
|
265
|
+
"""Called when a sandbox session starts."""
|
|
266
|
+
if self.session_status:
|
|
267
|
+
self._print(
|
|
268
|
+
f'[{sandbox.id}@{session_id}] sandbox session started '
|
|
269
|
+
f'(duration={duration:.2f} seconds)',
|
|
270
|
+
error=error,
|
|
271
|
+
color='blue',
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
def on_sandbox_session_end(
|
|
275
|
+
self,
|
|
276
|
+
sandbox: interface.Sandbox,
|
|
277
|
+
session_id: str,
|
|
278
|
+
duration: float,
|
|
279
|
+
lifetime: float,
|
|
280
|
+
error: BaseException | None
|
|
281
|
+
) -> None:
|
|
282
|
+
"""Called when a sandbox session ends."""
|
|
283
|
+
if self.session_status:
|
|
284
|
+
self._print(
|
|
285
|
+
f'[{sandbox.id}@{session_id}] sandbox session ended '
|
|
286
|
+
f'(duration={duration:.2f} seconds), '
|
|
287
|
+
f'lifetime={lifetime:.2f} seconds)',
|
|
288
|
+
error=error,
|
|
289
|
+
color='blue',
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
def on_sandbox_activity(
|
|
293
|
+
self,
|
|
294
|
+
name: str,
|
|
295
|
+
sandbox: interface.Sandbox,
|
|
296
|
+
session_id: str | None,
|
|
297
|
+
duration: float,
|
|
298
|
+
error: BaseException | None,
|
|
299
|
+
**kwargs
|
|
300
|
+
) -> None:
|
|
301
|
+
"""Called when a sandbox activity is performed."""
|
|
302
|
+
log_id = f'{sandbox.id}@{session_id or "<idle>"}'
|
|
303
|
+
color = 'yellow' if session_id is None else 'cyan'
|
|
304
|
+
self._print(
|
|
305
|
+
f'[{log_id}] sandbox call {name!r} '
|
|
306
|
+
f'(duration={duration:.2f} seconds, kwargs={kwargs}) ',
|
|
307
|
+
error,
|
|
308
|
+
color=color
|
|
309
|
+
)
|
|
310
|
+
|
|
261
311
|
def on_sandbox_housekeep(
|
|
262
312
|
self,
|
|
263
|
-
environment: interface.Environment,
|
|
264
313
|
sandbox: interface.Sandbox,
|
|
265
314
|
counter: int,
|
|
266
315
|
duration: float,
|
|
@@ -279,8 +328,6 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
279
328
|
|
|
280
329
|
def on_feature_setup(
|
|
281
330
|
self,
|
|
282
|
-
environment: interface.Environment,
|
|
283
|
-
sandbox: interface.Sandbox,
|
|
284
331
|
feature: interface.Feature,
|
|
285
332
|
duration: float,
|
|
286
333
|
error: BaseException | None
|
|
@@ -288,7 +335,7 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
288
335
|
"""Called when a sandbox feature is setup."""
|
|
289
336
|
if self.feature_status:
|
|
290
337
|
self._print(
|
|
291
|
-
f'[{
|
|
338
|
+
f'[{feature.id}] feature setup complete '
|
|
292
339
|
f'(duration={duration:.2f} seconds)',
|
|
293
340
|
error=error,
|
|
294
341
|
color='white',
|
|
@@ -296,8 +343,6 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
296
343
|
|
|
297
344
|
def on_feature_teardown(
|
|
298
345
|
self,
|
|
299
|
-
environment: interface.Environment,
|
|
300
|
-
sandbox: interface.Sandbox,
|
|
301
346
|
feature: interface.Feature,
|
|
302
347
|
duration: float,
|
|
303
348
|
error: BaseException | None
|
|
@@ -305,7 +350,7 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
305
350
|
"""Called when a sandbox feature is teardown."""
|
|
306
351
|
if self.feature_status:
|
|
307
352
|
self._print(
|
|
308
|
-
f'[{
|
|
353
|
+
f'[{feature.id}] feature teardown complete '
|
|
309
354
|
f'(duration={duration:.2f} seconds)',
|
|
310
355
|
error=error,
|
|
311
356
|
color='white',
|
|
@@ -313,8 +358,6 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
313
358
|
|
|
314
359
|
def on_feature_setup_session(
|
|
315
360
|
self,
|
|
316
|
-
environment: interface.Environment,
|
|
317
|
-
sandbox: interface.Sandbox,
|
|
318
361
|
feature: interface.Feature,
|
|
319
362
|
session_id: str | None,
|
|
320
363
|
duration: float,
|
|
@@ -323,7 +366,7 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
323
366
|
"""Called when a sandbox feature is setup."""
|
|
324
367
|
if self.feature_status:
|
|
325
368
|
self._print(
|
|
326
|
-
f'[{
|
|
369
|
+
f'[{feature.id}@{session_id or "<idle>"}] '
|
|
327
370
|
f'feature setup complete (duration={duration:.2f} seconds)',
|
|
328
371
|
error=error,
|
|
329
372
|
color='yellow',
|
|
@@ -331,8 +374,6 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
331
374
|
|
|
332
375
|
def on_feature_teardown_session(
|
|
333
376
|
self,
|
|
334
|
-
environment: interface.Environment,
|
|
335
|
-
sandbox: interface.Sandbox,
|
|
336
377
|
feature: interface.Feature,
|
|
337
378
|
session_id: str,
|
|
338
379
|
duration: float,
|
|
@@ -341,16 +382,33 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
341
382
|
"""Called when a sandbox feature is teardown."""
|
|
342
383
|
if self.feature_status:
|
|
343
384
|
self._print(
|
|
344
|
-
f'[{
|
|
385
|
+
f'[{feature.id}@{session_id}] '
|
|
345
386
|
f'feature teardown complete (duration={duration:.2f} seconds)',
|
|
346
387
|
error=error,
|
|
347
388
|
color='yellow',
|
|
348
389
|
)
|
|
349
390
|
|
|
391
|
+
def on_feature_activity(
|
|
392
|
+
self,
|
|
393
|
+
name: str,
|
|
394
|
+
feature: interface.Feature,
|
|
395
|
+
session_id: str | None,
|
|
396
|
+
duration: float,
|
|
397
|
+
error: BaseException | None,
|
|
398
|
+
**kwargs
|
|
399
|
+
) -> None:
|
|
400
|
+
"""Called when a feature activity is performed."""
|
|
401
|
+
log_id = f'{feature.id}@{session_id or "<idle>"}'
|
|
402
|
+
color = 'yellow' if session_id is None else 'cyan'
|
|
403
|
+
self._print(
|
|
404
|
+
f'[{log_id}] feature call {name!r} '
|
|
405
|
+
f'(duration={duration:.2f} seconds, kwargs={kwargs}) ',
|
|
406
|
+
error,
|
|
407
|
+
color=color
|
|
408
|
+
)
|
|
409
|
+
|
|
350
410
|
def on_feature_housekeep(
|
|
351
411
|
self,
|
|
352
|
-
environment: interface.Environment,
|
|
353
|
-
sandbox: interface.Sandbox,
|
|
354
412
|
feature: interface.Feature,
|
|
355
413
|
counter: int,
|
|
356
414
|
duration: float,
|
|
@@ -360,74 +418,13 @@ class EventLogger(pg.Object, interface.EventHandler):
|
|
|
360
418
|
"""Called when a sandbox feature is housekeeping."""
|
|
361
419
|
if self.feature_status and self.housekeep_status:
|
|
362
420
|
self._print(
|
|
363
|
-
f'[{
|
|
421
|
+
f'[{feature.id}] feature housekeeping complete '
|
|
364
422
|
f'(counter={counter}, (duration={duration:.2f} seconds, '
|
|
365
423
|
f'housekeep_info={kwargs})',
|
|
366
424
|
error=error,
|
|
367
425
|
color='white',
|
|
368
426
|
)
|
|
369
427
|
|
|
370
|
-
def on_session_start(
|
|
371
|
-
self,
|
|
372
|
-
environment: interface.Environment,
|
|
373
|
-
sandbox: interface.Sandbox,
|
|
374
|
-
session_id: str,
|
|
375
|
-
duration: float,
|
|
376
|
-
error: BaseException | None
|
|
377
|
-
) -> None:
|
|
378
|
-
"""Called when a sandbox session starts."""
|
|
379
|
-
if self.session_status:
|
|
380
|
-
self._print(
|
|
381
|
-
f'[{sandbox.id}/{session_id}] session started '
|
|
382
|
-
f'(duration={duration:.2f} seconds)',
|
|
383
|
-
error=error,
|
|
384
|
-
color='blue',
|
|
385
|
-
)
|
|
386
|
-
|
|
387
|
-
def on_session_end(
|
|
388
|
-
self,
|
|
389
|
-
environment: interface.Environment,
|
|
390
|
-
sandbox: interface.Sandbox,
|
|
391
|
-
session_id: str,
|
|
392
|
-
duration: float,
|
|
393
|
-
lifetime: float,
|
|
394
|
-
error: BaseException | None
|
|
395
|
-
) -> None:
|
|
396
|
-
"""Called when a sandbox session ends."""
|
|
397
|
-
if self.session_status:
|
|
398
|
-
self._print(
|
|
399
|
-
f'[{sandbox.id}/{session_id}] session ended '
|
|
400
|
-
f'(duration={duration:.2f} seconds), '
|
|
401
|
-
f'lifetime={lifetime:.2f} seconds)',
|
|
402
|
-
error=error,
|
|
403
|
-
color='blue',
|
|
404
|
-
)
|
|
405
|
-
|
|
406
|
-
def on_sandbox_activity(
|
|
407
|
-
self,
|
|
408
|
-
name: str,
|
|
409
|
-
environment: interface.Environment,
|
|
410
|
-
sandbox: interface.Sandbox,
|
|
411
|
-
feature: interface.Feature | None,
|
|
412
|
-
session_id: str | None,
|
|
413
|
-
duration: float,
|
|
414
|
-
error: BaseException | None,
|
|
415
|
-
**kwargs
|
|
416
|
-
) -> None:
|
|
417
|
-
"""Called when a sandbox activity is performed."""
|
|
418
|
-
del environment
|
|
419
|
-
log_id = f'{sandbox.id}/{session_id or "<idle>"}'
|
|
420
|
-
if feature is not None:
|
|
421
|
-
log_id = f'{log_id}/{feature.name}'
|
|
422
|
-
|
|
423
|
-
color = 'yellow' if session_id is None else 'cyan'
|
|
424
|
-
self._print(
|
|
425
|
-
f'[{log_id}] call {name!r} '
|
|
426
|
-
f'(duration={duration:.2f} seconds, kwargs={kwargs}) ',
|
|
427
|
-
error,
|
|
428
|
-
color=color
|
|
429
|
-
)
|
|
430
|
-
|
|
431
428
|
def _print(
|
|
432
429
|
self,
|
|
433
430
|
message: str,
|
|
@@ -104,9 +104,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
104
104
|
'feature setup complete',
|
|
105
105
|
'feature teardown complete',
|
|
106
106
|
'/test_feature1] feature housekeeping',
|
|
107
|
-
'session started',
|
|
108
|
-
'session ended',
|
|
109
|
-
'call \'shell\'',
|
|
107
|
+
'sandbox session started',
|
|
108
|
+
'sandbox session ended',
|
|
109
|
+
'sandbox call \'shell\'',
|
|
110
110
|
'RuntimeError',
|
|
111
111
|
],
|
|
112
112
|
unexpected_substrings=[
|
|
@@ -154,9 +154,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
154
154
|
'sandbox shutdown',
|
|
155
155
|
'feature setup complete',
|
|
156
156
|
'feature teardown complete',
|
|
157
|
-
'session started',
|
|
158
|
-
'session ended',
|
|
159
|
-
'call \'shell\'',
|
|
157
|
+
'sandbox session started',
|
|
158
|
+
'sandbox session ended',
|
|
159
|
+
'sandbox call \'shell\'',
|
|
160
160
|
'RuntimeError',
|
|
161
161
|
],
|
|
162
162
|
regex='.*environment.*',
|
|
@@ -174,9 +174,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
174
174
|
'feature setup complete',
|
|
175
175
|
'feature teardown complete',
|
|
176
176
|
'feature housekeeping',
|
|
177
|
-
'session started',
|
|
178
|
-
'session ended',
|
|
179
|
-
'call \'shell\'',
|
|
177
|
+
'sandbox session started',
|
|
178
|
+
'sandbox session ended',
|
|
179
|
+
'sandbox call \'shell\'',
|
|
180
180
|
'RuntimeError',
|
|
181
181
|
],
|
|
182
182
|
unexpected_substrings=[
|
|
@@ -202,9 +202,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
202
202
|
'-> acquired',
|
|
203
203
|
'sandbox shutdown',
|
|
204
204
|
'sandbox housekeeping',
|
|
205
|
-
'session started',
|
|
206
|
-
'session ended',
|
|
207
|
-
'call \'shell\'',
|
|
205
|
+
'sandbox session started',
|
|
206
|
+
'sandbox session ended',
|
|
207
|
+
'sandbox call \'shell\'',
|
|
208
208
|
'RuntimeError',
|
|
209
209
|
],
|
|
210
210
|
unexpected_substrings=[
|
|
@@ -232,12 +232,12 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
232
232
|
'feature setup complete',
|
|
233
233
|
'feature teardown complete',
|
|
234
234
|
'feature housekeeping',
|
|
235
|
-
'call \'shell\'',
|
|
235
|
+
'sandbox call \'shell\'',
|
|
236
236
|
'RuntimeError',
|
|
237
237
|
],
|
|
238
238
|
unexpected_substrings=[
|
|
239
|
-
'session started',
|
|
240
|
-
'session ended',
|
|
239
|
+
'sandbox session started',
|
|
240
|
+
'sandbox session ended',
|
|
241
241
|
],
|
|
242
242
|
session_status=False,
|
|
243
243
|
)
|
|
@@ -256,9 +256,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
256
256
|
'sandbox shutdown',
|
|
257
257
|
'feature setup complete',
|
|
258
258
|
'feature teardown complete',
|
|
259
|
-
'session started',
|
|
260
|
-
'session ended',
|
|
261
|
-
'call \'shell\'',
|
|
259
|
+
'sandbox session started',
|
|
260
|
+
'sandbox session ended',
|
|
261
|
+
'sandbox call \'shell\'',
|
|
262
262
|
'RuntimeError',
|
|
263
263
|
],
|
|
264
264
|
unexpected_substrings=[
|