langfun 0.1.2.dev202410230804__py3-none-any.whl → 0.1.2.dev202410250804__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/concurrent.py +10 -1
- langfun/core/concurrent_test.py +10 -1
- langfun/core/langfunc_test.py +2 -1
- langfun/core/language_model.py +10 -0
- langfun/core/llms/__init__.py +2 -0
- langfun/core/llms/anthropic.py +18 -0
- langfun/core/llms/vertexai_test.py +5 -1
- langfun/core/structured/parsing.py +6 -3
- langfun/core/structured/parsing_test.py +18 -0
- {langfun-0.1.2.dev202410230804.dist-info → langfun-0.1.2.dev202410250804.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202410230804.dist-info → langfun-0.1.2.dev202410250804.dist-info}/RECORD +14 -14
- {langfun-0.1.2.dev202410230804.dist-info → langfun-0.1.2.dev202410250804.dist-info}/LICENSE +0 -0
- {langfun-0.1.2.dev202410230804.dist-info → langfun-0.1.2.dev202410250804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202410230804.dist-info → langfun-0.1.2.dev202410250804.dist-info}/top_level.txt +0 -0
langfun/core/concurrent.py
CHANGED
@@ -118,6 +118,7 @@ def with_retry(
|
|
118
118
|
max_attempts: int,
|
119
119
|
retry_interval: int | tuple[int, int] = (5, 60),
|
120
120
|
exponential_backoff: bool = True,
|
121
|
+
max_retry_interval: int = 300,
|
121
122
|
seed: int | None = None,
|
122
123
|
) -> Callable[..., Any]:
|
123
124
|
"""Derives a user function with retry on error.
|
@@ -133,6 +134,9 @@ def with_retry(
|
|
133
134
|
of the tuple.
|
134
135
|
exponential_backoff: If True, exponential wait time will be applied on top
|
135
136
|
of the base retry interval.
|
137
|
+
max_retry_interval: The max retry interval in seconds. This is useful when
|
138
|
+
the retry interval is exponential, to avoid the wait time to grow
|
139
|
+
exponentially.
|
136
140
|
seed: Random seed to generate retry interval. If None, the seed will be
|
137
141
|
determined based on current time.
|
138
142
|
|
@@ -153,7 +157,7 @@ def with_retry(
|
|
153
157
|
def next_wait_interval(attempt: int) -> float:
|
154
158
|
if not exponential_backoff:
|
155
159
|
attempt = 1
|
156
|
-
return base_interval() * (2 ** (attempt - 1))
|
160
|
+
return min(max_retry_interval, base_interval() * (2 ** (attempt - 1)))
|
157
161
|
|
158
162
|
wait_intervals = []
|
159
163
|
errors = []
|
@@ -193,6 +197,7 @@ def concurrent_execute(
|
|
193
197
|
max_attempts: int = 5,
|
194
198
|
retry_interval: int | tuple[int, int] = (5, 60),
|
195
199
|
exponential_backoff: bool = True,
|
200
|
+
max_retry_interval: int = 300,
|
196
201
|
) -> list[Any]:
|
197
202
|
"""Executes a function concurrently under current component context.
|
198
203
|
|
@@ -213,6 +218,9 @@ def concurrent_execute(
|
|
213
218
|
of the tuple.
|
214
219
|
exponential_backoff: If True, exponential wait time will be applied on top
|
215
220
|
of the base retry interval.
|
221
|
+
max_retry_interval: The max retry interval in seconds. This is useful when
|
222
|
+
the retry interval is exponential, to avoid the wait time to grow
|
223
|
+
exponentially.
|
216
224
|
|
217
225
|
Returns:
|
218
226
|
A list of ouputs. Each is the return value of `func` based on the input
|
@@ -225,6 +233,7 @@ def concurrent_execute(
|
|
225
233
|
max_attempts=max_attempts,
|
226
234
|
retry_interval=retry_interval,
|
227
235
|
exponential_backoff=exponential_backoff,
|
236
|
+
max_retry_interval=max_retry_interval,
|
228
237
|
)
|
229
238
|
|
230
239
|
# NOTE(daiyip): when executor is not specified and max_worker is 1,
|
langfun/core/concurrent_test.py
CHANGED
@@ -138,10 +138,19 @@ class WithRetryTest(unittest.TestCase):
|
|
138
138
|
raise ValueError('Intentional error.')
|
139
139
|
|
140
140
|
foo_with_retry = concurrent.with_retry(
|
141
|
-
foo, ValueError, max_attempts=4, retry_interval=1
|
141
|
+
foo, ValueError, max_attempts=4, retry_interval=1,
|
142
142
|
)
|
143
143
|
self.assert_retry(foo_with_retry, 4, [1, 2, 4])
|
144
144
|
|
145
|
+
def test_retry_with_max_retry_interval(self):
|
146
|
+
def foo():
|
147
|
+
raise ValueError('Intentional error.')
|
148
|
+
|
149
|
+
foo_with_retry = concurrent.with_retry(
|
150
|
+
foo, ValueError, max_attempts=4, retry_interval=1, max_retry_interval=3,
|
151
|
+
)
|
152
|
+
self.assert_retry(foo_with_retry, 4, [1, 2, 3])
|
153
|
+
|
145
154
|
def test_retry_with_uncaught_exception(self):
|
146
155
|
def foo():
|
147
156
|
raise ValueError('Intentional error.')
|
langfun/core/langfunc_test.py
CHANGED
@@ -108,7 +108,8 @@ class LangFuncCallTest(unittest.TestCase):
|
|
108
108
|
' max_tokens=None, n=1, top_k=40, top_p=None, stop=None,'
|
109
109
|
' random_seed=None, logprobs=False, top_logprobs=None), cache=None,'
|
110
110
|
' max_concurrency=None, timeout=120.0, max_attempts=5,'
|
111
|
-
' retry_interval=(5, 60), exponential_backoff=True,
|
111
|
+
' retry_interval=(5, 60), exponential_backoff=True,'
|
112
|
+
' max_retry_interval=300, debug=False))',
|
112
113
|
)
|
113
114
|
|
114
115
|
l = LangFunc('Hello')
|
langfun/core/language_model.py
CHANGED
@@ -409,6 +409,15 @@ class LanguageModel(component.Component):
|
|
409
409
|
)
|
410
410
|
] = True
|
411
411
|
|
412
|
+
max_retry_interval: Annotated[
|
413
|
+
int,
|
414
|
+
(
|
415
|
+
'The max retry interval in seconds. This is useful when the retry '
|
416
|
+
'interval is exponential, to avoid the wait time to grow '
|
417
|
+
'exponentially.'
|
418
|
+
)
|
419
|
+
] = 300
|
420
|
+
|
412
421
|
debug: Annotated[
|
413
422
|
bool | LMDebugMode,
|
414
423
|
(
|
@@ -587,6 +596,7 @@ class LanguageModel(component.Component):
|
|
587
596
|
max_attempts=self.max_attempts,
|
588
597
|
retry_interval=self.retry_interval,
|
589
598
|
exponential_backoff=self.exponential_backoff,
|
599
|
+
max_retry_interval=self.max_retry_interval,
|
590
600
|
)
|
591
601
|
|
592
602
|
def __call__(
|
langfun/core/llms/__init__.py
CHANGED
@@ -90,6 +90,8 @@ from langfun.core.llms.openai import Gpt3Ada
|
|
90
90
|
|
91
91
|
from langfun.core.llms.anthropic import Anthropic
|
92
92
|
from langfun.core.llms.anthropic import Claude35Sonnet
|
93
|
+
from langfun.core.llms.anthropic import Claude35Sonnet20241022
|
94
|
+
from langfun.core.llms.anthropic import Claude35Sonnet20240620
|
93
95
|
from langfun.core.llms.anthropic import Claude3Opus
|
94
96
|
from langfun.core.llms.anthropic import Claude3Sonnet
|
95
97
|
from langfun.core.llms.anthropic import Claude3Haiku
|
langfun/core/llms/anthropic.py
CHANGED
@@ -30,6 +30,13 @@ SUPPORTED_MODELS_AND_SETTINGS = {
|
|
30
30
|
# as RPM/TPM of the largest-available model (Claude-3-Opus).
|
31
31
|
# Price in US dollars at https://www.anthropic.com/pricing
|
32
32
|
# as of 2024-10-10.
|
33
|
+
'claude-3-5-sonnet-20241022': pg.Dict(
|
34
|
+
max_tokens=4096,
|
35
|
+
rpm=4000,
|
36
|
+
tpm=400000,
|
37
|
+
cost_per_1k_input_tokens=0.003,
|
38
|
+
cost_per_1k_output_tokens=0.015,
|
39
|
+
),
|
33
40
|
'claude-3-5-sonnet-20240620': pg.Dict(
|
34
41
|
max_tokens=4096,
|
35
42
|
rpm=4000,
|
@@ -264,6 +271,17 @@ class Claude3(Anthropic):
|
|
264
271
|
|
265
272
|
class Claude35Sonnet(Claude3):
|
266
273
|
"""A balance between between Opus and Haiku."""
|
274
|
+
model = 'claude-3-5-sonnet-20241022'
|
275
|
+
|
276
|
+
|
277
|
+
class Claude35Sonnet20241022(Claude3):
|
278
|
+
"""A balance between between Opus and Haiku."""
|
279
|
+
|
280
|
+
model = 'claude-3-5-sonnet-20241022'
|
281
|
+
|
282
|
+
|
283
|
+
class Claude35Sonnet20240620(Claude3):
|
284
|
+
"""A balance between between Opus and Haiku."""
|
267
285
|
|
268
286
|
model = 'claude-3-5-sonnet-20240620'
|
269
287
|
|
@@ -195,8 +195,12 @@ class VertexAITest(unittest.TestCase):
|
|
195
195
|
stop=['\n'],
|
196
196
|
),
|
197
197
|
)
|
198
|
+
actual = config.to_dict()
|
199
|
+
# There is a discrepancy between the `property_ordering` in the
|
200
|
+
# Google-internal version and the open-source version.
|
201
|
+
actual['response_schema'].pop('property_ordering', None)
|
198
202
|
self.assertEqual(
|
199
|
-
|
203
|
+
actual,
|
200
204
|
dict(
|
201
205
|
temperature=2.0,
|
202
206
|
top_p=1.0,
|
@@ -271,8 +271,8 @@ def call(
|
|
271
271
|
return lm_output if returns_message else lm_output.text
|
272
272
|
|
273
273
|
# Call `parsing_lm` for structured parsing.
|
274
|
-
|
275
|
-
lm_output,
|
274
|
+
parsing_message = prompting.query(
|
275
|
+
lm_output.text,
|
276
276
|
schema,
|
277
277
|
examples=parsing_examples,
|
278
278
|
lm=parsing_lm or lm,
|
@@ -281,9 +281,12 @@ def call(
|
|
281
281
|
autofix=autofix,
|
282
282
|
autofix_lm=autofix_lm or lm,
|
283
283
|
protocol=protocol,
|
284
|
-
returns_message=
|
284
|
+
returns_message=True,
|
285
285
|
**kwargs,
|
286
286
|
)
|
287
|
+
# Chain the source of the parsed output to the LM output.
|
288
|
+
parsing_message.root.source = lm_output
|
289
|
+
return parsing_message if returns_message else parsing_message.result
|
287
290
|
|
288
291
|
|
289
292
|
def _parse_structure_cls(
|
@@ -670,6 +670,24 @@ class CallTest(unittest.TestCase):
|
|
670
670
|
3,
|
671
671
|
)
|
672
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.assertEqual(output.root.text, 'Compute 1 + 2')
|
690
|
+
|
673
691
|
def test_call_with_autofix(self):
|
674
692
|
lm = fake.StaticSequence(
|
675
693
|
[
|
@@ -2,13 +2,13 @@ langfun/__init__.py,sha256=mCES7t3R7Z-ZQYvG38-yrVqZubrXNfGCa8tI5HGB7mE,2274
|
|
2
2
|
langfun/core/__init__.py,sha256=xlvFTXc7IKUTs8aCFRFhzOLTmmeuhXgk9yx2InBLNiA,4937
|
3
3
|
langfun/core/component.py,sha256=kOWdhEYlGw62CO_7aB_oAdivVhnDfyoymRXHr10VtLo,11502
|
4
4
|
langfun/core/component_test.py,sha256=sG-T2wpvBfHqWGZE7sc4NayJj2aj5QFBzSwFiwrGEIc,10376
|
5
|
-
langfun/core/concurrent.py,sha256=
|
6
|
-
langfun/core/concurrent_test.py,sha256=
|
5
|
+
langfun/core/concurrent.py,sha256=8L-fRc9x5PtrnuHJSEOPiKG4HUsQ2xWDt_1Ws1uGJRE,30324
|
6
|
+
langfun/core/concurrent_test.py,sha256=ILlAjfhV84yJfY1QLe3N9aYry1sCjY-ywfIlXGafenI,17336
|
7
7
|
langfun/core/console.py,sha256=bk5rNPNm9rMGW5YT2HixxU04p2umnoabn5SDz6Dqe88,2317
|
8
8
|
langfun/core/console_test.py,sha256=5SYJdxpJGLgdSSQqqMPoA1X6jpsLD8rgcyk-EgI65oE,1077
|
9
9
|
langfun/core/langfunc.py,sha256=G50YgoVZ0y1GFw2ev41MlOqr6qa8YakbvNC0h_E0PiA,11140
|
10
|
-
langfun/core/langfunc_test.py,sha256=
|
11
|
-
langfun/core/language_model.py,sha256=
|
10
|
+
langfun/core/langfunc_test.py,sha256=fKIAqcSNI_7M6nwoZW77HEam8Oa6vcWhsCNgVJanzb4,8822
|
11
|
+
langfun/core/language_model.py,sha256=jOvWyiKvcv2yJGBNPWmxV8wyzuWnCcrc1FhldYBtPkE,30219
|
12
12
|
langfun/core/language_model_test.py,sha256=cgoSdKwicnvHYo-tQeTdONXAVM-bvWLzgTlqxvace-A,28424
|
13
13
|
langfun/core/logging.py,sha256=2zVHV5E4vdsjxY8lFF1zZP0WQlts4LT3nXspOKqDeBs,7454
|
14
14
|
langfun/core/logging_test.py,sha256=b5bPTSUoYeICATaO6I8dOVumodwRbxSp1Oz96Sf3KcE,6104
|
@@ -52,8 +52,8 @@ langfun/core/eval/patching.py,sha256=R0s2eAd1m97exQt06dmUL0V_MBG0W2Hxg7fhNB7cXW0
|
|
52
52
|
langfun/core/eval/patching_test.py,sha256=8kCd54Egjju22FMgtJuxEsrXkW8ifs-UUBHtrCG1L6w,4775
|
53
53
|
langfun/core/eval/scoring.py,sha256=SUdMzOkP0n2qGaSuUA4VwFiTw36jgMvgCJHPJS4yYDw,6254
|
54
54
|
langfun/core/eval/scoring_test.py,sha256=O8olHbrUEg60gMxwOkWzKBJZpZoUlmVnBANX5Se2SXM,4546
|
55
|
-
langfun/core/llms/__init__.py,sha256=
|
56
|
-
langfun/core/llms/anthropic.py,sha256=
|
55
|
+
langfun/core/llms/__init__.py,sha256=SFa3qKHSq_P_bV_SkIEVasm58J6wvwLVeoh0rhhDy9o,5985
|
56
|
+
langfun/core/llms/anthropic.py,sha256=aPZkxesbbGhDCs3eTvyyGrScvXgQO6Tgl4BVgxLXjOY,9431
|
57
57
|
langfun/core/llms/anthropic_test.py,sha256=T-swuMkfnlgs8Fpif4rtXs579exGk0TsbLMirXDZCkg,5533
|
58
58
|
langfun/core/llms/fake.py,sha256=gCHBYBLvBCsC78HI1hpoqXCS-p1FMTgY1P1qh_sGBPk,3070
|
59
59
|
langfun/core/llms/fake_test.py,sha256=2h13qkwEz_JR0mtUDPxdAhQo7MueXaFSwsD2DIRDW9g,7653
|
@@ -68,7 +68,7 @@ langfun/core/llms/openai_test.py,sha256=_8cd3VRNEUfE0-Ko1RiM6MlC5hjalRj7nYTJNhG1
|
|
68
68
|
langfun/core/llms/rest.py,sha256=laopuq-zD8V-3Y6eFDngftHEbE66VlUkCD2-rvvRaLU,3388
|
69
69
|
langfun/core/llms/rest_test.py,sha256=NZ3Nf0XQVpT9kLP5cBVo_yBHLI7vWTYhWQxYEJVMGs4,3472
|
70
70
|
langfun/core/llms/vertexai.py,sha256=eUFU0JjgpTVCAvQVEWiGqZrlE3Dye-EkzZCF1P8nwc4,18866
|
71
|
-
langfun/core/llms/vertexai_test.py,sha256=
|
71
|
+
langfun/core/llms/vertexai_test.py,sha256=7uBVOF5VF86xQ9HFAbSTh4J-0NjYLnuotBS1YRm-vgw,10529
|
72
72
|
langfun/core/llms/cache/__init__.py,sha256=QAo3InUMDM_YpteNnVCSejI4zOsnjSMWKJKzkb3VY64,993
|
73
73
|
langfun/core/llms/cache/base.py,sha256=rt3zwmyw0y9jsSGW-ZbV1vAfLxQ7_3AVk0l2EySlse4,3918
|
74
74
|
langfun/core/llms/cache/in_memory.py,sha256=l6b-iU9OTfTRo9Zmg4VrQIuArs4cCJDOpXiEpvNocjo,5004
|
@@ -98,8 +98,8 @@ langfun/core/structured/function_generation.py,sha256=pFgS3vcRAWiuFBol2x5Eeip3Xq
|
|
98
98
|
langfun/core/structured/function_generation_test.py,sha256=ZJI-aaGgWWszn92u7h5IZ9Pl70N2DgAGGJrIxPzsvwg,10065
|
99
99
|
langfun/core/structured/mapping.py,sha256=pMSvxEPqA8h7LsCMKMGG5Fcm0hyaIOTHFcoddQpn4cs,13574
|
100
100
|
langfun/core/structured/mapping_test.py,sha256=bHm2ZCXBITq_G8Lvw_olFHeUUc4s_lGXZm9v9JhoPB4,9630
|
101
|
-
langfun/core/structured/parsing.py,sha256=
|
102
|
-
langfun/core/structured/parsing_test.py,sha256
|
101
|
+
langfun/core/structured/parsing.py,sha256=zwzXh_E6yp6CzSY-0-tjqjVUiSO8wohNQedpjhDbnoE,11671
|
102
|
+
langfun/core/structured/parsing_test.py,sha256=i0i090FVgM8ngGqYjds0hjEm1v7q4gv18k-z1kaNr7E,21467
|
103
103
|
langfun/core/structured/prompting.py,sha256=huwwh01AQQCwPBQESOMI_V1V5PZkVQ8C89Yjk67_4Uw,10677
|
104
104
|
langfun/core/structured/prompting_test.py,sha256=pviyb8yTnxkWPAZodLIlQT8y2ScE6FfSHKWf1NUtV-Y,26718
|
105
105
|
langfun/core/structured/schema.py,sha256=UO44Gn4XbFfHmTMYdrhuC8LfGa6kwaOCAMFqBnvFNns,28156
|
@@ -119,8 +119,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
119
119
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
120
120
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
121
121
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
122
|
-
langfun-0.1.2.
|
123
|
-
langfun-0.1.2.
|
124
|
-
langfun-0.1.2.
|
125
|
-
langfun-0.1.2.
|
126
|
-
langfun-0.1.2.
|
122
|
+
langfun-0.1.2.dev202410250804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
123
|
+
langfun-0.1.2.dev202410250804.dist-info/METADATA,sha256=tYKkpmIIXhUO6f3i6uUr5FfkVYrme8O3WtbNCD6YkqY,8890
|
124
|
+
langfun-0.1.2.dev202410250804.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
125
|
+
langfun-0.1.2.dev202410250804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
126
|
+
langfun-0.1.2.dev202410250804.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{langfun-0.1.2.dev202410230804.dist-info → langfun-0.1.2.dev202410250804.dist-info}/top_level.txt
RENAMED
File without changes
|