langfun 0.1.2.dev202505070805__py3-none-any.whl → 0.1.2.dev202505090804__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.
- langfun/core/eval/v2/experiment.py +12 -0
- langfun/core/eval/v2/runners.py +3 -0
- langfun/core/eval/v2/runners_test.py +9 -0
- langfun/core/structured/querying.py +23 -6
- langfun/core/structured/querying_test.py +20 -0
- {langfun-0.1.2.dev202505070805.dist-info → langfun-0.1.2.dev202505090804.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202505070805.dist-info → langfun-0.1.2.dev202505090804.dist-info}/RECORD +10 -10
- {langfun-0.1.2.dev202505070805.dist-info → langfun-0.1.2.dev202505090804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202505070805.dist-info → langfun-0.1.2.dev202505090804.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202505070805.dist-info → langfun-0.1.2.dev202505090804.dist-info}/top_level.txt +0 -0
@@ -382,6 +382,7 @@ class Experiment(lf.Component, pg.views.HtmlTreeView.Extension):
|
|
382
382
|
warm_start_from: str | None = None,
|
383
383
|
filter: Callable[['Experiment'], bool] | None = None, # pylint: disable=redefined-builtin
|
384
384
|
example_ids: list[int] | None = None,
|
385
|
+
shuffle_inputs: bool = False,
|
385
386
|
raise_if_has_error: bool = False,
|
386
387
|
reprocess: bool | list[int] = False,
|
387
388
|
generate_example_html: Literal['new', 'all', 'no'] | list[int] = 'new',
|
@@ -431,6 +432,8 @@ class Experiment(lf.Component, pg.views.HtmlTreeView.Extension):
|
|
431
432
|
filter: A filter function to decide whether an experiment should be run
|
432
433
|
or not.
|
433
434
|
example_ids: The example IDs to run. If None, it will run all examples.
|
435
|
+
shuffle_inputs: If True, the order of evaluatin examples will be shuffled.
|
436
|
+
Neverthless, the example ID remains unchanged for each example.
|
434
437
|
raise_if_has_error: If True, it will raise an error if any example fails.
|
435
438
|
Otherwise, it will continue and report the error in the output.
|
436
439
|
reprocess: A boolean or a list of example IDs. If boolean, it indicates
|
@@ -470,6 +473,7 @@ class Experiment(lf.Component, pg.views.HtmlTreeView.Extension):
|
|
470
473
|
warm_start_from=warm_start_from,
|
471
474
|
filter=filter,
|
472
475
|
example_ids=example_ids,
|
476
|
+
shuffle_inputs=shuffle_inputs,
|
473
477
|
raise_if_has_error=raise_if_has_error,
|
474
478
|
reprocess=reprocess,
|
475
479
|
generate_example_html=generate_example_html,
|
@@ -816,6 +820,14 @@ class Run(pg.Object, pg.views.html.HtmlTreeView.Extension):
|
|
816
820
|
)
|
817
821
|
] = None
|
818
822
|
|
823
|
+
shuffle_inputs: Annotated[
|
824
|
+
bool,
|
825
|
+
(
|
826
|
+
'If True, the order of evaluating examples will be shuffled.'
|
827
|
+
'Otherwise an increasing order will be used.'
|
828
|
+
)
|
829
|
+
] = False
|
830
|
+
|
819
831
|
raise_if_has_error: Annotated[
|
820
832
|
bool,
|
821
833
|
(
|
langfun/core/eval/v2/runners.py
CHANGED
@@ -356,6 +356,9 @@ class RunnerBase(Runner):
|
|
356
356
|
input=evaluation.example_input_by_id(example_id)
|
357
357
|
) for example_id in self.current_run.example_ids
|
358
358
|
)
|
359
|
+
if self.current_run.shuffle_inputs:
|
360
|
+
items = list(items)
|
361
|
+
random.shuffle(items)
|
359
362
|
self._evaluate_items(evaluation, items)
|
360
363
|
|
361
364
|
if cache:
|
@@ -163,6 +163,15 @@ class RunnerTest(unittest.TestCase):
|
|
163
163
|
self.assertEqual(plugin.started_example_ids, [5, 7, 9] * 6)
|
164
164
|
self.assertEqual(plugin.completed_example_ids, [5, 7, 9] * 6)
|
165
165
|
|
166
|
+
def test_shuffle_inputs(self):
|
167
|
+
root_dir = os.path.join(tempfile.gettempdir(), 'test_shuffle_inputs')
|
168
|
+
exp = eval_test_helper.test_experiment()
|
169
|
+
plugin = TestPlugin()
|
170
|
+
run = exp.run(
|
171
|
+
root_dir, runner='sequential', plugins=[plugin], shuffle_inputs=True
|
172
|
+
)
|
173
|
+
self.assertTrue(run.shuffle_inputs)
|
174
|
+
|
166
175
|
def test_filter(self):
|
167
176
|
plugin = TestPlugin()
|
168
177
|
exp = eval_test_helper.test_experiment()
|
@@ -325,7 +325,7 @@ def query(
|
|
325
325
|
|
326
326
|
```
|
327
327
|
lf.query('1 + 1 = ?', int, lm=lf.llms.Gpt4Turbo())
|
328
|
-
|
328
|
+
|
329
329
|
# Output: 2
|
330
330
|
```
|
331
331
|
|
@@ -349,7 +349,7 @@ def query(
|
|
349
349
|
|
350
350
|
class Dog(Animal):
|
351
351
|
pass
|
352
|
-
|
352
|
+
|
353
353
|
class Entity(pg.Object):
|
354
354
|
name: str
|
355
355
|
|
@@ -562,7 +562,10 @@ def query(
|
|
562
562
|
output_message = lf.AIMessage(processed_text, source=output_message)
|
563
563
|
else:
|
564
564
|
# Query with structured output.
|
565
|
-
|
565
|
+
query_cls = LfQuery.from_protocol(protocol)
|
566
|
+
if ':' not in protocol:
|
567
|
+
protocol = f'{protocol}:{query_cls.version}'
|
568
|
+
output_message = query_cls(
|
566
569
|
input=(
|
567
570
|
query_input.render(lm=lm)
|
568
571
|
if isinstance(query_input, lf.Template)
|
@@ -572,7 +575,7 @@ def query(
|
|
572
575
|
default=default,
|
573
576
|
examples=examples,
|
574
577
|
response_postprocess=response_postprocess,
|
575
|
-
autofix=autofix if protocol
|
578
|
+
autofix=autofix if protocol.startswith('python:') else 0,
|
576
579
|
**kwargs,
|
577
580
|
)(
|
578
581
|
lm=lm,
|
@@ -605,6 +608,8 @@ def query(
|
|
605
608
|
),
|
606
609
|
lm=pg.Ref(lm),
|
607
610
|
examples=pg.Ref(examples) if examples else [],
|
611
|
+
protocol=protocol,
|
612
|
+
kwargs={k: pg.Ref(v) for k, v in kwargs.items()},
|
608
613
|
lm_response=lf.AIMessage(output_message.text, metadata=metadata),
|
609
614
|
usage_summary=usage_summary,
|
610
615
|
start_time=start_time,
|
@@ -788,6 +793,14 @@ class QueryInvocation(pg.Object, pg.views.HtmlTreeView.Extension):
|
|
788
793
|
list[mapping.MappingExample],
|
789
794
|
'Fewshot exemplars for `lf.query`.'
|
790
795
|
]
|
796
|
+
protocol: Annotated[
|
797
|
+
str,
|
798
|
+
'Protocol of `lf.query`.'
|
799
|
+
] = 'python'
|
800
|
+
kwargs: Annotated[
|
801
|
+
dict[str, Any],
|
802
|
+
'Kwargs of `lf.query`.'
|
803
|
+
] = {}
|
791
804
|
usage_summary: Annotated[
|
792
805
|
lf.UsageSummary,
|
793
806
|
'Usage summary for `lf.query`.'
|
@@ -803,13 +816,17 @@ class QueryInvocation(pg.Object, pg.views.HtmlTreeView.Extension):
|
|
803
816
|
|
804
817
|
@functools.cached_property
|
805
818
|
def lm_request(self) -> lf.Message:
|
806
|
-
return query_prompt(
|
819
|
+
return query_prompt(
|
820
|
+
self.input, self.schema, examples=self.examples or None,
|
821
|
+
protocol=self.protocol,
|
822
|
+
**self.kwargs
|
823
|
+
)
|
807
824
|
|
808
825
|
@functools.cached_property
|
809
826
|
def output(self) -> Any:
|
810
827
|
"""The output of `lf.query`. If it failed, returns the `MappingError`."""
|
811
828
|
try:
|
812
|
-
return query_output(self.lm_response, self.schema)
|
829
|
+
return query_output(self.lm_response, self.schema, protocol=self.protocol)
|
813
830
|
except mapping.MappingError as e:
|
814
831
|
return e
|
815
832
|
|
@@ -1321,6 +1321,26 @@ class QueryInvocationTest(unittest.TestCase):
|
|
1321
1321
|
self.assertTrue(queries[0].has_error)
|
1322
1322
|
self.assertIsInstance(queries[0].output, mapping.MappingError)
|
1323
1323
|
|
1324
|
+
def test_kwargs(self):
|
1325
|
+
lm = fake.StaticSequence([
|
1326
|
+
'Activity(description="hi")',
|
1327
|
+
])
|
1328
|
+
with querying.track_queries() as queries:
|
1329
|
+
querying.query(
|
1330
|
+
'foo {{x}}',
|
1331
|
+
Activity,
|
1332
|
+
lm=lm,
|
1333
|
+
system_message='system message',
|
1334
|
+
x=1,
|
1335
|
+
)
|
1336
|
+
self.assertTrue(queries[0].protocol.startswith('python:'))
|
1337
|
+
self.assertEqual(
|
1338
|
+
list(queries[0].kwargs.keys()),
|
1339
|
+
['x', 'metadata_system_message']
|
1340
|
+
)
|
1341
|
+
self.assertIn('foo 1', queries[0].lm_request.text)
|
1342
|
+
self.assertEqual(queries[0].lm_request.system_message, 'system message')
|
1343
|
+
|
1324
1344
|
def test_to_html(self):
|
1325
1345
|
lm = fake.StaticSequence([
|
1326
1346
|
'Activity(description="hi")',
|
@@ -67,7 +67,7 @@ langfun/core/eval/v2/evaluation.py,sha256=BijbrYufnlRZLryxezDU32gHjFCCZvLAZMLF6k
|
|
67
67
|
langfun/core/eval/v2/evaluation_test.py,sha256=QNp_HEvRTupvNuLEeYTvylykh1Ut2jpMqHQ-gCUZQ10,6919
|
68
68
|
langfun/core/eval/v2/example.py,sha256=Jegt-viQSNYzPVkOZE_M19GON2TYGTct4Cp9HnJ7DGo,10861
|
69
69
|
langfun/core/eval/v2/example_test.py,sha256=1DNm6EuyZOq827DKvf3oTRVFkMNM_qTnLUpvOjpgz5I,3419
|
70
|
-
langfun/core/eval/v2/experiment.py,sha256=
|
70
|
+
langfun/core/eval/v2/experiment.py,sha256=fb3RHNOSRftV7ZTBfYVV50iEevqdPwRHCt3mgtLzuFw,33408
|
71
71
|
langfun/core/eval/v2/experiment_test.py,sha256=UmCobeS6ifPcaGkTJp0WPISolXrVFbeFCBiyJeA0Lt4,13666
|
72
72
|
langfun/core/eval/v2/metric_values.py,sha256=_B905bC-jxrYPLSEcP2M8MaHZOVMz_bVrUw8YC4arCE,4660
|
73
73
|
langfun/core/eval/v2/metric_values_test.py,sha256=ab2oF_HsIwrSy459108ggyjgefHSPn8UVILR4dRwx14,2634
|
@@ -79,8 +79,8 @@ langfun/core/eval/v2/progress_tracking.py,sha256=zNhNPGlnJnHELEfFpbTMCSXFn8d1IJ5
|
|
79
79
|
langfun/core/eval/v2/progress_tracking_test.py,sha256=fouMVJkFJqHjbhQJngGLGCmA9x3n0dU4USI2dY163mg,2291
|
80
80
|
langfun/core/eval/v2/reporting.py,sha256=yUIPCAMnp7InIzpv1DDWrcLO-75iiOUTpscj7smkfrA,8335
|
81
81
|
langfun/core/eval/v2/reporting_test.py,sha256=hcPJJaMtPulqERvHYTpId83WXdqDKnnexmULtK7WKwk,5686
|
82
|
-
langfun/core/eval/v2/runners.py,sha256=
|
83
|
-
langfun/core/eval/v2/runners_test.py,sha256=
|
82
|
+
langfun/core/eval/v2/runners.py,sha256=iqbH4jMtnNMhfuv1eHaxJmk1Vvsrz-sAJJFP8U44-tA,16758
|
83
|
+
langfun/core/eval/v2/runners_test.py,sha256=DO3xV0sBNB6n65j41xx2i7gqUCJcPF37DFZLEjrmISg,11987
|
84
84
|
langfun/core/llms/__init__.py,sha256=QWxRhzVn_vgJvdmW_xs5PcPuDbHsUxTU94YyV4Ofl34,8684
|
85
85
|
langfun/core/llms/anthropic.py,sha256=qaclpfX3qeHoZMDxU3Gn-638Vi4IyCbxdow3zgGUHK4,22195
|
86
86
|
langfun/core/llms/anthropic_test.py,sha256=dFnNvrgwCYUseDuiuWCBoQ5jloYX9RIlZQf7cCLPNU4,8282
|
@@ -137,8 +137,8 @@ langfun/core/structured/mapping.py,sha256=gxdcYQP9yqbDRtiJQ1RRAOrKHiCr0h6xBYLCRK
|
|
137
137
|
langfun/core/structured/mapping_test.py,sha256=OntYvfDitAf0tAnzQty3YS90vyEn6FY1Mi93r_ViEk8,9594
|
138
138
|
langfun/core/structured/parsing.py,sha256=MGvI7ypXlwfzr5XB8_TFU9Ei0_5reYqkWkv64eAy0EA,12015
|
139
139
|
langfun/core/structured/parsing_test.py,sha256=V8Cj1tJK4Lxv_b0YQj6-2hzXZgnYNBa2JR7rOLRBKoQ,22346
|
140
|
-
langfun/core/structured/querying.py,sha256=
|
141
|
-
langfun/core/structured/querying_test.py,sha256=
|
140
|
+
langfun/core/structured/querying.py,sha256=v-C8cU4LNFPwVSVgfO5PFyYxKCTHHh6SdbaR5V5MKKs,30938
|
141
|
+
langfun/core/structured/querying_test.py,sha256=6jN3oOSpVEBIlISrCUJtZfY6sBHahF_EBRUEhNNlzW8,40797
|
142
142
|
langfun/core/structured/schema.py,sha256=UTonddBx3hVr0Zhm_38jqd8khTSXWy-bkk8l1YOUdLA,28797
|
143
143
|
langfun/core/structured/schema_generation.py,sha256=3AcuKvv3VOtKY5zMVqODrxfOuDxzoZtGeBxHlOWDOWw,5308
|
144
144
|
langfun/core/structured/schema_generation_test.py,sha256=RM9s71kMNg2jTePwInkiW9fK1ACN37eyPeF8OII-0zw,2950
|
@@ -156,8 +156,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
156
156
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
157
157
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
158
158
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
159
|
-
langfun-0.1.2.
|
160
|
-
langfun-0.1.2.
|
161
|
-
langfun-0.1.2.
|
162
|
-
langfun-0.1.2.
|
163
|
-
langfun-0.1.2.
|
159
|
+
langfun-0.1.2.dev202505090804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
160
|
+
langfun-0.1.2.dev202505090804.dist-info/METADATA,sha256=m_vknRs5lJe6eWbqgQG2REHAaNbJn8P1nPpgpxorCsc,8178
|
161
|
+
langfun-0.1.2.dev202505090804.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
162
|
+
langfun-0.1.2.dev202505090804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
163
|
+
langfun-0.1.2.dev202505090804.dist-info/RECORD,,
|
File without changes
|
{langfun-0.1.2.dev202505070805.dist-info → langfun-0.1.2.dev202505090804.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
{langfun-0.1.2.dev202505070805.dist-info → langfun-0.1.2.dev202505090804.dist-info}/top_level.txt
RENAMED
File without changes
|