langfun 0.1.2.dev202503280804__py3-none-any.whl → 0.1.2.dev202503300803__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/structured/querying.py +16 -1
- langfun/core/structured/querying_test.py +23 -0
- {langfun-0.1.2.dev202503280804.dist-info → langfun-0.1.2.dev202503300803.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202503280804.dist-info → langfun-0.1.2.dev202503300803.dist-info}/RECORD +7 -7
- {langfun-0.1.2.dev202503280804.dist-info → langfun-0.1.2.dev202503300803.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202503280804.dist-info → langfun-0.1.2.dev202503300803.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202503280804.dist-info → langfun-0.1.2.dev202503300803.dist-info}/top_level.txt +0 -0
@@ -19,7 +19,6 @@ import time
|
|
19
19
|
from typing import Annotated, Any, Callable, Iterator, Type, Union
|
20
20
|
|
21
21
|
import langfun.core as lf
|
22
|
-
from langfun.core.llms import fake
|
23
22
|
from langfun.core.structured import mapping
|
24
23
|
from langfun.core.structured import schema as schema_lib
|
25
24
|
import pyglove as pg
|
@@ -477,6 +476,10 @@ def query_output(
|
|
477
476
|
**kwargs,
|
478
477
|
) -> Any:
|
479
478
|
"""Returns the final output of `lf.query` from a provided LLM response."""
|
479
|
+
# Delay import to avoid circular dependency in Colab.
|
480
|
+
# llms > data/conversion > structured > querying
|
481
|
+
from langfun.core.llms import fake # pylint: disable=g-import-not-at-top
|
482
|
+
|
480
483
|
kwargs.pop('prompt', None)
|
481
484
|
kwargs.pop('lm', None)
|
482
485
|
return query(
|
@@ -606,6 +609,18 @@ class QueryInvocation(pg.Object, pg.views.HtmlTreeView.Extension):
|
|
606
609
|
"""Returns query elapse in seconds."""
|
607
610
|
return self.end_time - self.start_time
|
608
611
|
|
612
|
+
def as_mapping_example(
|
613
|
+
self,
|
614
|
+
metadata: dict[str, Any] | None = None
|
615
|
+
) -> mapping.MappingExample:
|
616
|
+
"""Returns a `MappingExample` object for this query invocation."""
|
617
|
+
return mapping.MappingExample(
|
618
|
+
input=self.input,
|
619
|
+
schema=self.schema,
|
620
|
+
output=self.output,
|
621
|
+
metadata=metadata or {},
|
622
|
+
)
|
623
|
+
|
609
624
|
def _on_bound(self):
|
610
625
|
super()._on_bound()
|
611
626
|
self.__dict__.pop('lm_request', None)
|
@@ -1072,6 +1072,29 @@ class QueryInvocationTest(unittest.TestCase):
|
|
1072
1072
|
self.assertEqual(queries[0].lm_response.score, 1.0)
|
1073
1073
|
self.assertFalse(queries[0].lm_response.is_cached)
|
1074
1074
|
|
1075
|
+
def test_as_mapping_example(self):
|
1076
|
+
lm = fake.StaticSequence([
|
1077
|
+
'Activity(description="hi")',
|
1078
|
+
])
|
1079
|
+
with querying.track_queries() as queries:
|
1080
|
+
querying.query(lf.Template('foo {{x}}', x=1), Activity, lm=lm)
|
1081
|
+
mapping_example = queries[0].as_mapping_example()
|
1082
|
+
self.assertTrue(pg.eq(mapping_example.input, lf.Template('foo {{x}}', x=1)))
|
1083
|
+
self.assertEqual(mapping_example.schema.spec.cls, Activity)
|
1084
|
+
self.assertEqual(mapping_example.output, Activity(description='hi'))
|
1085
|
+
|
1086
|
+
lm = fake.StaticSequence(['Activity(description="hi"'])
|
1087
|
+
with querying.track_queries() as queries:
|
1088
|
+
querying.query(
|
1089
|
+
lf.Template('foo {{x}}', x=1), Activity, default=None, lm=lm
|
1090
|
+
)
|
1091
|
+
|
1092
|
+
self.assertTrue(queries[0].has_error)
|
1093
|
+
mapping_example = queries[0].as_mapping_example()
|
1094
|
+
self.assertTrue(pg.eq(mapping_example.input, lf.Template('foo {{x}}', x=1)))
|
1095
|
+
self.assertEqual(mapping_example.schema.spec.cls, Activity)
|
1096
|
+
self.assertIsInstance(mapping_example.output, mapping.MappingError)
|
1097
|
+
|
1075
1098
|
|
1076
1099
|
class TrackQueriesTest(unittest.TestCase):
|
1077
1100
|
|
@@ -137,8 +137,8 @@ langfun/core/structured/mapping.py,sha256=of-EeBq0RgmkiUaSk2rVEDVCzgn_wXU8tRke7N
|
|
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=kNPrhpdPY3iWhUld0TFYU-Zgn44wC0d6YuQ9XdVbQ8o,22346
|
140
|
-
langfun/core/structured/querying.py,sha256=
|
141
|
-
langfun/core/structured/querying_test.py,sha256=
|
140
|
+
langfun/core/structured/querying.py,sha256=6dE4bRHpyE8H-YNDVFokDmTLgS1G1YdrE9n2TEuyw_I,23911
|
141
|
+
langfun/core/structured/querying_test.py,sha256=OZKIh9-P0W5FFiDeDUrQikjYEwcIQOzLSm3u81XZceQ,33514
|
142
142
|
langfun/core/structured/schema.py,sha256=_iqhHEGDQsHk0AsybWnK44sOspTWkKJjci781PWD7x0,27988
|
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.dev202503300803.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
160
|
+
langfun-0.1.2.dev202503300803.dist-info/METADATA,sha256=cK9l4c5VJZyhL315GgLbAVSCTtMmE2mJKVxyhfXNoVI,7692
|
161
|
+
langfun-0.1.2.dev202503300803.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
162
|
+
langfun-0.1.2.dev202503300803.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
163
|
+
langfun-0.1.2.dev202503300803.dist-info/RECORD,,
|
File without changes
|
{langfun-0.1.2.dev202503280804.dist-info → langfun-0.1.2.dev202503300803.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
{langfun-0.1.2.dev202503280804.dist-info → langfun-0.1.2.dev202503300803.dist-info}/top_level.txt
RENAMED
File without changes
|