langfun 0.0.2.dev20240330__py3-none-any.whl → 0.1.2.dev202501140804__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 +22 -2
- langfun/core/__init__.py +17 -5
- langfun/core/agentic/__init__.py +30 -0
- langfun/core/agentic/action.py +854 -0
- langfun/core/agentic/action_eval.py +150 -0
- langfun/core/agentic/action_eval_test.py +109 -0
- langfun/core/agentic/action_test.py +136 -0
- langfun/core/coding/python/__init__.py +5 -11
- langfun/core/coding/python/correction.py +37 -28
- langfun/core/coding/python/correction_test.py +29 -3
- langfun/core/coding/python/execution.py +40 -216
- langfun/core/coding/python/execution_test.py +29 -89
- langfun/core/coding/python/generation.py +21 -11
- langfun/core/coding/python/generation_test.py +2 -2
- langfun/core/coding/python/parsing.py +108 -193
- langfun/core/coding/python/parsing_test.py +2 -105
- langfun/core/component.py +69 -2
- langfun/core/component_test.py +54 -0
- langfun/core/concurrent.py +414 -117
- langfun/core/concurrent_test.py +111 -24
- langfun/core/console.py +18 -5
- langfun/core/console_test.py +17 -0
- langfun/core/eval/__init__.py +17 -0
- langfun/core/eval/base.py +767 -140
- langfun/core/eval/base_test.py +238 -53
- langfun/core/eval/matching.py +80 -76
- langfun/core/eval/matching_test.py +19 -9
- langfun/core/eval/patching.py +130 -0
- langfun/core/eval/patching_test.py +170 -0
- langfun/core/eval/scoring.py +37 -28
- langfun/core/eval/scoring_test.py +21 -3
- langfun/core/eval/v2/__init__.py +42 -0
- langfun/core/eval/v2/checkpointing.py +380 -0
- langfun/core/eval/v2/checkpointing_test.py +228 -0
- langfun/core/eval/v2/eval_test_helper.py +136 -0
- langfun/core/eval/v2/evaluation.py +725 -0
- langfun/core/eval/v2/evaluation_test.py +180 -0
- langfun/core/eval/v2/example.py +305 -0
- langfun/core/eval/v2/example_test.py +128 -0
- langfun/core/eval/v2/experiment.py +1048 -0
- langfun/core/eval/v2/experiment_test.py +433 -0
- langfun/core/eval/v2/metric_values.py +156 -0
- langfun/core/eval/v2/metric_values_test.py +80 -0
- langfun/core/eval/v2/metrics.py +357 -0
- langfun/core/eval/v2/metrics_test.py +203 -0
- langfun/core/eval/v2/progress.py +348 -0
- langfun/core/eval/v2/progress_test.py +82 -0
- langfun/core/eval/v2/progress_tracking.py +210 -0
- langfun/core/eval/v2/progress_tracking_test.py +66 -0
- langfun/core/eval/v2/reporting.py +270 -0
- langfun/core/eval/v2/reporting_test.py +158 -0
- langfun/core/eval/v2/runners.py +488 -0
- langfun/core/eval/v2/runners_test.py +334 -0
- langfun/core/langfunc.py +3 -21
- langfun/core/langfunc_test.py +26 -8
- langfun/core/language_model.py +686 -48
- langfun/core/language_model_test.py +681 -44
- langfun/core/llms/__init__.py +100 -12
- langfun/core/llms/anthropic.py +488 -0
- langfun/core/llms/anthropic_test.py +235 -0
- langfun/core/llms/cache/base.py +21 -2
- langfun/core/llms/cache/in_memory.py +13 -0
- langfun/core/llms/cache/in_memory_test.py +88 -28
- langfun/core/llms/compositional.py +101 -0
- langfun/core/llms/compositional_test.py +73 -0
- langfun/core/llms/deepseek.py +117 -0
- langfun/core/llms/deepseek_test.py +61 -0
- langfun/core/llms/fake.py +39 -26
- langfun/core/llms/fake_test.py +136 -11
- langfun/core/llms/gemini.py +507 -0
- langfun/core/llms/gemini_test.py +195 -0
- langfun/core/llms/google_genai.py +62 -218
- langfun/core/llms/google_genai_test.py +9 -197
- langfun/core/llms/groq.py +276 -0
- langfun/core/llms/groq_test.py +64 -0
- langfun/core/llms/llama_cpp.py +15 -40
- langfun/core/llms/llama_cpp_test.py +4 -30
- langfun/core/llms/openai.py +436 -226
- langfun/core/llms/openai_compatible.py +179 -0
- langfun/core/llms/openai_compatible_test.py +495 -0
- langfun/core/llms/openai_test.py +35 -174
- langfun/core/llms/rest.py +113 -0
- langfun/core/llms/rest_test.py +111 -0
- langfun/core/llms/vertexai.py +192 -0
- langfun/core/llms/vertexai_test.py +52 -0
- langfun/core/logging.py +284 -0
- langfun/core/logging_test.py +125 -0
- langfun/core/message.py +319 -9
- langfun/core/message_test.py +190 -13
- langfun/core/modalities/__init__.py +6 -2
- langfun/core/modalities/audio.py +30 -0
- langfun/core/modalities/audio_test.py +63 -0
- langfun/core/modalities/image.py +39 -20
- langfun/core/modalities/image_test.py +52 -9
- langfun/core/modalities/mime.py +206 -29
- langfun/core/modalities/mime_test.py +90 -9
- langfun/core/modalities/ms_office.py +117 -0
- langfun/core/modalities/ms_office_test.py +389 -0
- langfun/core/modalities/pdf.py +22 -0
- langfun/core/modalities/pdf_test.py +57 -0
- langfun/core/modalities/video.py +9 -23
- langfun/core/modalities/video_test.py +3 -3
- langfun/core/modality.py +26 -3
- langfun/core/modality_test.py +2 -2
- langfun/core/sampling.py +11 -11
- langfun/core/structured/__init__.py +15 -16
- langfun/core/structured/completion.py +32 -5
- langfun/core/structured/completion_test.py +9 -8
- langfun/core/structured/description.py +2 -2
- langfun/core/structured/description_test.py +3 -3
- langfun/core/structured/function_generation.py +278 -0
- langfun/core/structured/function_generation_test.py +399 -0
- langfun/core/structured/mapping.py +150 -46
- langfun/core/structured/mapping_test.py +105 -0
- langfun/core/structured/parsing.py +33 -21
- langfun/core/structured/parsing_test.py +71 -22
- langfun/core/structured/querying.py +746 -0
- langfun/core/structured/{prompting_test.py → querying_test.py} +545 -60
- langfun/core/structured/schema.py +208 -99
- langfun/core/structured/schema_generation.py +1 -1
- langfun/core/structured/schema_generation_test.py +2 -2
- langfun/core/structured/schema_test.py +133 -34
- langfun/core/structured/scoring.py +125 -19
- langfun/core/structured/scoring_test.py +30 -0
- langfun/core/structured/tokenization.py +64 -0
- langfun/core/structured/tokenization_test.py +48 -0
- langfun/core/template.py +240 -11
- langfun/core/template_test.py +146 -1
- langfun/core/templates/conversation.py +9 -0
- langfun/core/templates/conversation_test.py +4 -3
- langfun/core/templates/selfplay_test.py +14 -2
- langfun-0.1.2.dev202501140804.dist-info/METADATA +225 -0
- langfun-0.1.2.dev202501140804.dist-info/RECORD +153 -0
- {langfun-0.0.2.dev20240330.dist-info → langfun-0.1.2.dev202501140804.dist-info}/WHEEL +1 -1
- langfun/core/coding/python/errors.py +0 -108
- langfun/core/coding/python/errors_test.py +0 -99
- langfun/core/coding/python/permissions.py +0 -90
- langfun/core/coding/python/permissions_test.py +0 -86
- langfun/core/structured/prompting.py +0 -217
- langfun/core/text_formatting.py +0 -162
- langfun/core/text_formatting_test.py +0 -47
- langfun-0.0.2.dev20240330.dist-info/METADATA +0 -99
- langfun-0.0.2.dev20240330.dist-info/RECORD +0 -102
- {langfun-0.0.2.dev20240330.dist-info → langfun-0.1.2.dev202501140804.dist-info}/LICENSE +0 -0
- {langfun-0.0.2.dev20240330.dist-info → langfun-0.1.2.dev202501140804.dist-info}/top_level.txt +0 -0
@@ -17,11 +17,9 @@ import inspect
|
|
17
17
|
import unittest
|
18
18
|
|
19
19
|
import langfun.core as lf
|
20
|
-
from langfun.core import coding
|
21
20
|
from langfun.core.llms import fake
|
22
21
|
from langfun.core.structured import mapping
|
23
22
|
from langfun.core.structured import parsing
|
24
|
-
from langfun.core.structured import schema as schema_lib
|
25
23
|
import pyglove as pg
|
26
24
|
|
27
25
|
|
@@ -39,7 +37,7 @@ class Itinerary(pg.Object):
|
|
39
37
|
class ParseStructurePythonTest(unittest.TestCase):
|
40
38
|
|
41
39
|
def test_render_no_examples(self):
|
42
|
-
l = parsing.
|
40
|
+
l = parsing._ParseStructurePython(int)
|
43
41
|
m = lf.AIMessage('12 / 6 + 2 = 4')
|
44
42
|
self.assertEqual(
|
45
43
|
l.render(input=m, context='Compute 12 / 6 + 2.').text,
|
@@ -64,7 +62,7 @@ class ParseStructurePythonTest(unittest.TestCase):
|
|
64
62
|
)
|
65
63
|
|
66
64
|
def test_render_no_context(self):
|
67
|
-
l = parsing.
|
65
|
+
l = parsing._ParseStructurePython(int)
|
68
66
|
m = lf.AIMessage('12 / 6 + 2 = 4')
|
69
67
|
|
70
68
|
self.assertEqual(
|
@@ -87,7 +85,7 @@ class ParseStructurePythonTest(unittest.TestCase):
|
|
87
85
|
)
|
88
86
|
|
89
87
|
def test_render(self):
|
90
|
-
l = parsing.
|
88
|
+
l = parsing._ParseStructurePython(
|
91
89
|
int,
|
92
90
|
examples=[
|
93
91
|
mapping.MappingExample(
|
@@ -214,7 +212,7 @@ class ParseStructurePythonTest(unittest.TestCase):
|
|
214
212
|
),
|
215
213
|
override_attrs=True,
|
216
214
|
):
|
217
|
-
l = parsing.
|
215
|
+
l = parsing._ParseStructurePython(
|
218
216
|
[Itinerary],
|
219
217
|
examples=[
|
220
218
|
mapping.MappingExample(
|
@@ -255,7 +253,7 @@ class ParseStructurePythonTest(unittest.TestCase):
|
|
255
253
|
override_attrs=True,
|
256
254
|
):
|
257
255
|
with self.assertRaisesRegex(
|
258
|
-
|
256
|
+
mapping.MappingError,
|
259
257
|
'name .* is not defined',
|
260
258
|
):
|
261
259
|
parsing.parse('three', int)
|
@@ -280,13 +278,15 @@ class ParseStructurePythonTest(unittest.TestCase):
|
|
280
278
|
),
|
281
279
|
1,
|
282
280
|
)
|
281
|
+
r = parsing.parse(
|
282
|
+
'the answer is 1', int, user_prompt='what is 0 + 1?', lm=lm,
|
283
|
+
returns_message=True
|
284
|
+
)
|
283
285
|
self.assertEqual(
|
284
|
-
|
285
|
-
'the answer is 1', int, user_prompt='what is 0 + 1?', lm=lm,
|
286
|
-
returns_message=True
|
287
|
-
),
|
286
|
+
r,
|
288
287
|
lf.AIMessage(
|
289
|
-
'1', score=1.0, result=1, logprobs=None,
|
288
|
+
'1', score=1.0, result=1, logprobs=None, is_cached=False,
|
289
|
+
usage=lf.LMSamplingUsage(652, 1, 653),
|
290
290
|
tags=['lm-response', 'lm-output', 'transformed']
|
291
291
|
),
|
292
292
|
)
|
@@ -295,7 +295,7 @@ class ParseStructurePythonTest(unittest.TestCase):
|
|
295
295
|
class ParseStructureJsonTest(unittest.TestCase):
|
296
296
|
|
297
297
|
def test_render_no_examples(self):
|
298
|
-
l = parsing.
|
298
|
+
l = parsing._ParseStructureJson(int)
|
299
299
|
m = lf.AIMessage('12 / 6 + 2 = 4')
|
300
300
|
self.assertEqual(
|
301
301
|
l.render(input=m, context='Compute 12 / 6 + 2.').text,
|
@@ -320,7 +320,7 @@ class ParseStructureJsonTest(unittest.TestCase):
|
|
320
320
|
)
|
321
321
|
|
322
322
|
def test_render_no_context(self):
|
323
|
-
l = parsing.
|
323
|
+
l = parsing._ParseStructureJson(int)
|
324
324
|
m = lf.AIMessage('12 / 6 + 2 = 4')
|
325
325
|
|
326
326
|
self.assertEqual(
|
@@ -343,7 +343,7 @@ class ParseStructureJsonTest(unittest.TestCase):
|
|
343
343
|
)
|
344
344
|
|
345
345
|
def test_render(self):
|
346
|
-
l = parsing.
|
346
|
+
l = parsing._ParseStructureJson(
|
347
347
|
int,
|
348
348
|
examples=[
|
349
349
|
mapping.MappingExample(
|
@@ -504,7 +504,7 @@ class ParseStructureJsonTest(unittest.TestCase):
|
|
504
504
|
override_attrs=True,
|
505
505
|
):
|
506
506
|
message = lf.LangFunc(lm_input)()
|
507
|
-
l = parsing.
|
507
|
+
l = parsing._ParseStructureJson(
|
508
508
|
[Itinerary],
|
509
509
|
examples=[
|
510
510
|
mapping.MappingExample(
|
@@ -544,7 +544,7 @@ class ParseStructureJsonTest(unittest.TestCase):
|
|
544
544
|
override_attrs=True,
|
545
545
|
):
|
546
546
|
with self.assertRaisesRegex(
|
547
|
-
|
547
|
+
mapping.MappingError,
|
548
548
|
'No JSON dict in the output',
|
549
549
|
):
|
550
550
|
parsing.parse('three', int, protocol='json')
|
@@ -634,13 +634,19 @@ class CallTest(unittest.TestCase):
|
|
634
634
|
)
|
635
635
|
|
636
636
|
def test_call_with_returning_message(self):
|
637
|
+
r = parsing.call(
|
638
|
+
'Compute 1 + 2', int, lm=fake.StaticSequence(['three', '3']),
|
639
|
+
returns_message=True
|
640
|
+
)
|
637
641
|
self.assertEqual(
|
638
|
-
|
639
|
-
'Compute 1 + 2', int, lm=fake.StaticSequence(['three', '3']),
|
640
|
-
returns_message=True
|
641
|
-
),
|
642
|
+
r,
|
642
643
|
lf.AIMessage(
|
643
|
-
'3',
|
644
|
+
'3',
|
645
|
+
result=3,
|
646
|
+
score=1.0,
|
647
|
+
logprobs=None,
|
648
|
+
is_cached=False,
|
649
|
+
usage=lf.LMSamplingUsage(315, 1, 316),
|
644
650
|
tags=['lm-response', 'lm-output', 'transformed']
|
645
651
|
),
|
646
652
|
)
|
@@ -664,6 +670,49 @@ class CallTest(unittest.TestCase):
|
|
664
670
|
3,
|
665
671
|
)
|
666
672
|
|
673
|
+
def test_call_with_parsing_message_chaining(self):
|
674
|
+
output = parsing.call(
|
675
|
+
'Compute 1 + 2',
|
676
|
+
int,
|
677
|
+
lm=fake.StaticSequence(['three']),
|
678
|
+
parsing_lm=fake.StaticSequence(['3']),
|
679
|
+
parsing_examples=[
|
680
|
+
mapping.MappingExample(
|
681
|
+
context='Multiple four and five',
|
682
|
+
input='twenty',
|
683
|
+
schema=int,
|
684
|
+
output=20,
|
685
|
+
)
|
686
|
+
],
|
687
|
+
returns_message=True,
|
688
|
+
)
|
689
|
+
self.assertIn('parsing-lm-output', output.tags)
|
690
|
+
self.assertIn('parsing-lm-input', output.source.tags)
|
691
|
+
self.assertEqual(output.root.text, 'Compute 1 + 2')
|
692
|
+
|
693
|
+
def test_call_with_parsing_message_chaining_on_parsing_error(self):
|
694
|
+
try:
|
695
|
+
output = parsing.call(
|
696
|
+
'Compute 1 + 2',
|
697
|
+
int,
|
698
|
+
lm=fake.StaticSequence(['three']),
|
699
|
+
parsing_lm=fake.StaticSequence(['abc']),
|
700
|
+
parsing_examples=[
|
701
|
+
mapping.MappingExample(
|
702
|
+
context='Multiple four and five',
|
703
|
+
input='twenty',
|
704
|
+
schema=int,
|
705
|
+
output=20,
|
706
|
+
)
|
707
|
+
],
|
708
|
+
returns_message=True,
|
709
|
+
)
|
710
|
+
except mapping.MappingError as e:
|
711
|
+
output = e.lm_response
|
712
|
+
self.assertIn('parsing-lm-output', output.tags)
|
713
|
+
self.assertIn('parsing-lm-input', output.source.tags)
|
714
|
+
self.assertEqual(output.root.text, 'Compute 1 + 2')
|
715
|
+
|
667
716
|
def test_call_with_autofix(self):
|
668
717
|
lm = fake.StaticSequence(
|
669
718
|
[
|