langfun 0.1.2.dev202412030000__py3-none-any.whl → 0.1.2.dev202412040804__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/__init__.py +2 -0
- langfun/core/agentic/action.py +74 -24
- langfun/core/agentic/action_test.py +20 -4
- langfun/core/llms/__init__.py +1 -7
- langfun/core/llms/vertexai.py +23 -422
- langfun/core/llms/vertexai_test.py +21 -337
- langfun/core/structured/__init__.py +2 -0
- langfun/core/structured/prompting.py +148 -47
- langfun/core/structured/prompting_test.py +84 -1
- {langfun-0.1.2.dev202412030000.dist-info → langfun-0.1.2.dev202412040804.dist-info}/METADATA +1 -7
- {langfun-0.1.2.dev202412030000.dist-info → langfun-0.1.2.dev202412040804.dist-info}/RECORD +14 -14
- {langfun-0.1.2.dev202412030000.dist-info → langfun-0.1.2.dev202412040804.dist-info}/LICENSE +0 -0
- {langfun-0.1.2.dev202412030000.dist-info → langfun-0.1.2.dev202412040804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202412030000.dist-info → langfun-0.1.2.dev202412040804.dist-info}/top_level.txt +0 -0
@@ -89,7 +89,7 @@ class QueryTest(unittest.TestCase):
|
|
89
89
|
)
|
90
90
|
self.assertEqual(
|
91
91
|
prompting.query(
|
92
|
-
lf.Template('what is {{x}} + {{y}}'
|
92
|
+
lf.Template('what is {{x}} + {{y}}', x=1, y=0), int, lm=lm.clone()
|
93
93
|
),
|
94
94
|
1,
|
95
95
|
)
|
@@ -365,6 +365,23 @@ class QueryTest(unittest.TestCase):
|
|
365
365
|
"""),
|
366
366
|
)
|
367
367
|
|
368
|
+
def test_query_prompt_with_metadata(self):
|
369
|
+
self.assertIn(
|
370
|
+
'x',
|
371
|
+
prompting.query_prompt(
|
372
|
+
'what is this?',
|
373
|
+
metadata_x=1
|
374
|
+
).metadata
|
375
|
+
)
|
376
|
+
self.assertIn(
|
377
|
+
'x',
|
378
|
+
prompting.query_prompt(
|
379
|
+
'what is this?',
|
380
|
+
int,
|
381
|
+
metadata_x=1
|
382
|
+
).metadata
|
383
|
+
)
|
384
|
+
|
368
385
|
def test_query_prompt_with_unrooted_template(self):
|
369
386
|
output = prompting.query_prompt(
|
370
387
|
pg.Dict(
|
@@ -945,5 +962,71 @@ class QueryStructureJsonTest(unittest.TestCase):
|
|
945
962
|
)
|
946
963
|
|
947
964
|
|
965
|
+
class TrackQueriesTest(unittest.TestCase):
|
966
|
+
|
967
|
+
def test_include_child_scopes(self):
|
968
|
+
lm = fake.StaticSequence([
|
969
|
+
'bar',
|
970
|
+
'Activity(description="hi")',
|
971
|
+
])
|
972
|
+
with prompting.track_queries() as queries:
|
973
|
+
prompting.query('foo', lm=lm)
|
974
|
+
with prompting.track_queries() as child_queries:
|
975
|
+
prompting.query('give me an activity', Activity, lm=lm)
|
976
|
+
|
977
|
+
self.assertEqual(len(queries), 2)
|
978
|
+
self.assertTrue(pg.eq(queries[0].input, lf.Template('foo')))
|
979
|
+
self.assertIsNone(queries[0].schema)
|
980
|
+
self.assertEqual(queries[0].output, 'bar')
|
981
|
+
self.assertIs(queries[0].lm, lm)
|
982
|
+
|
983
|
+
self.assertTrue(pg.eq(queries[1].input, lf.Template('give me an activity')))
|
984
|
+
self.assertEqual(queries[1].schema.spec.cls, Activity)
|
985
|
+
self.assertTrue(pg.eq(queries[1].output, Activity(description='hi')))
|
986
|
+
self.assertIs(queries[1].lm, lm)
|
987
|
+
self.assertGreater(queries[0].usage_summary.total.total_tokens, 0)
|
988
|
+
self.assertGreater(queries[1].usage_summary.total.total_tokens, 0)
|
989
|
+
|
990
|
+
self.assertEqual(len(child_queries), 1)
|
991
|
+
self.assertIs(child_queries[0], queries[1])
|
992
|
+
|
993
|
+
def test_exclude_child_scopes(self):
|
994
|
+
lm = fake.StaticSequence([
|
995
|
+
'bar',
|
996
|
+
'Activity(description="hi")',
|
997
|
+
])
|
998
|
+
with prompting.track_queries(include_child_scopes=False) as queries:
|
999
|
+
prompting.query('foo', lm=lm)
|
1000
|
+
with prompting.track_queries(include_child_scopes=False) as child_queries:
|
1001
|
+
prompting.query('give me an activity', Activity, lm=lm)
|
1002
|
+
|
1003
|
+
self.assertEqual(len(queries), 1)
|
1004
|
+
self.assertTrue(pg.eq(queries[0].input, lf.Template('foo')))
|
1005
|
+
self.assertIsNone(queries[0].schema)
|
1006
|
+
self.assertEqual(queries[0].output, 'bar')
|
1007
|
+
self.assertIs(queries[0].lm, lm)
|
1008
|
+
|
1009
|
+
self.assertEqual(len(child_queries), 1)
|
1010
|
+
self.assertTrue(
|
1011
|
+
pg.eq(child_queries[0].input, lf.Template('give me an activity'))
|
1012
|
+
)
|
1013
|
+
self.assertEqual(child_queries[0].schema.spec.cls, Activity)
|
1014
|
+
self.assertTrue(pg.eq(child_queries[0].output, Activity(description='hi')))
|
1015
|
+
self.assertIs(child_queries[0].lm, lm)
|
1016
|
+
|
1017
|
+
def test_concurrent_map(self):
|
1018
|
+
|
1019
|
+
def make_query(prompt):
|
1020
|
+
_ = prompting.query(prompt, lm=lm)
|
1021
|
+
|
1022
|
+
lm = fake.StaticSequence([
|
1023
|
+
'foo',
|
1024
|
+
'bar',
|
1025
|
+
])
|
1026
|
+
with prompting.track_queries() as queries:
|
1027
|
+
list(lf.concurrent_map(make_query, ['a', 'b']))
|
1028
|
+
self.assertEqual(len(queries), 2)
|
1029
|
+
|
1030
|
+
|
948
1031
|
if __name__ == '__main__':
|
949
1032
|
unittest.main()
|
{langfun-0.1.2.dev202412030000.dist-info → langfun-0.1.2.dev202412040804.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: langfun
|
3
|
-
Version: 0.1.2.
|
3
|
+
Version: 0.1.2.dev202412040804
|
4
4
|
Summary: Langfun: Language as Functions.
|
5
5
|
Home-page: https://github.com/google/langfun
|
6
6
|
Author: Langfun Authors
|
@@ -30,7 +30,6 @@ Requires-Dist: jinja2>=3.1.2; extra == "all"
|
|
30
30
|
Requires-Dist: requests>=2.31.0; extra == "all"
|
31
31
|
Requires-Dist: termcolor==1.1.0; extra == "all"
|
32
32
|
Requires-Dist: tqdm>=4.64.1; extra == "all"
|
33
|
-
Requires-Dist: google-cloud-aiplatform>=1.5.0; extra == "all"
|
34
33
|
Requires-Dist: google-generativeai>=0.3.2; extra == "all"
|
35
34
|
Requires-Dist: python-magic>=0.4.27; extra == "all"
|
36
35
|
Requires-Dist: python-docx>=0.8.11; extra == "all"
|
@@ -41,13 +40,9 @@ Provides-Extra: ui
|
|
41
40
|
Requires-Dist: termcolor==1.1.0; extra == "ui"
|
42
41
|
Requires-Dist: tqdm>=4.64.1; extra == "ui"
|
43
42
|
Provides-Extra: llm
|
44
|
-
Requires-Dist: google-cloud-aiplatform>=1.5.0; extra == "llm"
|
45
43
|
Requires-Dist: google-generativeai>=0.3.2; extra == "llm"
|
46
44
|
Provides-Extra: llm-google
|
47
|
-
Requires-Dist: google-cloud-aiplatform>=1.5.0; extra == "llm-google"
|
48
45
|
Requires-Dist: google-generativeai>=0.3.2; extra == "llm-google"
|
49
|
-
Provides-Extra: llm-google-vertex
|
50
|
-
Requires-Dist: google-cloud-aiplatform>=1.5.0; extra == "llm-google-vertex"
|
51
46
|
Provides-Extra: llm-google-genai
|
52
47
|
Requires-Dist: google-generativeai>=0.3.2; extra == "llm-google-genai"
|
53
48
|
Provides-Extra: mime
|
@@ -208,7 +203,6 @@ If you want to customize your installation, you can select specific features usi
|
|
208
203
|
| all | All Langfun features. |
|
209
204
|
| llm | All supported LLMs. |
|
210
205
|
| llm-google | All supported Google-powered LLMs. |
|
211
|
-
| llm-google-vertexai | LLMs powered by Google Cloud VertexAI |
|
212
206
|
| llm-google-genai | LLMs powered by Google Generative AI API |
|
213
207
|
| mime | All MIME supports. |
|
214
208
|
| mime-auto | Automatic MIME type detection. |
|
@@ -1,4 +1,4 @@
|
|
1
|
-
langfun/__init__.py,sha256=
|
1
|
+
langfun/__init__.py,sha256=Xkzi8VV93jI7iLSrypzyHV9FtRbxHQpmoUCIZJSGHdA,2400
|
2
2
|
langfun/core/__init__.py,sha256=xlvFTXc7IKUTs8aCFRFhzOLTmmeuhXgk9yx2InBLNiA,4937
|
3
3
|
langfun/core/component.py,sha256=HVrEoTL1Y01iqOHC3FYdbAOnffqfHHtGJXoK1vkdEwo,11583
|
4
4
|
langfun/core/component_test.py,sha256=sG-T2wpvBfHqWGZE7sc4NayJj2aj5QFBzSwFiwrGEIc,10376
|
@@ -30,10 +30,10 @@ langfun/core/template_test.py,sha256=Qokz1hQFhRYaTZWBWGqvPJ0NXC9B9ennUpnRYHEf0hE
|
|
30
30
|
langfun/core/text_formatting.py,sha256=d7t9vaY6aCn1dkfkikpNYnBy5E_i93vHbfyDWFclGZU,5284
|
31
31
|
langfun/core/text_formatting_test.py,sha256=ck0Xzdd4YF4CtCUj7VE0GybfbAyKQ8p3xkM1FBGrqIk,2096
|
32
32
|
langfun/core/agentic/__init__.py,sha256=ndoDX0sAYsa3eVdXuu6nB-a-BH5TaK3urW6zAaFiyVs,1110
|
33
|
-
langfun/core/agentic/action.py,sha256=
|
33
|
+
langfun/core/agentic/action.py,sha256=lsEltCSrPag5GOvAeaakf_3iil28tKZJdN-NrovqQDw,8954
|
34
34
|
langfun/core/agentic/action_eval.py,sha256=ZtjTh34S7XPIUqandQ0YwAtzw-S7ofuZ7rRXnRbUMdQ,4424
|
35
35
|
langfun/core/agentic/action_eval_test.py,sha256=tRUkWmOE9p0rpNOq19xAY2oDEnYsEEykjg6sUpAwJk0,2832
|
36
|
-
langfun/core/agentic/action_test.py,sha256=
|
36
|
+
langfun/core/agentic/action_test.py,sha256=K6Ynop1zthRYMd_6Y4tpv3TFZRJAbNxEAwJf5dKlU5A,3235
|
37
37
|
langfun/core/coding/__init__.py,sha256=5utju_fwEsImaiftx4oXKl9FAM8p281k8-Esdh_-m1w,835
|
38
38
|
langfun/core/coding/python/__init__.py,sha256=MJ-vubliz-ebrZH3OBRKBwMi0S9-FrhGCp8YQLR6_I4,1776
|
39
39
|
langfun/core/coding/python/correction.py,sha256=WiBdoScL-6C___iA3Tg3vizuYtJWI-_4wy9zcMfVpj8,7020
|
@@ -79,7 +79,7 @@ langfun/core/eval/v2/reporting_test.py,sha256=JxffbUPWInUyLjo-AQVFrllga884Mdfm05
|
|
79
79
|
langfun/core/eval/v2/runners.py,sha256=zJmu-amUiYv1g0Ek4c3mXkBgp-AFvSF7WpXVZCCf7Y4,14245
|
80
80
|
langfun/core/eval/v2/runners_test.py,sha256=UeiUNygux_U6iGVG18rhp68ZE4hoWeoT6XsXvSjxNQg,11620
|
81
81
|
langfun/core/eval/v2/test_helper.py,sha256=pDpZTBnWRR5xjJv3Uy3NWEzArqlL8FTMOgeR4C53F5M,2348
|
82
|
-
langfun/core/llms/__init__.py,sha256=
|
82
|
+
langfun/core/llms/__init__.py,sha256=C4hyLflqOQT841nMfclcxcnOhdP83zR0GGW29PnA-vU,6216
|
83
83
|
langfun/core/llms/anthropic.py,sha256=uJXVgaFONL8okOSVQ4VGMGht_VZ30m1hoLzmDbIjmks,13990
|
84
84
|
langfun/core/llms/anthropic_test.py,sha256=-2U4kc_pgBM7wqxu8RuxzyHPGww1EAWqKUvN4PW8Btw,8058
|
85
85
|
langfun/core/llms/compositional.py,sha256=csW_FLlgL-tpeyCOTVvfUQkMa_zCN5Y2I-YbSNuK27U,2872
|
@@ -96,8 +96,8 @@ langfun/core/llms/openai.py,sha256=l49v6RubfInvV0iG114AymTKNogTX4u4N-UFCeSgIxw,2
|
|
96
96
|
langfun/core/llms/openai_test.py,sha256=kOWa1nf-nJvtYY10REUw5wojh3ZgfU8tRaCZ8wUgJbA,16623
|
97
97
|
langfun/core/llms/rest.py,sha256=sWbYUV8S3SuOg9giq7xwD-xDRfaF7NP_ig7bI52-Rj4,3442
|
98
98
|
langfun/core/llms/rest_test.py,sha256=NZ3Nf0XQVpT9kLP5cBVo_yBHLI7vWTYhWQxYEJVMGs4,3472
|
99
|
-
langfun/core/llms/vertexai.py,sha256=
|
100
|
-
langfun/core/llms/vertexai_test.py,sha256=
|
99
|
+
langfun/core/llms/vertexai.py,sha256=48GFuf04NOeInvwHeLhs-iEyxL03VCjtw05BGcKio0s,14172
|
100
|
+
langfun/core/llms/vertexai_test.py,sha256=ffcA5yPecnQy_rhkuYAw_6o1iLW8AR8FgswmHt6aAys,6725
|
101
101
|
langfun/core/llms/cache/__init__.py,sha256=QAo3InUMDM_YpteNnVCSejI4zOsnjSMWKJKzkb3VY64,993
|
102
102
|
langfun/core/llms/cache/base.py,sha256=rt3zwmyw0y9jsSGW-ZbV1vAfLxQ7_3AVk0l2EySlse4,3918
|
103
103
|
langfun/core/llms/cache/in_memory.py,sha256=l6b-iU9OTfTRo9Zmg4VrQIuArs4cCJDOpXiEpvNocjo,5004
|
@@ -118,7 +118,7 @@ langfun/core/modalities/pdf.py,sha256=mfaeCbUA4JslFVTARiJh8hW7imvL4tLVw9gUhO5bAZ
|
|
118
118
|
langfun/core/modalities/pdf_test.py,sha256=ulZ0FbnlsU0wkrdckJ4ONZPTYRyMPO9Aob1UO6FXygk,1950
|
119
119
|
langfun/core/modalities/video.py,sha256=vI9apcHIHGyp90i34Srg7S3G6IBDtDCk8qiXhwRQmkw,967
|
120
120
|
langfun/core/modalities/video_test.py,sha256=7OXZoohKMYjt7vrJUdPb553HLyl1oBOKRgzBePFv68Q,2042
|
121
|
-
langfun/core/structured/__init__.py,sha256=
|
121
|
+
langfun/core/structured/__init__.py,sha256=YGyGN-6gcGpzo1Hh-kpPFvC-dPYayjx7NRn06tyAdXE,4016
|
122
122
|
langfun/core/structured/completion.py,sha256=cS2PjG7sqzDu5x0xoTk8RmNcoeX55iVwH38NTefkMHg,8108
|
123
123
|
langfun/core/structured/completion_test.py,sha256=lendf6nPsNfAmd5A7k3v_HS2At9F_jjbKBcV7OEt94o,19310
|
124
124
|
langfun/core/structured/description.py,sha256=SXW4MJvshFjbR-0gw6rE21o6WXq12UlRXawvDBXMZFA,5211
|
@@ -129,8 +129,8 @@ langfun/core/structured/mapping.py,sha256=vLKH79UT-j0qkQdvqlQBO7SkXXuM-yr2Idm8_H
|
|
129
129
|
langfun/core/structured/mapping_test.py,sha256=bHm2ZCXBITq_G8Lvw_olFHeUUc4s_lGXZm9v9JhoPB4,9630
|
130
130
|
langfun/core/structured/parsing.py,sha256=D58wBWOC6r6DCJNychCDkiHPrsy1XJfBDCDDZtug00k,11765
|
131
131
|
langfun/core/structured/parsing_test.py,sha256=i0i090FVgM8ngGqYjds0hjEm1v7q4gv18k-z1kaNr7E,21467
|
132
|
-
langfun/core/structured/prompting.py,sha256=
|
133
|
-
langfun/core/structured/prompting_test.py,sha256=
|
132
|
+
langfun/core/structured/prompting.py,sha256=R9tfitDCBsQ725lzrSfaVgLi7FdtArWRStEMkzmJWQU,13698
|
133
|
+
langfun/core/structured/prompting_test.py,sha256=B0D70JmWgFYjRN9wfoSRX8zn0vdCUCJWk-igb59K0WY,29421
|
134
134
|
langfun/core/structured/schema.py,sha256=XHA-m_ENT_J0k8Q7WCiCL51xm7oXHOqskhO8RpPIurc,28174
|
135
135
|
langfun/core/structured/schema_generation.py,sha256=U3nRQsqmMZg_qIVDh2fiY3K4JLfsAL1LcKzIFP1iXFg,5316
|
136
136
|
langfun/core/structured/schema_generation_test.py,sha256=RM9s71kMNg2jTePwInkiW9fK1ACN37eyPeF8OII-0zw,2950
|
@@ -148,8 +148,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
148
148
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
149
149
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
150
150
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
151
|
-
langfun-0.1.2.
|
152
|
-
langfun-0.1.2.
|
153
|
-
langfun-0.1.2.
|
154
|
-
langfun-0.1.2.
|
155
|
-
langfun-0.1.2.
|
151
|
+
langfun-0.1.2.dev202412040804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
152
|
+
langfun-0.1.2.dev202412040804.dist-info/METADATA,sha256=0IziLhpTHxU_V2Sb2WLt0oiaBRLnrUj4QjwY9WnFW3g,8281
|
153
|
+
langfun-0.1.2.dev202412040804.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
154
|
+
langfun-0.1.2.dev202412040804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
155
|
+
langfun-0.1.2.dev202412040804.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{langfun-0.1.2.dev202412030000.dist-info → langfun-0.1.2.dev202412040804.dist-info}/top_level.txt
RENAMED
File without changes
|