langfun 0.0.2.dev20240429__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 +20 -2
- langfun/core/__init__.py +16 -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 -21
- 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 +63 -2
- langfun/core/component_test.py +53 -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 +16 -1
- langfun/core/eval/base.py +622 -174
- langfun/core/eval/base_test.py +200 -54
- langfun/core/eval/matching.py +63 -76
- langfun/core/eval/matching_test.py +17 -8
- langfun/core/eval/patching.py +130 -0
- langfun/core/eval/patching_test.py +170 -0
- langfun/core/eval/scoring.py +26 -26
- langfun/core/eval/scoring_test.py +19 -2
- 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 +4 -17
- langfun/core/langfunc_test.py +22 -6
- langfun/core/language_model.py +577 -39
- langfun/core/language_model_test.py +470 -56
- langfun/core/llms/__init__.py +87 -16
- langfun/core/llms/anthropic.py +312 -87
- langfun/core/llms/anthropic_test.py +71 -3
- 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 +53 -2
- 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 +11 -7
- langfun/core/llms/fake_test.py +14 -0
- 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 -202
- langfun/core/llms/groq.py +160 -144
- langfun/core/llms/groq_test.py +31 -137
- langfun/core/llms/llama_cpp.py +15 -42
- langfun/core/llms/llama_cpp_test.py +4 -30
- langfun/core/llms/openai.py +395 -203
- langfun/core/llms/openai_compatible.py +179 -0
- langfun/core/llms/openai_compatible_test.py +495 -0
- langfun/core/llms/openai_test.py +30 -395
- 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 -26
- 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 +12 -16
- langfun/core/structured/completion.py +32 -5
- langfun/core/structured/completion_test.py +7 -6
- langfun/core/structured/description.py +2 -2
- langfun/core/structured/description_test.py +3 -3
- langfun/core/structured/function_generation.py +60 -27
- langfun/core/structured/function_generation_test.py +72 -2
- langfun/core/structured/mapping.py +97 -47
- langfun/core/structured/mapping_test.py +90 -2
- langfun/core/structured/parsing.py +33 -21
- langfun/core/structured/parsing_test.py +53 -9
- langfun/core/structured/querying.py +746 -0
- langfun/core/structured/{prompting_test.py → querying_test.py} +469 -51
- langfun/core/structured/schema.py +204 -97
- langfun/core/structured/schema_generation.py +1 -1
- langfun/core/structured/schema_test.py +130 -29
- 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 +115 -1
- langfun/core/template_test.py +71 -1
- langfun/core/templates/conversation.py +9 -0
- langfun/core/templates/conversation_test.py +4 -3
- langfun/core/templates/selfplay_test.py +10 -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.dev20240429.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 -238
- langfun/core/text_formatting.py +0 -162
- langfun/core/text_formatting_test.py +0 -47
- langfun-0.0.2.dev20240429.dist-info/METADATA +0 -100
- langfun-0.0.2.dev20240429.dist-info/RECORD +0 -108
- {langfun-0.0.2.dev20240429.dist-info → langfun-0.1.2.dev202501140804.dist-info}/LICENSE +0 -0
- {langfun-0.0.2.dev20240429.dist-info → langfun-0.1.2.dev202501140804.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
# Copyright 2024 The Langfun Authors
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
"""Helper classes and functions for evaluation tests."""
|
15
|
+
|
16
|
+
from langfun.core import language_model
|
17
|
+
from langfun.core import llms
|
18
|
+
from langfun.core import message as message_lib
|
19
|
+
from langfun.core import structured
|
20
|
+
|
21
|
+
from langfun.core.eval.v2 import evaluation as evaluation_lib
|
22
|
+
from langfun.core.eval.v2 import example as example_lib
|
23
|
+
from langfun.core.eval.v2 import experiment as experiment_lib
|
24
|
+
from langfun.core.eval.v2 import metrics as metrics_lib
|
25
|
+
|
26
|
+
import pyglove as pg
|
27
|
+
|
28
|
+
Example = example_lib.Example
|
29
|
+
Suite = experiment_lib.Suite
|
30
|
+
Evaluation = evaluation_lib.Evaluation
|
31
|
+
RunId = experiment_lib.RunId
|
32
|
+
Run = experiment_lib.Run
|
33
|
+
|
34
|
+
|
35
|
+
@pg.functor()
|
36
|
+
def test_inputs(num_examples: int | None = 10):
|
37
|
+
if num_examples is None:
|
38
|
+
num_examples = 20
|
39
|
+
return [
|
40
|
+
pg.Dict(x=i, y=i ** 2, groundtruth=i + i ** 2)
|
41
|
+
for i in range(num_examples)
|
42
|
+
]
|
43
|
+
|
44
|
+
|
45
|
+
class TestLLM(llms.Fake):
|
46
|
+
"""Test language model."""
|
47
|
+
|
48
|
+
offset: int = 0
|
49
|
+
|
50
|
+
def _response_from(self, prompt: message_lib.Message) -> message_lib.Message:
|
51
|
+
return message_lib.AIMessage(
|
52
|
+
str(prompt.metadata.x + prompt.metadata.y + self.offset)
|
53
|
+
)
|
54
|
+
|
55
|
+
@property
|
56
|
+
def resource_id(self) -> str:
|
57
|
+
return f'test_llm:{self.offset}'
|
58
|
+
|
59
|
+
|
60
|
+
class TestEvaluation(Evaluation):
|
61
|
+
"""Test evaluation class."""
|
62
|
+
inputs = test_inputs()
|
63
|
+
metrics = [metrics_lib.Match()]
|
64
|
+
lm: language_model.LanguageModel = TestLLM()
|
65
|
+
|
66
|
+
def process(self, v):
|
67
|
+
if v.x == 5:
|
68
|
+
raise ValueError('x should not be 5')
|
69
|
+
return structured.query(
|
70
|
+
'{{x}} + {{y}} = ?', int, lm=self.lm, x=v.x, y=v.y,
|
71
|
+
metadata_x=v.x, metadata_y=v.y
|
72
|
+
)
|
73
|
+
|
74
|
+
|
75
|
+
class BadJsonConvertible(pg.Object):
|
76
|
+
|
77
|
+
def to_json(self, *args, **kwargs):
|
78
|
+
raise ValueError('Cannot convert to JSON.')
|
79
|
+
|
80
|
+
|
81
|
+
class TestEvaluationWithExampleCheckpointingError(TestEvaluation):
|
82
|
+
"""Test evaluation class with bad example checkpointing."""
|
83
|
+
inputs = test_inputs()
|
84
|
+
metrics = [metrics_lib.Match()]
|
85
|
+
|
86
|
+
def process(self, v):
|
87
|
+
return 1, dict(
|
88
|
+
x=BadJsonConvertible()
|
89
|
+
)
|
90
|
+
|
91
|
+
|
92
|
+
class BadHtmlConvertible(pg.Object, pg.views.HtmlTreeView.Extension):
|
93
|
+
|
94
|
+
def _html_tree_view(self, *args, **kwargs):
|
95
|
+
raise ValueError('Cannot render HTML.')
|
96
|
+
|
97
|
+
|
98
|
+
class TestEvaluationWithExampleHtmlGenerationError(Evaluation):
|
99
|
+
"""Test evaluation class with bad example HTML generation."""
|
100
|
+
inputs = test_inputs()
|
101
|
+
metrics = [metrics_lib.Match()]
|
102
|
+
|
103
|
+
def process(self, v):
|
104
|
+
return 1, dict(
|
105
|
+
x=BadHtmlConvertible()
|
106
|
+
)
|
107
|
+
|
108
|
+
|
109
|
+
class TestEvaluationWithIndexHtmlGenerationError(TestEvaluation):
|
110
|
+
"""Test evaluation class with bad index HTML generation."""
|
111
|
+
|
112
|
+
def _html_tree_view(self, *args, **kwargs):
|
113
|
+
raise ValueError('Cannot render HTML.')
|
114
|
+
|
115
|
+
|
116
|
+
def test_experiment():
|
117
|
+
"""Returns a test experiment."""
|
118
|
+
return Suite([
|
119
|
+
TestEvaluation(lm=TestLLM(offset=0)),
|
120
|
+
TestEvaluation(lm=TestLLM(offset=pg.oneof(range(5)))),
|
121
|
+
])
|
122
|
+
|
123
|
+
|
124
|
+
def test_experiment_with_example_checkpointing_error():
|
125
|
+
"""Returns a test experiment with example checkpointing error."""
|
126
|
+
return TestEvaluationWithExampleCheckpointingError()
|
127
|
+
|
128
|
+
|
129
|
+
def test_experiment_with_example_html_generation_error():
|
130
|
+
"""Returns a test experiment with bad example HTML."""
|
131
|
+
return TestEvaluationWithExampleHtmlGenerationError()
|
132
|
+
|
133
|
+
|
134
|
+
def test_experiment_with_index_html_generation_error():
|
135
|
+
"""Returns a test experiment with bad index HTML."""
|
136
|
+
return TestEvaluationWithIndexHtmlGenerationError()
|