langfun 0.1.2.dev202501060804__py3-none-any.whl → 0.1.2.dev202501090804__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/core/__init__.py +0 -5
- langfun/core/coding/python/correction.py +4 -3
- langfun/core/coding/python/errors.py +10 -9
- langfun/core/coding/python/execution.py +23 -12
- langfun/core/coding/python/execution_test.py +21 -2
- langfun/core/coding/python/generation.py +18 -9
- langfun/core/concurrent.py +2 -3
- langfun/core/console.py +8 -3
- langfun/core/eval/base.py +2 -3
- langfun/core/eval/v2/reporting.py +8 -4
- langfun/core/language_model.py +7 -4
- langfun/core/language_model_test.py +15 -0
- langfun/core/llms/__init__.py +4 -0
- langfun/core/llms/deepseek.py +261 -0
- langfun/core/llms/deepseek_test.py +438 -0
- langfun/core/llms/google_genai.py +1 -0
- langfun/core/llms/openai.py +5 -0
- langfun/core/llms/vertexai.py +6 -2
- langfun/core/llms/vertexai_test.py +1 -1
- langfun/core/structured/mapping.py +13 -13
- langfun/core/structured/mapping_test.py +2 -2
- langfun/core/structured/schema.py +16 -8
- {langfun-0.1.2.dev202501060804.dist-info → langfun-0.1.2.dev202501090804.dist-info}/METADATA +13 -2
- {langfun-0.1.2.dev202501060804.dist-info → langfun-0.1.2.dev202501090804.dist-info}/RECORD +27 -27
- {langfun-0.1.2.dev202501060804.dist-info → langfun-0.1.2.dev202501090804.dist-info}/WHEEL +1 -1
- langfun/core/text_formatting.py +0 -168
- langfun/core/text_formatting_test.py +0 -65
- {langfun-0.1.2.dev202501060804.dist-info → langfun-0.1.2.dev202501090804.dist-info}/LICENSE +0 -0
- {langfun-0.1.2.dev202501060804.dist-info → langfun-0.1.2.dev202501090804.dist-info}/top_level.txt +0 -0
langfun/core/llms/openai.py
CHANGED
@@ -553,26 +553,31 @@ class GptO1(OpenAI):
|
|
553
553
|
|
554
554
|
model = 'o1'
|
555
555
|
multimodal = True
|
556
|
+
timeout = None
|
556
557
|
|
557
558
|
|
558
559
|
class GptO1Preview(OpenAI):
|
559
560
|
"""GPT-O1."""
|
560
561
|
model = 'o1-preview'
|
562
|
+
timeout = None
|
561
563
|
|
562
564
|
|
563
565
|
class GptO1Preview_20240912(OpenAI): # pylint: disable=invalid-name
|
564
566
|
"""GPT O1."""
|
565
567
|
model = 'o1-preview-2024-09-12'
|
568
|
+
timeout = None
|
566
569
|
|
567
570
|
|
568
571
|
class GptO1Mini(OpenAI):
|
569
572
|
"""GPT O1-mini."""
|
570
573
|
model = 'o1-mini'
|
574
|
+
timeout = None
|
571
575
|
|
572
576
|
|
573
577
|
class GptO1Mini_20240912(OpenAI): # pylint: disable=invalid-name
|
574
578
|
"""GPT O1-mini."""
|
575
579
|
model = 'o1-mini-2024-09-12'
|
580
|
+
timeout = None
|
576
581
|
|
577
582
|
|
578
583
|
class Gpt4(OpenAI):
|
langfun/core/llms/vertexai.py
CHANGED
@@ -90,6 +90,8 @@ class VertexAI(gemini.Gemini):
|
|
90
90
|
)
|
91
91
|
|
92
92
|
self._project = project
|
93
|
+
self._location = location
|
94
|
+
|
93
95
|
credentials = self.credentials
|
94
96
|
if credentials is None:
|
95
97
|
# Use default credentials.
|
@@ -114,9 +116,10 @@ class VertexAI(gemini.Gemini):
|
|
114
116
|
|
115
117
|
@property
|
116
118
|
def api_endpoint(self) -> str:
|
119
|
+
assert self._api_initialized
|
117
120
|
return (
|
118
|
-
f'https://{self.
|
119
|
-
f'{self.
|
121
|
+
f'https://{self._location}-aiplatform.googleapis.com/v1/projects/'
|
122
|
+
f'{self._project}/locations/{self._location}/publishers/google/'
|
120
123
|
f'models/{self.model}:generateContent'
|
121
124
|
)
|
122
125
|
|
@@ -126,6 +129,7 @@ class VertexAIGeminiFlash2_0ThinkingExp_20241219(VertexAI): # pylint: disable=i
|
|
126
129
|
|
127
130
|
api_version = 'v1alpha'
|
128
131
|
model = 'gemini-2.0-flash-thinking-exp-1219'
|
132
|
+
timeout = None
|
129
133
|
|
130
134
|
|
131
135
|
class VertexAIGeminiFlash2_0Exp(VertexAI): # pylint: disable=invalid-name
|
@@ -41,7 +41,7 @@ class VertexAITest(unittest.TestCase):
|
|
41
41
|
os.environ['VERTEXAI_LOCATION'] = 'us-central1'
|
42
42
|
model = vertexai.VertexAIGeminiPro1()
|
43
43
|
self.assertTrue(model.model_id.startswith('VertexAI('))
|
44
|
-
self.
|
44
|
+
self.assertIn('us-central1', model.api_endpoint)
|
45
45
|
self.assertTrue(model._api_initialized)
|
46
46
|
self.assertIsNotNone(model._session)
|
47
47
|
del os.environ['VERTEXAI_PROJECT']
|
@@ -46,15 +46,15 @@ class MappingError(Exception): # pylint: disable=g-bad-exception-name
|
|
46
46
|
r = io.StringIO()
|
47
47
|
error_message = str(self.cause).rstrip()
|
48
48
|
r.write(
|
49
|
-
|
49
|
+
pg.colored(
|
50
50
|
f'{self.cause.__class__.__name__}: {error_message}', 'magenta'
|
51
51
|
)
|
52
52
|
)
|
53
53
|
if include_lm_response:
|
54
54
|
r.write('\n\n')
|
55
|
-
r.write(
|
55
|
+
r.write(pg.colored('[LM Response]', 'blue', styles=['bold']))
|
56
56
|
r.write('\n')
|
57
|
-
r.write(
|
57
|
+
r.write(pg.colored(self.lm_response.text, 'blue'))
|
58
58
|
return r.getvalue()
|
59
59
|
|
60
60
|
|
@@ -163,27 +163,27 @@ class MappingExample(lf.NaturalLanguageFormattable,
|
|
163
163
|
def natural_language_format(self) -> str:
|
164
164
|
result = io.StringIO()
|
165
165
|
if self.context:
|
166
|
-
result.write(
|
167
|
-
result.write(
|
166
|
+
result.write(pg.colored('[CONTEXT]\n', styles=['bold']))
|
167
|
+
result.write(pg.colored(self.context, color='magenta'))
|
168
168
|
result.write('\n\n')
|
169
169
|
|
170
|
-
result.write(
|
171
|
-
result.write(
|
170
|
+
result.write(pg.colored('[INPUT]\n', styles=['bold']))
|
171
|
+
result.write(pg.colored(self.input_repr(), color='green'))
|
172
172
|
|
173
173
|
if self.schema is not None:
|
174
174
|
result.write('\n\n')
|
175
|
-
result.write(
|
176
|
-
result.write(
|
175
|
+
result.write(pg.colored('[SCHEMA]\n', styles=['bold']))
|
176
|
+
result.write(pg.colored(self.schema_repr(), color='red'))
|
177
177
|
|
178
178
|
if schema_lib.MISSING != self.output:
|
179
179
|
result.write('\n\n')
|
180
|
-
result.write(
|
181
|
-
result.write(
|
180
|
+
result.write(pg.colored('[OUTPUT]\n', styles=['bold']))
|
181
|
+
result.write(pg.colored(self.output_repr(), color='blue'))
|
182
182
|
|
183
183
|
if self.metadata:
|
184
184
|
result.write('\n\n')
|
185
|
-
result.write(
|
186
|
-
result.write(
|
185
|
+
result.write(pg.colored('[METADATA]\n', styles=['bold']))
|
186
|
+
result.write(pg.colored(str(self.metadata), color='cyan'))
|
187
187
|
return result.getvalue().strip()
|
188
188
|
|
189
189
|
@classmethod
|
@@ -29,11 +29,11 @@ class MappingErrorTest(unittest.TestCase):
|
|
29
29
|
lf.AIMessage('hi'), ValueError('Cannot parse message.')
|
30
30
|
)
|
31
31
|
self.assertEqual(
|
32
|
-
|
32
|
+
pg.decolor(str(error)),
|
33
33
|
'ValueError: Cannot parse message.\n\n[LM Response]\nhi',
|
34
34
|
)
|
35
35
|
self.assertEqual(
|
36
|
-
|
36
|
+
pg.decolor(error.format(include_lm_response=False)),
|
37
37
|
'ValueError: Cannot parse message.',
|
38
38
|
)
|
39
39
|
|
@@ -91,20 +91,25 @@ class SchemaError(Exception): # pylint: disable=g-bad-exception-name
|
|
91
91
|
def __str__(self):
|
92
92
|
r = io.StringIO()
|
93
93
|
r.write(
|
94
|
-
|
94
|
+
pg.colored(
|
95
|
+
f'{self.cause.__class__.__name__}: {self.cause}', 'magenta'
|
96
|
+
)
|
97
|
+
)
|
95
98
|
|
96
99
|
r.write('\n')
|
97
|
-
r.write(
|
100
|
+
r.write(pg.colored('Schema:', 'red'))
|
98
101
|
r.write('\n\n')
|
99
102
|
r.write(textwrap.indent(
|
100
|
-
|
103
|
+
pg.colored(
|
104
|
+
schema_repr(self.protocol).repr(self.schema), 'magenta'
|
105
|
+
),
|
101
106
|
' ' * 2
|
102
107
|
))
|
103
108
|
r.write('\n\n')
|
104
|
-
r.write(
|
109
|
+
r.write(pg.colored('Generated value:', 'red'))
|
105
110
|
r.write('\n\n')
|
106
111
|
r.write(textwrap.indent(
|
107
|
-
|
112
|
+
pg.colored(value_repr(self.protocol).repr(self.value), 'magenta'),
|
108
113
|
' ' * 2
|
109
114
|
))
|
110
115
|
return r.getvalue()
|
@@ -759,12 +764,15 @@ class JsonError(Exception):
|
|
759
764
|
def __str__(self) -> str:
|
760
765
|
r = io.StringIO()
|
761
766
|
r.write(
|
762
|
-
|
767
|
+
pg.colored(
|
768
|
+
f'{self.cause.__class__.__name__}: {self.cause}', 'magenta'
|
769
|
+
)
|
770
|
+
)
|
763
771
|
|
764
772
|
r.write('\n\n')
|
765
|
-
r.write(
|
773
|
+
r.write(pg.colored('JSON text:', 'red'))
|
766
774
|
r.write('\n\n')
|
767
|
-
r.write(textwrap.indent(
|
775
|
+
r.write(textwrap.indent(pg.colored(self.json, 'magenta'), ' ' * 2))
|
768
776
|
return r.getvalue()
|
769
777
|
|
770
778
|
|
{langfun-0.1.2.dev202501060804.dist-info → langfun-0.1.2.dev202501090804.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: langfun
|
3
|
-
Version: 0.1.2.
|
3
|
+
Version: 0.1.2.dev202501090804
|
4
4
|
Summary: Langfun: Language as Functions.
|
5
5
|
Home-page: https://github.com/google/langfun
|
6
6
|
Author: Langfun Authors
|
@@ -56,6 +56,17 @@ Requires-Dist: pillow>=10.0.0; extra == "mime-pil"
|
|
56
56
|
Provides-Extra: mime-xlsx
|
57
57
|
Requires-Dist: openpyxl>=3.1.0; extra == "mime-xlsx"
|
58
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
|
59
70
|
|
60
71
|
<div align="center">
|
61
72
|
<img src="https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg" width="520px" alt="logo"></img>
|
@@ -1,15 +1,15 @@
|
|
1
1
|
langfun/__init__.py,sha256=fhfPXpHN7GoGqixpFfqhQkYxFs_siP_LhbjZhd3lhio,2497
|
2
|
-
langfun/core/__init__.py,sha256=
|
2
|
+
langfun/core/__init__.py,sha256=1fHngxhnpxYaVzNMPnifU2JXKaC4LdJGTGp0VnbaXUo,4580
|
3
3
|
langfun/core/component.py,sha256=HVrEoTL1Y01iqOHC3FYdbAOnffqfHHtGJXoK1vkdEwo,11583
|
4
4
|
langfun/core/component_test.py,sha256=sG-T2wpvBfHqWGZE7sc4NayJj2aj5QFBzSwFiwrGEIc,10376
|
5
|
-
langfun/core/concurrent.py,sha256=
|
5
|
+
langfun/core/concurrent.py,sha256=zhZX-YpByUKXWwarlDZFfY8TMW4r71jSW_wDlLhB980,29485
|
6
6
|
langfun/core/concurrent_test.py,sha256=ILlAjfhV84yJfY1QLe3N9aYry1sCjY-ywfIlXGafenI,17336
|
7
|
-
langfun/core/console.py,sha256=
|
7
|
+
langfun/core/console.py,sha256=bGwuJZRs_9NNKY1KmJjIZLeoQ_fL0BikAJPLDVdp1hw,2558
|
8
8
|
langfun/core/console_test.py,sha256=pBOcuNMJdVELywvroptfcRtJMsegMm3wSlHAL2TdxVk,1679
|
9
9
|
langfun/core/langfunc.py,sha256=G50YgoVZ0y1GFw2ev41MlOqr6qa8YakbvNC0h_E0PiA,11140
|
10
10
|
langfun/core/langfunc_test.py,sha256=fKIAqcSNI_7M6nwoZW77HEam8Oa6vcWhsCNgVJanzb4,8822
|
11
|
-
langfun/core/language_model.py,sha256=
|
12
|
-
langfun/core/language_model_test.py,sha256=
|
11
|
+
langfun/core/language_model.py,sha256=lQFHIEAHMNZtKNQ5tG6Gb74dGcfvy5mA4eeftYhnEOg,33881
|
12
|
+
langfun/core/language_model_test.py,sha256=lFPXBcxofvvL6u5GEpAAbsPxIDmk0Wy038SQ_mBIOz8,32153
|
13
13
|
langfun/core/logging.py,sha256=W3mLEMXdo210Q5OX3a1ZTc4nU-xMy73-IfNKnsA-RFo,8051
|
14
14
|
langfun/core/logging_test.py,sha256=N7-YvSXC8zvnr2SNwWHOykn1CFmqvIuTLDgn41Ku9JU,6642
|
15
15
|
langfun/core/memory.py,sha256=f-asN1F7Vehgdn_fK84v73GrEUOxRtaW934keutTKjk,2416
|
@@ -25,8 +25,6 @@ langfun/core/subscription.py,sha256=euawEuSZP-BHydaT-AQpfYFL0m5pWPGcW0upFhrojqc,
|
|
25
25
|
langfun/core/subscription_test.py,sha256=Y4ZdbZEwm83YNZBxHff0QR4QUa4rdaNXA3_jfIcArBo,8717
|
26
26
|
langfun/core/template.py,sha256=jNhYSrbLIn9kZOa03w5QZbyjgfnzJzE_ZrrMvvWY4t4,24929
|
27
27
|
langfun/core/template_test.py,sha256=g7x4mgNIAXEEj-4W1D5whGfl5YikLEQoylKPzaeDomk,17069
|
28
|
-
langfun/core/text_formatting.py,sha256=d7t9vaY6aCn1dkfkikpNYnBy5E_i93vHbfyDWFclGZU,5284
|
29
|
-
langfun/core/text_formatting_test.py,sha256=ck0Xzdd4YF4CtCUj7VE0GybfbAyKQ8p3xkM1FBGrqIk,2096
|
30
28
|
langfun/core/agentic/__init__.py,sha256=ndoDX0sAYsa3eVdXuu6nB-a-BH5TaK3urW6zAaFiyVs,1110
|
31
29
|
langfun/core/agentic/action.py,sha256=yW5-2NRHIrQmmQEYmL83aIdSwaRfUez9mqCbME_aBWQ,25391
|
32
30
|
langfun/core/agentic/action_eval.py,sha256=ZtjTh34S7XPIUqandQ0YwAtzw-S7ofuZ7rRXnRbUMdQ,4424
|
@@ -34,20 +32,20 @@ langfun/core/agentic/action_eval_test.py,sha256=tRUkWmOE9p0rpNOq19xAY2oDEnYsEEyk
|
|
34
32
|
langfun/core/agentic/action_test.py,sha256=Gu7P5XQvzqbKawn2jjyTpWaARzzhzO04KkC1TuBnUnw,4612
|
35
33
|
langfun/core/coding/__init__.py,sha256=5utju_fwEsImaiftx4oXKl9FAM8p281k8-Esdh_-m1w,835
|
36
34
|
langfun/core/coding/python/__init__.py,sha256=MJ-vubliz-ebrZH3OBRKBwMi0S9-FrhGCp8YQLR6_I4,1776
|
37
|
-
langfun/core/coding/python/correction.py,sha256=
|
35
|
+
langfun/core/coding/python/correction.py,sha256=SR_ZP8MYqvipFi5Scsl_5FYzBRRTwRehig79r67ZdlM,7129
|
38
36
|
langfun/core/coding/python/correction_test.py,sha256=qGxXuHaO32onF6cAoTfO1_sH_lM7-3dE9UqaaU8Myxs,4215
|
39
|
-
langfun/core/coding/python/errors.py,sha256=
|
37
|
+
langfun/core/coding/python/errors.py,sha256=KDn0bJH-34dUM5fp3Ocgn3HvWg1XYgFnxCSiWXGNI1c,3162
|
40
38
|
langfun/core/coding/python/errors_test.py,sha256=_ZbWJCFIb-FkCK7K1zCuH8W3x_NFt-jNe3dfP8yqaD4,2323
|
41
|
-
langfun/core/coding/python/execution.py,sha256=
|
42
|
-
langfun/core/coding/python/execution_test.py,sha256=
|
43
|
-
langfun/core/coding/python/generation.py,sha256=
|
39
|
+
langfun/core/coding/python/execution.py,sha256=vf8AzDcL_9xh-kpTKWywt9gV7Pc8KLghOHj6hrpiqS8,10762
|
40
|
+
langfun/core/coding/python/execution_test.py,sha256=xBsk5OZuuEY1_w7dxu25akL-NVHm02xjzyOQ2rPWhgY,7693
|
41
|
+
langfun/core/coding/python/generation.py,sha256=MqzoFdB3v7BtrAzqIMMyH8RvqaNJ6TSqZ9Xw-iPmPTI,8427
|
44
42
|
langfun/core/coding/python/generation_test.py,sha256=54bgKr1DgzYFLoqR8bTn7Yjol0gPCuR6XvRltR4l6YM,2777
|
45
43
|
langfun/core/coding/python/parsing.py,sha256=LMg8REP4VDY0YQjtPAGNAW4rKlMNdSXF8m19wMT9yrY,7128
|
46
44
|
langfun/core/coding/python/parsing_test.py,sha256=9vAWF484kWIm6JZq8NFiMgKUDhXV-deRl1QMmNERfAA,7386
|
47
45
|
langfun/core/coding/python/permissions.py,sha256=1QWGHvzL8MM0Ok_auQ9tURqZHtdOfJaDpBzZ29GUE-c,2544
|
48
46
|
langfun/core/coding/python/permissions_test.py,sha256=w5EDb8QxpxgJyZkojyzVWQvDfg366zn99-g__6TbPQ0,2699
|
49
47
|
langfun/core/eval/__init__.py,sha256=OEXr1ZRuvLuhJJfuQ1ZWQ-SvYzjyrtiAAEogYaB7E6o,1933
|
50
|
-
langfun/core/eval/base.py,sha256=
|
48
|
+
langfun/core/eval/base.py,sha256=XXerMVkK4wREo7K1_aCyay6vDjw3mfs389XThAdzv50,75768
|
51
49
|
langfun/core/eval/base_test.py,sha256=-LsIV9DXlDal0EnOlaWpibJvfef0NbxtZAm0OH_abAE,27189
|
52
50
|
langfun/core/eval/matching.py,sha256=AVKkGoc-BaHEzgSBamaAk3194TgqckDe_dinpS6LrXI,9323
|
53
51
|
langfun/core/eval/matching_test.py,sha256=QCoYEuf4b_1bkHqUCuRzKMbXHrV3AB2FCOBivo1stC4,5249
|
@@ -73,31 +71,33 @@ langfun/core/eval/v2/progress.py,sha256=azZgssQgNdv3IgjKEaQBuGI5ucFDNbdi02P4z_nQ
|
|
73
71
|
langfun/core/eval/v2/progress_test.py,sha256=YU7VHzmy5knPZwj9vpBN3rQQH2tukj9eKHkuBCI62h8,2540
|
74
72
|
langfun/core/eval/v2/progress_tracking.py,sha256=l9fEkz4oP5McpZzf72Ua7PYm3lAWtRru7gRWNf8H0ms,6083
|
75
73
|
langfun/core/eval/v2/progress_tracking_test.py,sha256=fouMVJkFJqHjbhQJngGLGCmA9x3n0dU4USI2dY163mg,2291
|
76
|
-
langfun/core/eval/v2/reporting.py,sha256=
|
74
|
+
langfun/core/eval/v2/reporting.py,sha256=QOp5jX761Esvi5w_UIRLDqPY_XRO6ru02-DOrdqVK_4,8392
|
77
75
|
langfun/core/eval/v2/reporting_test.py,sha256=UmYSAQvD3AIXsSyWQ-WD2uLtEISYpmBeoKY5u5Qwc8E,5696
|
78
76
|
langfun/core/eval/v2/runners.py,sha256=DKEmSlGXjOXKWFdBhTpLy7tMsBHZHd1Brl3hWIngsSQ,15931
|
79
77
|
langfun/core/eval/v2/runners_test.py,sha256=A37fKK2MvAVTiShsg_laluJzJ9AuAQn52k7HPbfD0Ks,11666
|
80
|
-
langfun/core/llms/__init__.py,sha256=
|
78
|
+
langfun/core/llms/__init__.py,sha256=AvKRIryNNDgL3fchzNp25NPh95ojI5lOnT8XHaJS_BE,6639
|
81
79
|
langfun/core/llms/anthropic.py,sha256=a5MmnFsBA0CbfvwzXT1v_0fqLRMrhUNdh1tx6469PQ4,14357
|
82
80
|
langfun/core/llms/anthropic_test.py,sha256=-2U4kc_pgBM7wqxu8RuxzyHPGww1EAWqKUvN4PW8Btw,8058
|
83
81
|
langfun/core/llms/compositional.py,sha256=csW_FLlgL-tpeyCOTVvfUQkMa_zCN5Y2I-YbSNuK27U,2872
|
84
82
|
langfun/core/llms/compositional_test.py,sha256=4eTnOer-DncRKGaIJW2ZQQMLnt5r2R0UIx_DYOvGAQo,2027
|
83
|
+
langfun/core/llms/deepseek.py,sha256=HxdLFFar5Mh01kKMyoLGnoYciACwxe2UzSpvKtXbSyw,8471
|
84
|
+
langfun/core/llms/deepseek_test.py,sha256=Eo-FFyW8PWeFH-AbfY6Ib2MARnFlMtEtPIJ86DsTyz4,14856
|
85
85
|
langfun/core/llms/fake.py,sha256=gCHBYBLvBCsC78HI1hpoqXCS-p1FMTgY1P1qh_sGBPk,3070
|
86
86
|
langfun/core/llms/fake_test.py,sha256=2h13qkwEz_JR0mtUDPxdAhQo7MueXaFSwsD2DIRDW9g,7653
|
87
87
|
langfun/core/llms/gemini.py,sha256=tfM4vrt0WnvnrxRhWXZWh7Gp8dYYfMnSbi9uOstkSak,17399
|
88
88
|
langfun/core/llms/gemini_test.py,sha256=2ERhYWCJwnfDTQbCaZHFuB1TdWJFrOBS7yyCBInIdQk,6129
|
89
|
-
langfun/core/llms/google_genai.py,sha256=
|
89
|
+
langfun/core/llms/google_genai.py,sha256=85Vmx5QmsziON03PRsFQINSu5NF6pAAuFFhUdDteWGc,3662
|
90
90
|
langfun/core/llms/google_genai_test.py,sha256=JZf_cbQ4GGGpwiQCLjFJn7V4jxBBqgZhIx91AzbGKVo,1250
|
91
91
|
langfun/core/llms/groq.py,sha256=dCnR3eAECEKuKKAAj-PDTs8NRHl6CQPdf57m1f6a79U,10312
|
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=
|
95
|
+
langfun/core/llms/openai.py,sha256=g5X_ySW-b2f0uRE8sb3_W1sAB-pWpKLNNoflBoRBwrc,21080
|
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=MuwLPTJ6-9x2uRDCSM1_biPK6M76FFlL1ezf5OmobDA,5504
|
100
|
+
langfun/core/llms/vertexai_test.py,sha256=iXjmQs7TNiwcueoaRGpdp4KnASkDJaTP__Z9QroN8zQ,1787
|
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=i58oiQL28RDsq37dwqgVpC2mBETJjIEFS20yHiV5MKU,5185
|
@@ -125,13 +125,13 @@ langfun/core/structured/description.py,sha256=6BztYOiucPkF4CrTQtPLPJo1gN2dwnKmaJ
|
|
125
125
|
langfun/core/structured/description_test.py,sha256=UxaXnKKP7TnyPDPUyf3U-zPE0TvLlIP6DGr8thjcePw,7365
|
126
126
|
langfun/core/structured/function_generation.py,sha256=g7AOR_e8HxFU6n6Df750aGkgMgV1KExLZMAz0yd5Agg,8555
|
127
127
|
langfun/core/structured/function_generation_test.py,sha256=LaXYDXf9GlqUrR6v_gtmK_H4kxzonmU7SYbn7XXMgjU,12128
|
128
|
-
langfun/core/structured/mapping.py,sha256=
|
129
|
-
langfun/core/structured/mapping_test.py,sha256=
|
128
|
+
langfun/core/structured/mapping.py,sha256=of-EeBq0RgmkiUaSk2rVEDVCzgn_wXU8tRke7NCcC6E,13649
|
129
|
+
langfun/core/structured/mapping_test.py,sha256=OntYvfDitAf0tAnzQty3YS90vyEn6FY1Mi93r_ViEk8,9594
|
130
130
|
langfun/core/structured/parsing.py,sha256=MGvI7ypXlwfzr5XB8_TFU9Ei0_5reYqkWkv64eAy0EA,12015
|
131
131
|
langfun/core/structured/parsing_test.py,sha256=kNPrhpdPY3iWhUld0TFYU-Zgn44wC0d6YuQ9XdVbQ8o,22346
|
132
132
|
langfun/core/structured/querying.py,sha256=nqvsfMS_KLv5EvO0_VAGEHwY4pHy4S0CvJmeV0HBXlM,23066
|
133
133
|
langfun/core/structured/querying_test.py,sha256=YlC4s9LVChfhGZzaXGW1UYlcBnAjNOunu4SLl5_p7PQ,32054
|
134
|
-
langfun/core/structured/schema.py,sha256=
|
134
|
+
langfun/core/structured/schema.py,sha256=_iqhHEGDQsHk0AsybWnK44sOspTWkKJjci781PWD7x0,27988
|
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
|
137
137
|
langfun/core/structured/schema_test.py,sha256=RjYhwTgktQgyqAjzLvo967nTiIK9KWgP-aNGg4e7ihE,25258
|
@@ -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.dev202501090804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
152
|
+
langfun-0.1.2.dev202501090804.dist-info/METADATA,sha256=mzbVRkRzSywU6qRzqZJ5KeGgTUGpYjMepZqt6OJtMJw,8172
|
153
|
+
langfun-0.1.2.dev202501090804.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
154
|
+
langfun-0.1.2.dev202501090804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
155
|
+
langfun-0.1.2.dev202501090804.dist-info/RECORD,,
|
langfun/core/text_formatting.py
DELETED
@@ -1,168 +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
|
-
"""Utility library for LM input/output formatting."""
|
15
|
-
|
16
|
-
import io
|
17
|
-
import re
|
18
|
-
from typing import Any
|
19
|
-
|
20
|
-
try:
|
21
|
-
import termcolor # pylint: disable=g-import-not-at-top
|
22
|
-
except ImportError:
|
23
|
-
termcolor = None
|
24
|
-
|
25
|
-
|
26
|
-
# Regular expression for ANSI color characters.
|
27
|
-
_ANSI_COLOR_REGEX = re.compile(r'\x1b\[[0-9;]*m')
|
28
|
-
|
29
|
-
|
30
|
-
def decolored(text: str) -> str:
|
31
|
-
"""Return the de-colored string that may contains ANSI color characters."""
|
32
|
-
return re.sub(_ANSI_COLOR_REGEX, '', text)
|
33
|
-
|
34
|
-
|
35
|
-
def colored(
|
36
|
-
text: str,
|
37
|
-
color: str | None = None,
|
38
|
-
background: str | None = None,
|
39
|
-
styles: list[str] | None = None
|
40
|
-
) -> str:
|
41
|
-
"""Returns the colored text with ANSI color characters.
|
42
|
-
|
43
|
-
Args:
|
44
|
-
text: A string that may or may not already has ANSI color characters.
|
45
|
-
color: A string for text colors. Applicable values are:
|
46
|
-
'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'.
|
47
|
-
background: A string for background colors. Applicable values are:
|
48
|
-
'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'.
|
49
|
-
styles: A list of strings for applying styles on the text.
|
50
|
-
Applicable values are:
|
51
|
-
'bold', 'dark', 'underline', 'blink', 'reverse', 'concealed'.
|
52
|
-
|
53
|
-
Returns:
|
54
|
-
A string with ANSI color characters embracing the entire text.
|
55
|
-
"""
|
56
|
-
if not termcolor:
|
57
|
-
return text
|
58
|
-
return termcolor.colored(
|
59
|
-
text,
|
60
|
-
color=color,
|
61
|
-
on_color=('on_' + background) if background else None,
|
62
|
-
attrs=styles)
|
63
|
-
|
64
|
-
|
65
|
-
def colored_template(
|
66
|
-
text: str,
|
67
|
-
expression_color: str | None = 'white',
|
68
|
-
expression_background: str | None = 'blue',
|
69
|
-
expression_styles: list[str] | None = None,
|
70
|
-
statement_color: str | None = 'red',
|
71
|
-
statement_background: str | None = None,
|
72
|
-
statement_styles: list[str] | None = None,
|
73
|
-
comment_color: str | None = 'green',
|
74
|
-
comment_background: str | None = None,
|
75
|
-
comment_styles: list[str] | None = None,
|
76
|
-
) -> str:
|
77
|
-
"""Returns colored (maybe) Jinja2 template string."""
|
78
|
-
text = color_text_blocks(
|
79
|
-
text, '{{', '}}',
|
80
|
-
color=expression_color,
|
81
|
-
background=expression_background,
|
82
|
-
styles=expression_styles)
|
83
|
-
|
84
|
-
text = color_text_blocks(
|
85
|
-
text, '{%', '%}',
|
86
|
-
color=statement_color,
|
87
|
-
background=statement_background,
|
88
|
-
styles=statement_styles)
|
89
|
-
|
90
|
-
text = color_text_blocks(
|
91
|
-
text, '{#', '#}',
|
92
|
-
color=comment_color,
|
93
|
-
background=comment_background,
|
94
|
-
styles=comment_styles)
|
95
|
-
|
96
|
-
return text
|
97
|
-
|
98
|
-
|
99
|
-
def color_text_blocks(
|
100
|
-
text: str,
|
101
|
-
block_start: str,
|
102
|
-
block_end: str,
|
103
|
-
color: str | None = None,
|
104
|
-
background: str | None = None,
|
105
|
-
styles: list[str] | None = None
|
106
|
-
) -> str:
|
107
|
-
"""Apply colors to text blocks.
|
108
|
-
|
109
|
-
Args:
|
110
|
-
text: A string that may or may not already has ANSI color characters.
|
111
|
-
block_start: A string that signals the start of a block. E.g. '{{'
|
112
|
-
block_end: A string that signals the end of a block. E.g. '}}'.
|
113
|
-
color: A string for text colors. Applicable values are:
|
114
|
-
'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'.
|
115
|
-
background: A string for background colors. Applicable values are:
|
116
|
-
'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'.
|
117
|
-
styles: A list of strings for applying styles on the text.
|
118
|
-
Applicable values are:
|
119
|
-
'bold', 'dark', 'underline', 'blink', 'reverse', 'concealed'.
|
120
|
-
|
121
|
-
Returns:
|
122
|
-
A string with ANSI color characters embracing the matched text blocks.
|
123
|
-
"""
|
124
|
-
if not color and not background and not styles:
|
125
|
-
return text
|
126
|
-
|
127
|
-
string_buffer = io.StringIO()
|
128
|
-
start_index = 0
|
129
|
-
end_index = 0
|
130
|
-
previous_color = None
|
131
|
-
|
132
|
-
def write_nonblock_text(text: str, previous_color: str | None):
|
133
|
-
if previous_color:
|
134
|
-
string_buffer.write(previous_color)
|
135
|
-
string_buffer.write(text)
|
136
|
-
|
137
|
-
while start_index < len(text):
|
138
|
-
start_index = text.find(block_start, end_index)
|
139
|
-
if start_index == -1:
|
140
|
-
write_nonblock_text(text[end_index:], previous_color)
|
141
|
-
break
|
142
|
-
|
143
|
-
# Deal with text since last block.
|
144
|
-
since_last_block = text[end_index:start_index]
|
145
|
-
write_nonblock_text(since_last_block, previous_color)
|
146
|
-
colors = re.findall(_ANSI_COLOR_REGEX, since_last_block)
|
147
|
-
if colors:
|
148
|
-
previous_color = colors[-1]
|
149
|
-
|
150
|
-
# Match block.
|
151
|
-
end_index = text.find(block_end, start_index + len(block_start))
|
152
|
-
if end_index == -1:
|
153
|
-
write_nonblock_text(text[start_index:], previous_color)
|
154
|
-
break
|
155
|
-
end_index += len(block_end)
|
156
|
-
|
157
|
-
# Write block text.
|
158
|
-
block = text[start_index:end_index]
|
159
|
-
colored_block = colored(
|
160
|
-
block, color=color, background=background, styles=styles)
|
161
|
-
string_buffer.write(colored_block)
|
162
|
-
return string_buffer.getvalue()
|
163
|
-
|
164
|
-
|
165
|
-
def colored_print(value: Any):
|
166
|
-
"""Prints text with color."""
|
167
|
-
print(colored_template(str(value)))
|
168
|
-
|
@@ -1,65 +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 text formatting."""
|
15
|
-
|
16
|
-
import inspect
|
17
|
-
import unittest
|
18
|
-
from langfun.core import text_formatting
|
19
|
-
|
20
|
-
|
21
|
-
class TextFormattingTest(unittest.TestCase):
|
22
|
-
|
23
|
-
def test_colored_template(self):
|
24
|
-
original_text = inspect.cleandoc("""
|
25
|
-
Hi {{ foo }}
|
26
|
-
{# print x if x is present #}
|
27
|
-
{% if x %}
|
28
|
-
{{ x }}
|
29
|
-
{% endif %}
|
30
|
-
""")
|
31
|
-
|
32
|
-
colored_text = text_formatting.colored_template(
|
33
|
-
text_formatting.colored(original_text, color='blue')
|
34
|
-
)
|
35
|
-
self.assertEqual(
|
36
|
-
colored_text,
|
37
|
-
'\x1b[34mHi \x1b[44m\x1b[37m{{ foo }}\x1b[0m\x1b[34m\n'
|
38
|
-
'\x1b[32m{# print x if x is present #}\x1b[0m\x1b[34m\n'
|
39
|
-
'\x1b[31m{% if x %}\x1b[0m\x1b[34m\n'
|
40
|
-
'\x1b[44m\x1b[37m{{ x }}\x1b[0m\x1b[34m\n'
|
41
|
-
'\x1b[31m{% endif %}\x1b[0m\x1b[34m\x1b[0m'
|
42
|
-
)
|
43
|
-
self.assertEqual(text_formatting.decolored(colored_text), original_text)
|
44
|
-
|
45
|
-
def test_colored_without_termcolor(self):
|
46
|
-
termcolor = text_formatting.termcolor
|
47
|
-
text_formatting.termcolor = None
|
48
|
-
original_text = inspect.cleandoc("""
|
49
|
-
Hi {{ foo }}
|
50
|
-
{# print x if x is present #}
|
51
|
-
{% if x %}
|
52
|
-
{{ x }}
|
53
|
-
{% endif %}
|
54
|
-
""")
|
55
|
-
|
56
|
-
colored_text = text_formatting.colored_template(
|
57
|
-
text_formatting.colored(original_text, color='blue')
|
58
|
-
)
|
59
|
-
self.assertEqual(colored_text, original_text)
|
60
|
-
self.assertEqual(text_formatting.decolored(colored_text), original_text)
|
61
|
-
text_formatting.termcolor = termcolor
|
62
|
-
|
63
|
-
|
64
|
-
if __name__ == '__main__':
|
65
|
-
unittest.main()
|
File without changes
|
{langfun-0.1.2.dev202501060804.dist-info → langfun-0.1.2.dev202501090804.dist-info}/top_level.txt
RENAMED
File without changes
|