langfun 0.1.2.dev202412020805__py3-none-any.whl → 0.1.2.dev202412050804__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.
@@ -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}}'), int, x=1, y=0, lm=lm.clone()
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.1.2.dev202412020805
3
+ Version: 0.1.2.dev202412050804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -30,9 +30,7 @@ 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
- Requires-Dist: openai>=0.27.2; extra == "all"
36
34
  Requires-Dist: python-magic>=0.4.27; extra == "all"
37
35
  Requires-Dist: python-docx>=0.8.11; extra == "all"
38
36
  Requires-Dist: pillow>=10.0.0; extra == "all"
@@ -42,18 +40,11 @@ Provides-Extra: ui
42
40
  Requires-Dist: termcolor==1.1.0; extra == "ui"
43
41
  Requires-Dist: tqdm>=4.64.1; extra == "ui"
44
42
  Provides-Extra: llm
45
- Requires-Dist: google-cloud-aiplatform>=1.5.0; extra == "llm"
46
43
  Requires-Dist: google-generativeai>=0.3.2; extra == "llm"
47
- Requires-Dist: openai>=0.27.2; extra == "llm"
48
44
  Provides-Extra: llm-google
49
- Requires-Dist: google-cloud-aiplatform>=1.5.0; extra == "llm-google"
50
45
  Requires-Dist: google-generativeai>=0.3.2; extra == "llm-google"
51
- Provides-Extra: llm-google-vertex
52
- Requires-Dist: google-cloud-aiplatform>=1.5.0; extra == "llm-google-vertex"
53
46
  Provides-Extra: llm-google-genai
54
47
  Requires-Dist: google-generativeai>=0.3.2; extra == "llm-google-genai"
55
- Provides-Extra: llm-openai
56
- Requires-Dist: openai>=0.27.2; extra == "llm-openai"
57
48
  Provides-Extra: mime
58
49
  Requires-Dist: python-magic>=0.4.27; extra == "mime"
59
50
  Requires-Dist: python-docx>=0.8.11; extra == "mime"
@@ -212,9 +203,7 @@ If you want to customize your installation, you can select specific features usi
212
203
  | all | All Langfun features. |
213
204
  | llm | All supported LLMs. |
214
205
  | llm-google | All supported Google-powered LLMs. |
215
- | llm-google-vertexai | LLMs powered by Google Cloud VertexAI |
216
206
  | llm-google-genai | LLMs powered by Google Generative AI API |
217
- | llm-openai | LLMs powered by OpenAI |
218
207
  | mime | All MIME supports. |
219
208
  | mime-auto | Automatic MIME type detection. |
220
209
  | mime-docx | DocX format support. |
@@ -1,4 +1,4 @@
1
- langfun/__init__.py,sha256=o_HvoQggla5uqNA7uF1126aZhayHnVNP__nd_t5ElEQ,2358
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=Am5E1EH1ZBAhzagbnDVRnR4vBzI4H6MEtQ58laSPfTg,7515
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=CBsUQICD8yPCDUBBFouSkZuyLAcK_C-AWYc28Zts10E,2624
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
@@ -76,10 +76,10 @@ langfun/core/eval/v2/progress_tracking.py,sha256=l9fEkz4oP5McpZzf72Ua7PYm3lAWtRr
76
76
  langfun/core/eval/v2/progress_tracking_test.py,sha256=iO-DslCJWncU7-27XaMKxDeKrsGbwdk_tKfoRk3KboE,2271
77
77
  langfun/core/eval/v2/reporting.py,sha256=TGkli1IDwqfqsCJ_WslOMGk_24JDg7oRRTGXlAJlWpc,4361
78
78
  langfun/core/eval/v2/reporting_test.py,sha256=JxffbUPWInUyLjo-AQVFrllga884Mdfm05R86FtxSss,1482
79
- langfun/core/eval/v2/runners.py,sha256=zJmu-amUiYv1g0Ek4c3mXkBgp-AFvSF7WpXVZCCf7Y4,14245
79
+ langfun/core/eval/v2/runners.py,sha256=kP6ZEg9L8M7fK03tOZYGqIjTKUzoJn8Hz_LXS7btFPQ,14335
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=5djybv30-27qaVjZY50IkT66UdvLa-2xfGX-vOfeM0I,6573
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
@@ -92,12 +92,12 @@ langfun/core/llms/groq.py,sha256=dCnR3eAECEKuKKAAj-PDTs8NRHl6CQPdf57m1f6a79U,103
92
92
  langfun/core/llms/groq_test.py,sha256=GYF_Qtq5S1H1TrKH38t6_lkdroqT7v-joYLDKnmS9e0,5274
93
93
  langfun/core/llms/llama_cpp.py,sha256=9tXQntSCDtjTF3bnyJrAPCr4N6wycy5nXYvp9uduygE,2843
94
94
  langfun/core/llms/llama_cpp_test.py,sha256=MWO_qaOeKjRniGjcaWPDScd7HPaIJemqUZoslrt4FPs,1806
95
- langfun/core/llms/openai.py,sha256=_VwOSuDsyXDngUM2iiES0CW1aN0BzMjXNBMegLzm4J4,23209
96
- langfun/core/llms/openai_test.py,sha256=_8cd3VRNEUfE0-Ko1RiM6MlC5hjalRj7nYTJNhG1p3E,18907
95
+ langfun/core/llms/openai.py,sha256=l49v6RubfInvV0iG114AymTKNogTX4u4N-UFCeSgIxw,20963
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=EZhJrdN-SsZVV0KT3NHzaJLVKsNMxCT6M3W6f5fpIWQ,27068
100
- langfun/core/llms/vertexai_test.py,sha256=nGv59yE4xu1zUxqmP_U941QjSBrr_sW15Q2YakuxMv4,16982
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=7EgI6pQIWnSNxhcIawBcSRDR8GPq5ytcmGxgPEjbxeA,3894
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=huwwh01AQQCwPBQESOMI_V1V5PZkVQ8C89Yjk67_4Uw,10677
133
- langfun/core/structured/prompting_test.py,sha256=pviyb8yTnxkWPAZodLIlQT8y2ScE6FfSHKWf1NUtV-Y,26718
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.dev202412020805.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
- langfun-0.1.2.dev202412020805.dist-info/METADATA,sha256=c3yjg186RyrDaIHGLMpmXsI7-Kqj4V1vLGxYsjJJN2Y,8890
153
- langfun-0.1.2.dev202412020805.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
154
- langfun-0.1.2.dev202412020805.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
- langfun-0.1.2.dev202412020805.dist-info/RECORD,,
151
+ langfun-0.1.2.dev202412050804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
+ langfun-0.1.2.dev202412050804.dist-info/METADATA,sha256=8ZkJgyA-BfFziFIsZ96fuJkEf9wyf9bci5BoWx8X0Xk,8281
153
+ langfun-0.1.2.dev202412050804.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
154
+ langfun-0.1.2.dev202412050804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
+ langfun-0.1.2.dev202412050804.dist-info/RECORD,,