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
@@ -0,0 +1,225 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: langfun
|
3
|
+
Version: 0.1.2.dev202501140804
|
4
|
+
Summary: Langfun: Language as Functions.
|
5
|
+
Home-page: https://github.com/google/langfun
|
6
|
+
Author: Langfun Authors
|
7
|
+
Author-email: langfun-authors@google.com
|
8
|
+
License: Apache License 2.0
|
9
|
+
Keywords: llm generative-ai machine-learning
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: Intended Audience :: Education
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Human Machine Interfaces
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
22
|
+
Description-Content-Type: text/markdown
|
23
|
+
License-File: LICENSE
|
24
|
+
Requires-Dist: pyglove>=0.4.5.dev202409110000
|
25
|
+
Requires-Dist: jinja2>=3.1.2
|
26
|
+
Requires-Dist: requests>=2.31.0
|
27
|
+
Provides-Extra: all
|
28
|
+
Requires-Dist: pyglove>=0.4.5.dev202409110000; extra == "all"
|
29
|
+
Requires-Dist: jinja2>=3.1.2; extra == "all"
|
30
|
+
Requires-Dist: requests>=2.31.0; extra == "all"
|
31
|
+
Requires-Dist: termcolor==1.1.0; extra == "all"
|
32
|
+
Requires-Dist: tqdm>=4.64.1; extra == "all"
|
33
|
+
Requires-Dist: google-auth>=2.16.0; extra == "all"
|
34
|
+
Requires-Dist: python-magic>=0.4.27; extra == "all"
|
35
|
+
Requires-Dist: python-docx>=0.8.11; extra == "all"
|
36
|
+
Requires-Dist: pillow>=10.0.0; extra == "all"
|
37
|
+
Requires-Dist: openpyxl>=3.1.0; extra == "all"
|
38
|
+
Requires-Dist: pandas>=2.0.3; extra == "all"
|
39
|
+
Provides-Extra: ui
|
40
|
+
Requires-Dist: termcolor==1.1.0; extra == "ui"
|
41
|
+
Requires-Dist: tqdm>=4.64.1; extra == "ui"
|
42
|
+
Provides-Extra: vertexai
|
43
|
+
Requires-Dist: google-auth>=2.16.0; extra == "vertexai"
|
44
|
+
Provides-Extra: mime
|
45
|
+
Requires-Dist: python-magic>=0.4.27; extra == "mime"
|
46
|
+
Requires-Dist: python-docx>=0.8.11; extra == "mime"
|
47
|
+
Requires-Dist: pillow>=10.0.0; extra == "mime"
|
48
|
+
Requires-Dist: openpyxl>=3.1.0; extra == "mime"
|
49
|
+
Requires-Dist: pandas>=2.0.3; extra == "mime"
|
50
|
+
Provides-Extra: mime-auto
|
51
|
+
Requires-Dist: python-magic>=0.4.27; extra == "mime-auto"
|
52
|
+
Provides-Extra: mime-docx
|
53
|
+
Requires-Dist: python-docx>=0.8.11; extra == "mime-docx"
|
54
|
+
Provides-Extra: mime-pil
|
55
|
+
Requires-Dist: pillow>=10.0.0; extra == "mime-pil"
|
56
|
+
Provides-Extra: mime-xlsx
|
57
|
+
Requires-Dist: openpyxl>=3.1.0; extra == "mime-xlsx"
|
58
|
+
Requires-Dist: pandas>=2.0.3; extra == "mime-xlsx"
|
59
|
+
Dynamic: author
|
60
|
+
Dynamic: author-email
|
61
|
+
Dynamic: classifier
|
62
|
+
Dynamic: description
|
63
|
+
Dynamic: description-content-type
|
64
|
+
Dynamic: home-page
|
65
|
+
Dynamic: keywords
|
66
|
+
Dynamic: license
|
67
|
+
Dynamic: provides-extra
|
68
|
+
Dynamic: requires-dist
|
69
|
+
Dynamic: summary
|
70
|
+
|
71
|
+
<div align="center">
|
72
|
+
<img src="https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg" width="520px" alt="logo"></img>
|
73
|
+
</div>
|
74
|
+
|
75
|
+
# Langfun
|
76
|
+
|
77
|
+
[](https://badge.fury.io/py/langfun)
|
78
|
+
[](https://codecov.io/gh/google/langfun)
|
79
|
+

|
80
|
+
|
81
|
+
[**Installation**](#install) | [**Getting started**](#hello-langfun) | [**Tutorial**](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb) | [**Discord community**](https://discord.gg/U6wPN9R68k)
|
82
|
+
|
83
|
+
## Introduction
|
84
|
+
|
85
|
+
Langfun is a [PyGlove](https://github.com/google/pyglove) powered library that
|
86
|
+
aims to *make language models (LM) fun to work with*. Its central principle is
|
87
|
+
to enable seamless integration between natural language and programming by
|
88
|
+
treating language as functions. Through the introduction of *Object-Oriented Prompting*,
|
89
|
+
Langfun empowers users to prompt LLMs using objects and types, offering enhanced
|
90
|
+
control and simplifying agent development.
|
91
|
+
|
92
|
+
To unlock the magic of Langfun, you can start with
|
93
|
+
[Langfun 101](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb). Notably, Langfun is compatible with popular LLMs such as Gemini, GPT,
|
94
|
+
Claude, all without the need for additional fine-tuning.
|
95
|
+
|
96
|
+
## Why Langfun?
|
97
|
+
|
98
|
+
Langfun is *powerful and scalable*:
|
99
|
+
|
100
|
+
* Seamless integration between natural language and computer programs.
|
101
|
+
* Modular prompts, which allows a natural blend of texts and modalities;
|
102
|
+
* Efficient for both request-based workflows and batch jobs;
|
103
|
+
* A powerful eval framework that thrives dimension explosions.
|
104
|
+
|
105
|
+
Langfun is *simple and elegant*:
|
106
|
+
|
107
|
+
* An intuitive programming model, graspable in 5 minutes;
|
108
|
+
* Plug-and-play into any Python codebase, making an immediate difference;
|
109
|
+
* Comprehensive LLMs under a unified API: Gemini, GPT, Claude, Llama3, and more.
|
110
|
+
* Designed for agile developement: offering intellisense, easy debugging, with minimal overhead;
|
111
|
+
|
112
|
+
## Hello, Langfun
|
113
|
+
|
114
|
+
```python
|
115
|
+
import langfun as lf
|
116
|
+
import pyglove as pg
|
117
|
+
|
118
|
+
from IPython import display
|
119
|
+
|
120
|
+
class Item(pg.Object):
|
121
|
+
name: str
|
122
|
+
color: str
|
123
|
+
|
124
|
+
class ImageDescription(pg.Object):
|
125
|
+
items: list[Item]
|
126
|
+
|
127
|
+
image = lf.Image.from_uri('https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Solar_system.jpg/1646px-Solar_system.jpg')
|
128
|
+
display.display(image)
|
129
|
+
|
130
|
+
desc = lf.query(
|
131
|
+
'Describe objects in {{my_image}} from top to bottom.',
|
132
|
+
ImageDescription,
|
133
|
+
lm=lf.llms.Gpt4o(api_key='<your-openai-api-key>'),
|
134
|
+
my_image=image,
|
135
|
+
)
|
136
|
+
print(desc)
|
137
|
+
```
|
138
|
+
*Output:*
|
139
|
+
|
140
|
+
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Solar_system.jpg/1646px-Solar_system.jpg" width="520px" alt="my_image"></img>
|
141
|
+
|
142
|
+
```
|
143
|
+
ImageDescription(
|
144
|
+
items = [
|
145
|
+
0 : Item(
|
146
|
+
name = 'Mercury',
|
147
|
+
color = 'Gray'
|
148
|
+
),
|
149
|
+
1 : Item(
|
150
|
+
name = 'Venus',
|
151
|
+
color = 'Yellow'
|
152
|
+
),
|
153
|
+
2 : Item(
|
154
|
+
name = 'Earth',
|
155
|
+
color = 'Blue and white'
|
156
|
+
),
|
157
|
+
3 : Item(
|
158
|
+
name = 'Moon',
|
159
|
+
color = 'Gray'
|
160
|
+
),
|
161
|
+
4 : Item(
|
162
|
+
name = 'Mars',
|
163
|
+
color = 'Red'
|
164
|
+
),
|
165
|
+
5 : Item(
|
166
|
+
name = 'Jupiter',
|
167
|
+
color = 'Brown and white'
|
168
|
+
),
|
169
|
+
6 : Item(
|
170
|
+
name = 'Saturn',
|
171
|
+
color = 'Yellowish-brown with rings'
|
172
|
+
),
|
173
|
+
7 : Item(
|
174
|
+
name = 'Uranus',
|
175
|
+
color = 'Light blue'
|
176
|
+
),
|
177
|
+
8 : Item(
|
178
|
+
name = 'Neptune',
|
179
|
+
color = 'Dark blue'
|
180
|
+
)
|
181
|
+
]
|
182
|
+
)
|
183
|
+
```
|
184
|
+
See [Langfun 101](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb) for more examples.
|
185
|
+
|
186
|
+
## Install
|
187
|
+
|
188
|
+
Langfun offers a range of features through [Extras](https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-extras), allowing users to install only what they need. The minimal installation of Langfun requires only [PyGlove](https://github.com/google/pyglove), [Jinja2](https://github.com/pallets/jinja/), and [requests](https://github.com/psf/requests). To install Langfun with its minimal dependencies, use:
|
189
|
+
|
190
|
+
```
|
191
|
+
pip install langfun
|
192
|
+
```
|
193
|
+
|
194
|
+
For a complete installation with all dependencies, use:
|
195
|
+
|
196
|
+
```
|
197
|
+
pip install langfun[all]
|
198
|
+
```
|
199
|
+
|
200
|
+
To install a nightly build, include the `--pre` flag, like this:
|
201
|
+
|
202
|
+
```
|
203
|
+
pip install langfun[all] --pre
|
204
|
+
```
|
205
|
+
|
206
|
+
If you want to customize your installation, you can select specific features using package names like `langfun[X1, X2, ..., Xn]`, where `Xi` corresponds to a tag from the list below:
|
207
|
+
|
208
|
+
| Tag | Description |
|
209
|
+
| ------------------- | ---------------------------------------- |
|
210
|
+
| all | All Langfun features. |
|
211
|
+
| vertexai | VertexAI access. |
|
212
|
+
| mime | All MIME supports. |
|
213
|
+
| mime-auto | Automatic MIME type detection. |
|
214
|
+
| mime-docx | DocX format support. |
|
215
|
+
| mime-pil | Image support for PIL. |
|
216
|
+
| mime-xlsx | XlsX format support. |
|
217
|
+
| ui | UI enhancements |
|
218
|
+
|
219
|
+
|
220
|
+
For example, to install a nightly build that includes VertexAI access, full modality support, and UI enhancements, use:
|
221
|
+
```
|
222
|
+
pip install langfun[vertexai,mime,ui] --pre
|
223
|
+
```
|
224
|
+
|
225
|
+
*Disclaimer: this is not an officially supported Google product.*
|
@@ -0,0 +1,153 @@
|
|
1
|
+
langfun/__init__.py,sha256=fhfPXpHN7GoGqixpFfqhQkYxFs_siP_LhbjZhd3lhio,2497
|
2
|
+
langfun/core/__init__.py,sha256=oo81OUA4Xy2q7icxcxAMicVzbla5gMDf9Nzw_iIAkis,4627
|
3
|
+
langfun/core/component.py,sha256=HVrEoTL1Y01iqOHC3FYdbAOnffqfHHtGJXoK1vkdEwo,11583
|
4
|
+
langfun/core/component_test.py,sha256=sG-T2wpvBfHqWGZE7sc4NayJj2aj5QFBzSwFiwrGEIc,10376
|
5
|
+
langfun/core/concurrent.py,sha256=4CqOlH9YrtrK-Jijp09hLX7AYxRYL8slpy-tL2aqnIM,33121
|
6
|
+
langfun/core/concurrent_test.py,sha256=0ucEYxPgTErOOK1TIN-TSqZphHS1Vl1VssyQP49cpOI,17997
|
7
|
+
langfun/core/console.py,sha256=bGwuJZRs_9NNKY1KmJjIZLeoQ_fL0BikAJPLDVdp1hw,2558
|
8
|
+
langfun/core/console_test.py,sha256=pBOcuNMJdVELywvroptfcRtJMsegMm3wSlHAL2TdxVk,1679
|
9
|
+
langfun/core/langfunc.py,sha256=G50YgoVZ0y1GFw2ev41MlOqr6qa8YakbvNC0h_E0PiA,11140
|
10
|
+
langfun/core/langfunc_test.py,sha256=fKIAqcSNI_7M6nwoZW77HEam8Oa6vcWhsCNgVJanzb4,8822
|
11
|
+
langfun/core/language_model.py,sha256=Hfs-SIxiO2rK7BvPmnOuYTrT4jbmFiV31NMmI-mkPzY,36635
|
12
|
+
langfun/core/language_model_test.py,sha256=jic5w8w9Mie43e6zwjXDwLV-8Cqc1HxHP0GKkXzeL8I,33666
|
13
|
+
langfun/core/logging.py,sha256=W3mLEMXdo210Q5OX3a1ZTc4nU-xMy73-IfNKnsA-RFo,8051
|
14
|
+
langfun/core/logging_test.py,sha256=N7-YvSXC8zvnr2SNwWHOykn1CFmqvIuTLDgn41Ku9JU,6642
|
15
|
+
langfun/core/memory.py,sha256=f-asN1F7Vehgdn_fK84v73GrEUOxRtaW934keutTKjk,2416
|
16
|
+
langfun/core/message.py,sha256=16oiMpg9O9VKrgpfrvJrfvga3n3FzUuD_zdWb9nvSWA,25686
|
17
|
+
langfun/core/message_test.py,sha256=AAKOZitp-Pu_w2x98zV6hQhll2ZTmWdtW0vmT3MyOjI,36165
|
18
|
+
langfun/core/modality.py,sha256=K8pUGuMpfWcOtVcXC_OqVjro1-RhHF6ddQni61DuYzM,4166
|
19
|
+
langfun/core/modality_test.py,sha256=0WL_yd3B4K-FviWdSpDnOwj0f9TQI0v9t6X0vWvvJbo,2415
|
20
|
+
langfun/core/natural_language.py,sha256=3ynSnaYQnjE60LIPK5fyMgdIjubnPYZwzGq4rWPeloE,1177
|
21
|
+
langfun/core/natural_language_test.py,sha256=LHGU_1ytbkGuSZQFIFP7vP3dBlcY4-A12fT6dbjUA0E,1424
|
22
|
+
langfun/core/sampling.py,sha256=SCnS5PFJWNVxSKvSkSCNRUmruvScun8UcNN4gafuXcw,5866
|
23
|
+
langfun/core/sampling_test.py,sha256=U7PANpMsl9E_pa4_Y4FzesSjcwg-u-LKHGCWSgv-8FY,3663
|
24
|
+
langfun/core/subscription.py,sha256=euawEuSZP-BHydaT-AQpfYFL0m5pWPGcW0upFhrojqc,10930
|
25
|
+
langfun/core/subscription_test.py,sha256=Y4ZdbZEwm83YNZBxHff0QR4QUa4rdaNXA3_jfIcArBo,8717
|
26
|
+
langfun/core/template.py,sha256=jNhYSrbLIn9kZOa03w5QZbyjgfnzJzE_ZrrMvvWY4t4,24929
|
27
|
+
langfun/core/template_test.py,sha256=g7x4mgNIAXEEj-4W1D5whGfl5YikLEQoylKPzaeDomk,17069
|
28
|
+
langfun/core/agentic/__init__.py,sha256=ndoDX0sAYsa3eVdXuu6nB-a-BH5TaK3urW6zAaFiyVs,1110
|
29
|
+
langfun/core/agentic/action.py,sha256=yW5-2NRHIrQmmQEYmL83aIdSwaRfUez9mqCbME_aBWQ,25391
|
30
|
+
langfun/core/agentic/action_eval.py,sha256=ZtjTh34S7XPIUqandQ0YwAtzw-S7ofuZ7rRXnRbUMdQ,4424
|
31
|
+
langfun/core/agentic/action_eval_test.py,sha256=tRUkWmOE9p0rpNOq19xAY2oDEnYsEEykjg6sUpAwJk0,2832
|
32
|
+
langfun/core/agentic/action_test.py,sha256=Gu7P5XQvzqbKawn2jjyTpWaARzzhzO04KkC1TuBnUnw,4612
|
33
|
+
langfun/core/coding/__init__.py,sha256=5utju_fwEsImaiftx4oXKl9FAM8p281k8-Esdh_-m1w,835
|
34
|
+
langfun/core/coding/python/__init__.py,sha256=K6jb2le6Hq-aaKqAF4pGW5JRwSyO-RnUTMIxxaVcsNA,1540
|
35
|
+
langfun/core/coding/python/correction.py,sha256=7zBedlhQKMPA4cfchUMxAOFl6Zl5RqCyllRHGWys40s,7092
|
36
|
+
langfun/core/coding/python/correction_test.py,sha256=sie88lAbsV15bvkRcYC88pgToybZYXI32Xmg_ym5V1A,4175
|
37
|
+
langfun/core/coding/python/execution.py,sha256=tsXnJ-11RqNDro0C-6LwbHkqPuNVJ_cLxAq8-C5Wz20,4442
|
38
|
+
langfun/core/coding/python/execution_test.py,sha256=NynCGNP0gZ08fqmmQIJjJu6HmhkNOSkgWUXUCNQ0_yg,5990
|
39
|
+
langfun/core/coding/python/generation.py,sha256=sA6t97qBflO3WtuL9axknEVQPgqXHeqamTQitc_hL4k,8446
|
40
|
+
langfun/core/coding/python/generation_test.py,sha256=dcF5ef1UApzRfTpvICiChpynkzZ1mDsE0DvH0iMpTvg,2743
|
41
|
+
langfun/core/coding/python/parsing.py,sha256=jvGDIwoaY3mdGXeFhjP27w0ukO0TtdCC7G4ODVNp8S4,4554
|
42
|
+
langfun/core/coding/python/parsing_test.py,sha256=PIexYpSEhgNaSd4T6QYWzWHzm3sL4VhQJ4dhdvJAQk8,5005
|
43
|
+
langfun/core/eval/__init__.py,sha256=OEXr1ZRuvLuhJJfuQ1ZWQ-SvYzjyrtiAAEogYaB7E6o,1933
|
44
|
+
langfun/core/eval/base.py,sha256=XXerMVkK4wREo7K1_aCyay6vDjw3mfs389XThAdzv50,75768
|
45
|
+
langfun/core/eval/base_test.py,sha256=-LsIV9DXlDal0EnOlaWpibJvfef0NbxtZAm0OH_abAE,27189
|
46
|
+
langfun/core/eval/matching.py,sha256=AVKkGoc-BaHEzgSBamaAk3194TgqckDe_dinpS6LrXI,9323
|
47
|
+
langfun/core/eval/matching_test.py,sha256=QCoYEuf4b_1bkHqUCuRzKMbXHrV3AB2FCOBivo1stC4,5249
|
48
|
+
langfun/core/eval/patching.py,sha256=R0s2eAd1m97exQt06dmUL0V_MBG0W2Hxg7fhNB7cXW0,3866
|
49
|
+
langfun/core/eval/patching_test.py,sha256=8kCd54Egjju22FMgtJuxEsrXkW8ifs-UUBHtrCG1L6w,4775
|
50
|
+
langfun/core/eval/scoring.py,sha256=_DvnlgI1SdRVaOojao_AkV3pnenfCPOqyhvlg-Sw-5M,6322
|
51
|
+
langfun/core/eval/scoring_test.py,sha256=O8olHbrUEg60gMxwOkWzKBJZpZoUlmVnBANX5Se2SXM,4546
|
52
|
+
langfun/core/eval/v2/__init__.py,sha256=qoa6zKdFXOFyCX6vay6OdgPf1eUhYGoHYAxe35qECGk,1628
|
53
|
+
langfun/core/eval/v2/checkpointing.py,sha256=u-MrnwQbm0T-BDcn9pPXs_FeKPzMYm1-pVos0DiTqgM,11769
|
54
|
+
langfun/core/eval/v2/checkpointing_test.py,sha256=R-R8SFzworuYnMmGGcvE9f4oiYkb8HMoZ0m4euF3pus,8466
|
55
|
+
langfun/core/eval/v2/eval_test_helper.py,sha256=A9w0FbRKieB3yym8x34kY24FfptHrp7m6_z3i8HXSFI,3922
|
56
|
+
langfun/core/eval/v2/evaluation.py,sha256=kARf0pG6SrpN__IMeFsw8DV_5mT_tl52pJrr6wIZdsw,22482
|
57
|
+
langfun/core/eval/v2/evaluation_test.py,sha256=0l0DqJTF8PZGA2Q1OlaF4YIax4ZhSk0ewOCvuVW1XAk,6658
|
58
|
+
langfun/core/eval/v2/example.py,sha256=4-LNr8Ke-fhaF6gyeXX4JMyw0s8YkVTC63pXZ-CXKrE,10144
|
59
|
+
langfun/core/eval/v2/example_test.py,sha256=1DNm6EuyZOq827DKvf3oTRVFkMNM_qTnLUpvOjpgz5I,3419
|
60
|
+
langfun/core/eval/v2/experiment.py,sha256=qYWx22KMfoUa4ieSq1bt7NE8L9dgoiJpuNOQGT1IBQw,32723
|
61
|
+
langfun/core/eval/v2/experiment_test.py,sha256=CqpDsDai2DiIU-SzpVmqFzM_ZxxkVYKd0Gr1Uvcvkuw,13546
|
62
|
+
langfun/core/eval/v2/metric_values.py,sha256=_B905bC-jxrYPLSEcP2M8MaHZOVMz_bVrUw8YC4arCE,4660
|
63
|
+
langfun/core/eval/v2/metric_values_test.py,sha256=ab2oF_HsIwrSy459108ggyjgefHSPn8UVILR4dRwx14,2634
|
64
|
+
langfun/core/eval/v2/metrics.py,sha256=bl8i6u-ZHRBz4hAc3LzsZ2Dc7ZRQcuTYeUhhH-GxfF0,10628
|
65
|
+
langfun/core/eval/v2/metrics_test.py,sha256=p4FzLJsE8XAzAQuyP9hfEf9YeKWZ__PO_ue8a9P0-cc,6082
|
66
|
+
langfun/core/eval/v2/progress.py,sha256=azZgssQgNdv3IgjKEaQBuGI5ucFDNbdi02P4z_nQ8GE,10292
|
67
|
+
langfun/core/eval/v2/progress_test.py,sha256=YU7VHzmy5knPZwj9vpBN3rQQH2tukj9eKHkuBCI62h8,2540
|
68
|
+
langfun/core/eval/v2/progress_tracking.py,sha256=l9fEkz4oP5McpZzf72Ua7PYm3lAWtRru7gRWNf8H0ms,6083
|
69
|
+
langfun/core/eval/v2/progress_tracking_test.py,sha256=fouMVJkFJqHjbhQJngGLGCmA9x3n0dU4USI2dY163mg,2291
|
70
|
+
langfun/core/eval/v2/reporting.py,sha256=QOp5jX761Esvi5w_UIRLDqPY_XRO6ru02-DOrdqVK_4,8392
|
71
|
+
langfun/core/eval/v2/reporting_test.py,sha256=UmYSAQvD3AIXsSyWQ-WD2uLtEISYpmBeoKY5u5Qwc8E,5696
|
72
|
+
langfun/core/eval/v2/runners.py,sha256=DKEmSlGXjOXKWFdBhTpLy7tMsBHZHd1Brl3hWIngsSQ,15931
|
73
|
+
langfun/core/eval/v2/runners_test.py,sha256=A37fKK2MvAVTiShsg_laluJzJ9AuAQn52k7HPbfD0Ks,11666
|
74
|
+
langfun/core/llms/__init__.py,sha256=Ntr0kvHc17VEZ5EV9fCoYY1kzRvQxCoZrtDRYNiMWCs,6742
|
75
|
+
langfun/core/llms/anthropic.py,sha256=a5MmnFsBA0CbfvwzXT1v_0fqLRMrhUNdh1tx6469PQ4,14357
|
76
|
+
langfun/core/llms/anthropic_test.py,sha256=-2U4kc_pgBM7wqxu8RuxzyHPGww1EAWqKUvN4PW8Btw,8058
|
77
|
+
langfun/core/llms/compositional.py,sha256=csW_FLlgL-tpeyCOTVvfUQkMa_zCN5Y2I-YbSNuK27U,2872
|
78
|
+
langfun/core/llms/compositional_test.py,sha256=4eTnOer-DncRKGaIJW2ZQQMLnt5r2R0UIx_DYOvGAQo,2027
|
79
|
+
langfun/core/llms/deepseek.py,sha256=Y7DlLUWrukbPVyBMesppd-m75Q-PxD0b3KnMKaoY_8I,3744
|
80
|
+
langfun/core/llms/deepseek_test.py,sha256=dS72i52bwMpCN4dJDvpJI59AnNChpwxS5eYYFrhGh90,1843
|
81
|
+
langfun/core/llms/fake.py,sha256=gCHBYBLvBCsC78HI1hpoqXCS-p1FMTgY1P1qh_sGBPk,3070
|
82
|
+
langfun/core/llms/fake_test.py,sha256=2h13qkwEz_JR0mtUDPxdAhQo7MueXaFSwsD2DIRDW9g,7653
|
83
|
+
langfun/core/llms/gemini.py,sha256=tfM4vrt0WnvnrxRhWXZWh7Gp8dYYfMnSbi9uOstkSak,17399
|
84
|
+
langfun/core/llms/gemini_test.py,sha256=2ERhYWCJwnfDTQbCaZHFuB1TdWJFrOBS7yyCBInIdQk,6129
|
85
|
+
langfun/core/llms/google_genai.py,sha256=85Vmx5QmsziON03PRsFQINSu5NF6pAAuFFhUdDteWGc,3662
|
86
|
+
langfun/core/llms/google_genai_test.py,sha256=JZf_cbQ4GGGpwiQCLjFJn7V4jxBBqgZhIx91AzbGKVo,1250
|
87
|
+
langfun/core/llms/groq.py,sha256=oGxyyCi5TtMVu2POdO8pXS7pK4Es56FtqjghZIGYopc,7579
|
88
|
+
langfun/core/llms/groq_test.py,sha256=9aOD3nO4dEoH57B-5iOr5DQjG0vyv1jzFtAe7HfoiNg,1963
|
89
|
+
langfun/core/llms/llama_cpp.py,sha256=Z7P3gc4xeIjc2bX0Ey1y5EUYJVMnMa2Q67PZ9iye9sE,1409
|
90
|
+
langfun/core/llms/llama_cpp_test.py,sha256=wfTO7nmUwL65U2kK9P9fcMt92JjNDuVia4G1E7znf_4,1086
|
91
|
+
langfun/core/llms/openai.py,sha256=CHUg8c0FE30LZkhvj0Kc8w0oqckbZhrp45GA94HWPs8,16614
|
92
|
+
langfun/core/llms/openai_compatible.py,sha256=MF9JCc0uTPkIK95uvQTMIBXk4z_xKQMZqQHFaVmXwcA,5898
|
93
|
+
langfun/core/llms/openai_compatible_test.py,sha256=0uFYhCiuHo2Wrlgj16-GRG6rW8P6EaHCUguL3jS0QJ8,16708
|
94
|
+
langfun/core/llms/openai_test.py,sha256=m85YjGCvWvV5ZYagjC0FqI0FcqyCEVCbUUs8Wm3iUrc,2475
|
95
|
+
langfun/core/llms/rest.py,sha256=sWbYUV8S3SuOg9giq7xwD-xDRfaF7NP_ig7bI52-Rj4,3442
|
96
|
+
langfun/core/llms/rest_test.py,sha256=zWGiI08f9gXsoQPJS9TlX1zD2uQLrJUB-1VpAJXRHfs,3475
|
97
|
+
langfun/core/llms/vertexai.py,sha256=MuwLPTJ6-9x2uRDCSM1_biPK6M76FFlL1ezf5OmobDA,5504
|
98
|
+
langfun/core/llms/vertexai_test.py,sha256=iXjmQs7TNiwcueoaRGpdp4KnASkDJaTP__Z9QroN8zQ,1787
|
99
|
+
langfun/core/llms/cache/__init__.py,sha256=QAo3InUMDM_YpteNnVCSejI4zOsnjSMWKJKzkb3VY64,993
|
100
|
+
langfun/core/llms/cache/base.py,sha256=rt3zwmyw0y9jsSGW-ZbV1vAfLxQ7_3AVk0l2EySlse4,3918
|
101
|
+
langfun/core/llms/cache/in_memory.py,sha256=i58oiQL28RDsq37dwqgVpC2mBETJjIEFS20yHiV5MKU,5185
|
102
|
+
langfun/core/llms/cache/in_memory_test.py,sha256=V2UPeu5co5vUwSkjekCH1B1iLm9qQKPaacvP6VW3GTg,10388
|
103
|
+
langfun/core/memories/__init__.py,sha256=HpghfZ-w1NQqzJXBx8Lz0daRhB2rcy2r9Xm491SBhC4,773
|
104
|
+
langfun/core/memories/conversation_history.py,sha256=c9amD8hCxGFiZuVAzkP0dOMWSp8L90uvwkOejjuBqO0,1835
|
105
|
+
langfun/core/memories/conversation_history_test.py,sha256=AaW8aNoFjxNusanwJDV0r3384Mg0eAweGmPx5DIkM0Y,2052
|
106
|
+
langfun/core/modalities/__init__.py,sha256=F8P72IwFiTpEseTR2tYEJyQMlDW7fd9csvGJquLKJNg,1269
|
107
|
+
langfun/core/modalities/audio.py,sha256=qCrVCX690SG0ps-ZfOtNWvHn_CmdJsmxF7GySScWUqY,964
|
108
|
+
langfun/core/modalities/audio_test.py,sha256=yyGEBYqMXmNs_F2dEtj-PX8HE040vqh-YQppsvdxPw4,2025
|
109
|
+
langfun/core/modalities/image.py,sha256=ovcX8NLBNv8WzxAdhQ-u4VQfHVBkWijRj_oiNwhE9lk,1768
|
110
|
+
langfun/core/modalities/image_test.py,sha256=XMgtJXY75R5eo0CZ222D1QUy57_hESnttmCGWwDLt7k,3824
|
111
|
+
langfun/core/modalities/mime.py,sha256=xZpnENHqwIUBLbT3s3izJvAPnw3XTtXe2v1y4mz9UkI,7856
|
112
|
+
langfun/core/modalities/mime_test.py,sha256=Lg21nKFi--a884gnI7tFS4cHnwByEEhWg4Ugsr-UCbw,5277
|
113
|
+
langfun/core/modalities/ms_office.py,sha256=0PnM6W9SovVfJNd4XCpUfOcGBuvj4hlA1zqPjdsJNFM,3725
|
114
|
+
langfun/core/modalities/ms_office_test.py,sha256=rrDBx51ELAqRaUX6Y6tgg0k3tEFHOlRMfUpeULD7mlo,87868
|
115
|
+
langfun/core/modalities/pdf.py,sha256=mfaeCbUA4JslFVTARiJh8hW7imvL4tLVw9gUhO5bAZA,727
|
116
|
+
langfun/core/modalities/pdf_test.py,sha256=ulZ0FbnlsU0wkrdckJ4ONZPTYRyMPO9Aob1UO6FXygk,1950
|
117
|
+
langfun/core/modalities/video.py,sha256=vI9apcHIHGyp90i34Srg7S3G6IBDtDCk8qiXhwRQmkw,967
|
118
|
+
langfun/core/modalities/video_test.py,sha256=7OXZoohKMYjt7vrJUdPb553HLyl1oBOKRgzBePFv68Q,2042
|
119
|
+
langfun/core/structured/__init__.py,sha256=3Wb4ks14D5E5z1nQ5trXSXiLqFN5E_3HvcEJQAfFRl0,3220
|
120
|
+
langfun/core/structured/completion.py,sha256=yW95Yd4wbt964I5wIyPUtIVeeqeZbA6HidLgN0ZpWm0,8110
|
121
|
+
langfun/core/structured/completion_test.py,sha256=VtYfI3ciVSSWbi8x3l1WwpWK-Ofn2DMHYEEqm2uTzhw,19314
|
122
|
+
langfun/core/structured/description.py,sha256=6BztYOiucPkF4CrTQtPLPJo1gN2dwnKmaJW83GBf4H0,5213
|
123
|
+
langfun/core/structured/description_test.py,sha256=UxaXnKKP7TnyPDPUyf3U-zPE0TvLlIP6DGr8thjcePw,7365
|
124
|
+
langfun/core/structured/function_generation.py,sha256=g7AOR_e8HxFU6n6Df750aGkgMgV1KExLZMAz0yd5Agg,8555
|
125
|
+
langfun/core/structured/function_generation_test.py,sha256=LaXYDXf9GlqUrR6v_gtmK_H4kxzonmU7SYbn7XXMgjU,12128
|
126
|
+
langfun/core/structured/mapping.py,sha256=of-EeBq0RgmkiUaSk2rVEDVCzgn_wXU8tRke7NCcC6E,13649
|
127
|
+
langfun/core/structured/mapping_test.py,sha256=OntYvfDitAf0tAnzQty3YS90vyEn6FY1Mi93r_ViEk8,9594
|
128
|
+
langfun/core/structured/parsing.py,sha256=MGvI7ypXlwfzr5XB8_TFU9Ei0_5reYqkWkv64eAy0EA,12015
|
129
|
+
langfun/core/structured/parsing_test.py,sha256=kNPrhpdPY3iWhUld0TFYU-Zgn44wC0d6YuQ9XdVbQ8o,22346
|
130
|
+
langfun/core/structured/querying.py,sha256=nqvsfMS_KLv5EvO0_VAGEHwY4pHy4S0CvJmeV0HBXlM,23066
|
131
|
+
langfun/core/structured/querying_test.py,sha256=YlC4s9LVChfhGZzaXGW1UYlcBnAjNOunu4SLl5_p7PQ,32054
|
132
|
+
langfun/core/structured/schema.py,sha256=_iqhHEGDQsHk0AsybWnK44sOspTWkKJjci781PWD7x0,27988
|
133
|
+
langfun/core/structured/schema_generation.py,sha256=3AcuKvv3VOtKY5zMVqODrxfOuDxzoZtGeBxHlOWDOWw,5308
|
134
|
+
langfun/core/structured/schema_generation_test.py,sha256=RM9s71kMNg2jTePwInkiW9fK1ACN37eyPeF8OII-0zw,2950
|
135
|
+
langfun/core/structured/schema_test.py,sha256=RjYhwTgktQgyqAjzLvo967nTiIK9KWgP-aNGg4e7ihE,25258
|
136
|
+
langfun/core/structured/scoring.py,sha256=Y7Jqs5VVjUQLF_9Z1uIY_dw5zasv2FF52Cz-cxGMsro,5857
|
137
|
+
langfun/core/structured/scoring_test.py,sha256=QvlwDAzwuamKL5tCotm1L3Sx0cs3idoNK4aIEhaO4Yk,2272
|
138
|
+
langfun/core/structured/tokenization.py,sha256=-b4_693quHeYn2AqndwucuXNmhd5NVXVTU3mmDane98,2189
|
139
|
+
langfun/core/structured/tokenization_test.py,sha256=dVW30kGYkX2HNtiRZe1oTmXFP7iIK6PrlKCttZ3QXe4,1311
|
140
|
+
langfun/core/templates/__init__.py,sha256=bO0eMsVJbi7sxEB2YlInKRQ2EVP-RyyKUwcD-8msuN4,927
|
141
|
+
langfun/core/templates/completion.py,sha256=mUqZHOEV3ag6-A08XghpeEltcrBvCDxXP004eDDfeag,1931
|
142
|
+
langfun/core/templates/completion_test.py,sha256=vGnjnM38UHyVDUyaUYtmp20s9KBGOdbPVsX-H-ET11E,1636
|
143
|
+
langfun/core/templates/conversation.py,sha256=dTy_fs3g92d3vP09bACGJ_zJ3b8-OzA8vsKgUDoB76o,2866
|
144
|
+
langfun/core/templates/conversation_test.py,sha256=HCD5f1sgmSGqL3OGe7hEctjRdcFjcmkz3NV1ArexNYI,3942
|
145
|
+
langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fikKhwhzwhpKI,1460
|
146
|
+
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
147
|
+
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
148
|
+
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
149
|
+
langfun-0.1.2.dev202501140804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
150
|
+
langfun-0.1.2.dev202501140804.dist-info/METADATA,sha256=x6f3Dt7iwPgwothAHIYVh629F01uM9B5EJr19nmbPLo,8172
|
151
|
+
langfun-0.1.2.dev202501140804.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
152
|
+
langfun-0.1.2.dev202501140804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
153
|
+
langfun-0.1.2.dev202501140804.dist-info/RECORD,,
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# Copyright 2023 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
|
-
"""Python code errors."""
|
15
|
-
|
16
|
-
import io
|
17
|
-
import sys
|
18
|
-
import textwrap
|
19
|
-
import traceback
|
20
|
-
import langfun.core as lf
|
21
|
-
|
22
|
-
|
23
|
-
class CodeError(RuntimeError):
|
24
|
-
"""Python code error."""
|
25
|
-
|
26
|
-
def __init__(
|
27
|
-
self,
|
28
|
-
code: str,
|
29
|
-
cause: Exception,
|
30
|
-
):
|
31
|
-
self.code = code
|
32
|
-
self.cause = cause
|
33
|
-
|
34
|
-
# Figure out the starting and ending line numbers of the erratic code.
|
35
|
-
lineno = None
|
36
|
-
end_lineno = None
|
37
|
-
if isinstance(cause, SyntaxError):
|
38
|
-
lineno = cause.lineno
|
39
|
-
end_lineno = cause.end_lineno
|
40
|
-
elif not isinstance(cause, TimeoutError):
|
41
|
-
tb = sys.exc_info()[2]
|
42
|
-
frames = traceback.extract_tb(tb, limit=5)
|
43
|
-
for f in frames:
|
44
|
-
if not f.filename or f.filename == '<string>':
|
45
|
-
lineno = f.lineno
|
46
|
-
end_lineno = lineno
|
47
|
-
break
|
48
|
-
self.lineno = lineno
|
49
|
-
self.end_lineno = end_lineno
|
50
|
-
|
51
|
-
def __str__(self):
|
52
|
-
return self.format(include_complete_code=True)
|
53
|
-
|
54
|
-
def code_lines(self, start_line: int, end_line: int):
|
55
|
-
"""Returns code lines ."""
|
56
|
-
return '\n'.join(self.code.split('\n')[start_line:end_line])
|
57
|
-
|
58
|
-
def format(self, include_complete_code: bool = True):
|
59
|
-
"""Formats the code error."""
|
60
|
-
r = io.StringIO()
|
61
|
-
error_message = str(self.cause).rstrip()
|
62
|
-
if 'line' not in error_message and self.lineno is not None:
|
63
|
-
error_message += f' (<unknown>, line {self.lineno})'
|
64
|
-
r.write(
|
65
|
-
lf.colored(
|
66
|
-
f'{self.cause.__class__.__name__}: {error_message}', 'magenta'))
|
67
|
-
|
68
|
-
if self.lineno is not None:
|
69
|
-
r.write('\n\n')
|
70
|
-
r.write(textwrap.indent(
|
71
|
-
lf.colored(
|
72
|
-
self.code_lines(self.lineno - 1, self.end_lineno), 'magenta'),
|
73
|
-
' ' * 2
|
74
|
-
))
|
75
|
-
r.write('\n')
|
76
|
-
|
77
|
-
if include_complete_code:
|
78
|
-
r.write('\n')
|
79
|
-
r.write(lf.colored('[Generated Code]', 'green', styles=['bold']))
|
80
|
-
r.write('\n\n')
|
81
|
-
r.write(lf.colored(' ```python\n', 'green'))
|
82
|
-
r.write(textwrap.indent(
|
83
|
-
lf.colored(self.code, 'green'),
|
84
|
-
' ' * 2
|
85
|
-
))
|
86
|
-
r.write(lf.colored('\n ```\n', 'green'))
|
87
|
-
return r.getvalue()
|
88
|
-
|
89
|
-
|
90
|
-
class SerializationError(RuntimeError):
|
91
|
-
"""Object serialization error."""
|
92
|
-
|
93
|
-
def __init__(self, message: str | None, cause: Exception):
|
94
|
-
self.message = message
|
95
|
-
self.cause = cause
|
96
|
-
|
97
|
-
def __str__(self):
|
98
|
-
r = io.StringIO()
|
99
|
-
cause_message = str(self.cause).rstrip()
|
100
|
-
if self.message:
|
101
|
-
r.write(lf.colored(self.message, 'magenta'))
|
102
|
-
r.write('\n\n')
|
103
|
-
r.write(
|
104
|
-
lf.colored(
|
105
|
-
f'{self.cause.__class__.__name__}: {cause_message}', 'magenta'
|
106
|
-
)
|
107
|
-
)
|
108
|
-
return r.getvalue()
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# Copyright 2023 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
|
-
"""Tests for code errors."""
|
15
|
-
|
16
|
-
import unittest
|
17
|
-
|
18
|
-
from langfun.core.coding.python import errors
|
19
|
-
from langfun.core.coding.python import execution
|
20
|
-
|
21
|
-
|
22
|
-
def code_error(code: str) -> errors.CodeError | None:
|
23
|
-
try:
|
24
|
-
execution.run(code, timeout=2)
|
25
|
-
return None
|
26
|
-
except errors.CodeError as e:
|
27
|
-
return e
|
28
|
-
|
29
|
-
|
30
|
-
class CodeErrorsTest(unittest.TestCase):
|
31
|
-
|
32
|
-
def test_format(self):
|
33
|
-
e = code_error(
|
34
|
-
"""
|
35
|
-
x = y + 1
|
36
|
-
"""
|
37
|
-
)
|
38
|
-
self.assertIn('[Generated Code]', str(e))
|
39
|
-
self.assertNotIn(
|
40
|
-
'[Generated Code]', e.format(include_complete_code=False))
|
41
|
-
|
42
|
-
def test_lineno(self):
|
43
|
-
self.assertEqual(
|
44
|
-
code_error(
|
45
|
-
"""
|
46
|
-
x = y + 1
|
47
|
-
"""
|
48
|
-
).lineno, 1)
|
49
|
-
self.assertEqual(
|
50
|
-
code_error(
|
51
|
-
"""
|
52
|
-
x = 1
|
53
|
-
for i of x:
|
54
|
-
y = i
|
55
|
-
"""
|
56
|
-
).lineno, 2)
|
57
|
-
self.assertEqual(
|
58
|
-
code_error(
|
59
|
-
"""
|
60
|
-
x = 1
|
61
|
-
y = 2
|
62
|
-
raise ValueError
|
63
|
-
"""
|
64
|
-
).lineno, 3)
|
65
|
-
|
66
|
-
def test_lineno_in_error_message(self):
|
67
|
-
def assert_lineno(code):
|
68
|
-
e = code_error(code)
|
69
|
-
self.assertIn('line', e.format(include_complete_code=False))
|
70
|
-
|
71
|
-
assert_lineno(
|
72
|
-
"""
|
73
|
-
x = y + 1
|
74
|
-
"""
|
75
|
-
)
|
76
|
-
assert_lineno(
|
77
|
-
"""
|
78
|
-
x = 1
|
79
|
-
y = 2
|
80
|
-
"""
|
81
|
-
)
|
82
|
-
assert_lineno(
|
83
|
-
"""
|
84
|
-
raise ValueError()
|
85
|
-
"""
|
86
|
-
)
|
87
|
-
|
88
|
-
|
89
|
-
class SerializationErrorTest(unittest.TestCase):
|
90
|
-
|
91
|
-
def test_str(self):
|
92
|
-
e = errors.SerializationError(
|
93
|
-
'Output cannot be serialized.', ValueError('abc'))
|
94
|
-
self.assertIn('Output cannot be serialized', str(e))
|
95
|
-
self.assertIn('ValueError: abc', str(e))
|
96
|
-
|
97
|
-
|
98
|
-
if __name__ == '__main__':
|
99
|
-
unittest.main()
|