langfun 0.1.2.dev202509050804__py3-none-any.whl → 0.1.2.dev202509070803__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/llms/__init__.py +1 -0
- langfun/core/llms/fake.py +7 -0
- langfun/core/llms/fake_test.py +9 -0
- langfun/core/structured/querying.py +13 -3
- langfun/core/structured/querying_test.py +26 -31
- {langfun-0.1.2.dev202509050804.dist-info → langfun-0.1.2.dev202509070803.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202509050804.dist-info → langfun-0.1.2.dev202509070803.dist-info}/RECORD +10 -10
- {langfun-0.1.2.dev202509050804.dist-info → langfun-0.1.2.dev202509070803.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202509050804.dist-info → langfun-0.1.2.dev202509070803.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202509050804.dist-info → langfun-0.1.2.dev202509070803.dist-info}/top_level.txt +0 -0
langfun/core/llms/__init__.py
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
# LMs for testing.
|
|
21
21
|
from langfun.core.llms.fake import Fake
|
|
22
22
|
from langfun.core.llms.fake import Echo
|
|
23
|
+
from langfun.core.llms.fake import Pseudo
|
|
23
24
|
from langfun.core.llms.fake import StaticMapping
|
|
24
25
|
from langfun.core.llms.fake import StaticResponse
|
|
25
26
|
from langfun.core.llms.fake import StaticSequence
|
langfun/core/llms/fake.py
CHANGED
|
@@ -62,6 +62,13 @@ class Echo(Fake):
|
|
|
62
62
|
return lf.AIMessage(prompt.text)
|
|
63
63
|
|
|
64
64
|
|
|
65
|
+
class Pseudo(Fake):
|
|
66
|
+
"""A pseudo language model that should never be called."""
|
|
67
|
+
|
|
68
|
+
def _response_from(self, prompt: lf.Message) -> lf.Message:
|
|
69
|
+
raise ValueError('Pseudo language model should never be called.')
|
|
70
|
+
|
|
71
|
+
|
|
65
72
|
@lf.use_init_args(['response'])
|
|
66
73
|
class StaticResponse(Fake):
|
|
67
74
|
"""Language model that always gives the same canned response."""
|
langfun/core/llms/fake_test.py
CHANGED
|
@@ -20,6 +20,15 @@ import langfun.core as lf
|
|
|
20
20
|
from langfun.core.llms import fake as fakelm
|
|
21
21
|
|
|
22
22
|
|
|
23
|
+
class PseudoTest(unittest.TestCase):
|
|
24
|
+
|
|
25
|
+
def test_sample(self):
|
|
26
|
+
lm = fakelm.Pseudo()
|
|
27
|
+
self.assertEqual(lm.model_id, 'Pseudo')
|
|
28
|
+
with self.assertRaises(ValueError):
|
|
29
|
+
_ = lm.sample(['hi'])
|
|
30
|
+
|
|
31
|
+
|
|
23
32
|
class EchoTest(unittest.TestCase):
|
|
24
33
|
|
|
25
34
|
def test_sample(self):
|
|
@@ -278,7 +278,7 @@ def query(
|
|
|
278
278
|
schema: schema_lib.SchemaType | None = None,
|
|
279
279
|
default: Any = lf.RAISE_IF_HAS_ERROR,
|
|
280
280
|
*,
|
|
281
|
-
lm: lf.LanguageModel | list[lf.LanguageModel]
|
|
281
|
+
lm: lf.LanguageModel | list[lf.LanguageModel],
|
|
282
282
|
num_samples: int | list[int] = 1,
|
|
283
283
|
system_message: str | lf.Template | None = None,
|
|
284
284
|
examples: list[mapping.MappingExample] | None = None,
|
|
@@ -414,7 +414,6 @@ def query(
|
|
|
414
414
|
lm: The language model(s) to query. Can be:
|
|
415
415
|
- A single `LanguageModel`,
|
|
416
416
|
- A list of `LanguageModel`s for multi-model fan-out.
|
|
417
|
-
If `None`, the LM from `lf.context` will be used.
|
|
418
417
|
num_samples: Number of samples to generate. If a list is provided, its
|
|
419
418
|
length must match the number of models in `lm`.
|
|
420
419
|
system_message: System instructions to guide the model output. If None,
|
|
@@ -766,9 +765,20 @@ def query_prompt(
|
|
|
766
765
|
**kwargs,
|
|
767
766
|
) -> lf.Message:
|
|
768
767
|
"""Returns the final prompt sent to LLM for `lf.query`."""
|
|
768
|
+
# Delay import to avoid circular dependency in Colab.
|
|
769
|
+
# llms > data/conversion > structured > querying
|
|
770
|
+
from langfun.core.llms import fake # pylint: disable=g-import-not-at-top
|
|
771
|
+
|
|
769
772
|
kwargs.pop('returns_message', None)
|
|
770
773
|
kwargs.pop('skip_lm', None)
|
|
771
|
-
return query(
|
|
774
|
+
return query(
|
|
775
|
+
prompt, schema,
|
|
776
|
+
# The LLM will never be used, it's just a placeholder.
|
|
777
|
+
lm=fake.Pseudo(),
|
|
778
|
+
skip_lm=True,
|
|
779
|
+
returns_message=True,
|
|
780
|
+
**kwargs
|
|
781
|
+
)
|
|
772
782
|
|
|
773
783
|
|
|
774
784
|
def query_output(
|
|
@@ -991,15 +991,11 @@ class LfQueryPythonV2Test(unittest.TestCase):
|
|
|
991
991
|
)
|
|
992
992
|
|
|
993
993
|
def test_bad_response(self):
|
|
994
|
-
with
|
|
995
|
-
|
|
996
|
-
|
|
994
|
+
with self.assertRaisesRegex(
|
|
995
|
+
mapping.MappingError,
|
|
996
|
+
'name .* is not defined',
|
|
997
997
|
):
|
|
998
|
-
|
|
999
|
-
mapping.MappingError,
|
|
1000
|
-
'name .* is not defined',
|
|
1001
|
-
):
|
|
1002
|
-
querying.query('Compute 1 + 2', int)
|
|
998
|
+
querying.query('Compute 1 + 2', int, lm=fake.StaticSequence(['a2']))
|
|
1003
999
|
|
|
1004
1000
|
def test_not_allowed_code(self):
|
|
1005
1001
|
lm = fake.StaticResponse(
|
|
@@ -1026,21 +1022,20 @@ class LfQueryPythonV2Test(unittest.TestCase):
|
|
|
1026
1022
|
self.assertEqual(querying.query('what is 1 + 0', int, lm=lm, autofix=3), 1)
|
|
1027
1023
|
|
|
1028
1024
|
def test_response_postprocess(self):
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
)
|
|
1025
|
+
self.assertEqual(
|
|
1026
|
+
querying.query(
|
|
1027
|
+
'Compute 1 + 2',
|
|
1028
|
+
lm=fake.StaticResponse('<!-- some comment-->\n3'),
|
|
1029
|
+
response_postprocess=lambda x: x.split('\n')[1]),
|
|
1030
|
+
'3'
|
|
1031
|
+
)
|
|
1032
|
+
self.assertEqual(
|
|
1033
|
+
querying.query(
|
|
1034
|
+
'Compute 1 + 2', int,
|
|
1035
|
+
lm=fake.StaticResponse('<!-- some comment-->\n3'),
|
|
1036
|
+
response_postprocess=lambda x: x.split('\n')[1]),
|
|
1037
|
+
3
|
|
1038
|
+
)
|
|
1044
1039
|
|
|
1045
1040
|
def test_render(self):
|
|
1046
1041
|
l = querying.LfQuery.from_protocol('python:2.0')(
|
|
@@ -1312,15 +1307,15 @@ class LfQueryJsonV1Test(unittest.TestCase):
|
|
|
1312
1307
|
|
|
1313
1308
|
def test_bad_transform(self):
|
|
1314
1309
|
with in_memory.lm_cache() as cache:
|
|
1315
|
-
with
|
|
1316
|
-
|
|
1317
|
-
|
|
1310
|
+
with self.assertRaisesRegex(
|
|
1311
|
+
mapping.MappingError,
|
|
1312
|
+
'No JSON dict in the output',
|
|
1318
1313
|
):
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
'
|
|
1322
|
-
|
|
1323
|
-
|
|
1314
|
+
querying.query(
|
|
1315
|
+
'Compute 1 + 2', int,
|
|
1316
|
+
lm=fake.StaticSequence(['3']),
|
|
1317
|
+
protocol='json', cache_seed=1
|
|
1318
|
+
)
|
|
1324
1319
|
# Make sure bad mapping does not impact cache.
|
|
1325
1320
|
self.assertEqual(len(cache), 0)
|
|
1326
1321
|
|
|
@@ -90,7 +90,7 @@ langfun/core/eval/v2/reporting.py,sha256=yUIPCAMnp7InIzpv1DDWrcLO-75iiOUTpscj7sm
|
|
|
90
90
|
langfun/core/eval/v2/reporting_test.py,sha256=CMK-vwho8cNRJwlbkCqm_v5fykE7Y3V6SaIOCY0CDyA,5671
|
|
91
91
|
langfun/core/eval/v2/runners.py,sha256=bEniZDNu44AQgvqpwLsvBU4V_7WltAe-NPhYgIsLj1E,16848
|
|
92
92
|
langfun/core/eval/v2/runners_test.py,sha256=spjkmqlls_vyERdZMdjv6dhIN9ZfxsDDvIQAWTj2kMk,11954
|
|
93
|
-
langfun/core/llms/__init__.py,sha256=
|
|
93
|
+
langfun/core/llms/__init__.py,sha256=u__rpDCoJz88P2vHnPtNwdvr4Em3SmmHgUhx-hHnDcc,9705
|
|
94
94
|
langfun/core/llms/anthropic.py,sha256=YcQ2VG8iOfXtry_tTpAukmiwXa2hK_9LkpkmXk41Nm0,26226
|
|
95
95
|
langfun/core/llms/anthropic_test.py,sha256=qA9vByp_cwwXNlXzcwHpPWFnO9lfFo8NKfDi5nBNqgI,9052
|
|
96
96
|
langfun/core/llms/azure_openai.py,sha256=-KkSLaR54MlsIqz_XIwv0TnsBnvNTAxnjA2Q2O2u5KM,2733
|
|
@@ -99,8 +99,8 @@ langfun/core/llms/compositional.py,sha256=W_Fe2BdbkjwTzWW-paCWcEeG9oOR3-IcBG8oc7
|
|
|
99
99
|
langfun/core/llms/compositional_test.py,sha256=4eTnOer-DncRKGaIJW2ZQQMLnt5r2R0UIx_DYOvGAQo,2027
|
|
100
100
|
langfun/core/llms/deepseek.py,sha256=jvTxdXPr-vH6HNakn_Ootx1heDg8Fen2FUkUW36bpCs,5247
|
|
101
101
|
langfun/core/llms/deepseek_test.py,sha256=DvROWPlDuow5E1lfoSkhyGt_ELA19JoQoDsTnRgDtTg,1847
|
|
102
|
-
langfun/core/llms/fake.py,sha256=
|
|
103
|
-
langfun/core/llms/fake_test.py,sha256=
|
|
102
|
+
langfun/core/llms/fake.py,sha256=bDk_4u7V2LmYUotyOaicwzi0-lnWOIIBbR3-Bil1P3o,3481
|
|
103
|
+
langfun/core/llms/fake_test.py,sha256=lC-C2TpEsnf2kmZpa3OiH2H944I4hMWTAaHEXzRj1DU,7855
|
|
104
104
|
langfun/core/llms/gemini.py,sha256=r4WVWMWHVtyR7tf4NdJ_eAL8Uq6OyQU_2-yBbzrx5mQ,30065
|
|
105
105
|
langfun/core/llms/gemini_test.py,sha256=y1s0W65SrdepbZxzgIeoTB2MI7sXnfBDf1NsGn57LbM,7617
|
|
106
106
|
langfun/core/llms/google_genai.py,sha256=ogyoOUK4s1OcSFKun0YK5xBRDVyxmvz9WsYNKAwuB0g,5918
|
|
@@ -146,8 +146,8 @@ langfun/core/structured/mapping.py,sha256=1YBW8PKpJKXS7DKukfzKNioL84PrKUcB4KOUud
|
|
|
146
146
|
langfun/core/structured/mapping_test.py,sha256=OntYvfDitAf0tAnzQty3YS90vyEn6FY1Mi93r_ViEk8,9594
|
|
147
147
|
langfun/core/structured/parsing.py,sha256=bLi7o1AdyDWc6TwxmYg70t_oTgmLkJWBafakdF8n2RI,14195
|
|
148
148
|
langfun/core/structured/parsing_test.py,sha256=vRfCSzA9q7C1cElkAnDvbRepULEa_vclqDIv-heypDw,22745
|
|
149
|
-
langfun/core/structured/querying.py,sha256=
|
|
150
|
-
langfun/core/structured/querying_test.py,sha256=
|
|
149
|
+
langfun/core/structured/querying.py,sha256=DKp3HCJRetbfC2hnrb680aQBr2AIkXoVA9pd8r6nuPI,39452
|
|
150
|
+
langfun/core/structured/querying_test.py,sha256=iDaqDJCJpdILj2b6I7fTLmbYzAU4EFjQacTRDxx2b0g,50353
|
|
151
151
|
langfun/core/structured/schema.py,sha256=xtgrr3t5tcYQ2gi_fkTKz2IgDMf84gpiykmBdfnV6Io,29486
|
|
152
152
|
langfun/core/structured/schema_generation.py,sha256=pEWeTd8tQWYnEHukas6GVl4uGerLsQ2aNybtnm4Qgxc,5352
|
|
153
153
|
langfun/core/structured/schema_generation_test.py,sha256=RM9s71kMNg2jTePwInkiW9fK1ACN37eyPeF8OII-0zw,2950
|
|
@@ -165,8 +165,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
|
165
165
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
|
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
|
-
langfun-0.1.2.
|
|
169
|
-
langfun-0.1.2.
|
|
170
|
-
langfun-0.1.2.
|
|
171
|
-
langfun-0.1.2.
|
|
172
|
-
langfun-0.1.2.
|
|
168
|
+
langfun-0.1.2.dev202509070803.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
169
|
+
langfun-0.1.2.dev202509070803.dist-info/METADATA,sha256=tBuxpz6mToS9KtFj1l_HUiJJJMlt0nqtpxlOuBuOdu4,7380
|
|
170
|
+
langfun-0.1.2.dev202509070803.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
171
|
+
langfun-0.1.2.dev202509070803.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
|
172
|
+
langfun-0.1.2.dev202509070803.dist-info/RECORD,,
|
|
File without changes
|
{langfun-0.1.2.dev202509050804.dist-info → langfun-0.1.2.dev202509070803.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{langfun-0.1.2.dev202509050804.dist-info → langfun-0.1.2.dev202509070803.dist-info}/top_level.txt
RENAMED
|
File without changes
|