langfun 0.1.2.dev202505270804__py3-none-any.whl → 0.1.2.dev202505290804__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.
@@ -16,7 +16,7 @@
16
16
  import abc
17
17
  import os
18
18
  import tempfile
19
- from typing import Annotated
19
+ from typing import Annotated, Protocol, Self
20
20
 
21
21
  from langfun.core.coding.python import parsing
22
22
  import pyglove as pg
@@ -35,10 +35,42 @@ class SandboxOutput(pg.Object):
35
35
  'The stderr of the sandbox execution.'
36
36
  ] = ''
37
37
 
38
+ output_files: Annotated[
39
+ dict[str, bytes],
40
+ 'The output files of the sandbox execution.'
41
+ ] = {}
38
42
 
39
- class Sandbox(pg.Object):
43
+
44
+ class Sandbox(Protocol):
40
45
  """Interface for Python sandbox."""
41
46
 
47
+ def run(
48
+ self,
49
+ code: str,
50
+ **kwargs,
51
+ ) -> SandboxOutput:
52
+ """Runs code in the sandbox."""
53
+
54
+ def upload(
55
+ self,
56
+ path: str,
57
+ **kwargs,
58
+ ) -> str:
59
+ """Uploads a file to the sandbox."""
60
+
61
+ def clone(self) -> 'Sandbox':
62
+ """Clones the sandbox."""
63
+
64
+ def __enter__(self) -> Self:
65
+ """Sandboxes should be used as a context manager."""
66
+
67
+ def __exit__(self, exc_type, exc_value, traceback) -> None:
68
+ """Sandboxes should be used as a context manager."""
69
+
70
+
71
+ class BaseSandbox(pg.Object):
72
+ """Interface and partial implementation for Python sandbox."""
73
+
42
74
  def _on_bound(self):
43
75
  super()._on_bound()
44
76
  self._uploaded_files: dict[str, str] = {}
@@ -105,7 +137,7 @@ class Sandbox(pg.Object):
105
137
  self.cleanup()
106
138
 
107
139
 
108
- class MultiProcessingSandbox(Sandbox):
140
+ class MultiProcessingSandbox(BaseSandbox):
109
141
  """Sandbox using multiprocessing."""
110
142
 
111
143
  def _on_bound(self):
langfun/core/llms/rest.py CHANGED
@@ -103,6 +103,8 @@ class REST(lf.LanguageModel):
103
103
  error_message = str(e)
104
104
  if 'REJECTED_CLIENT_THROTTLED' in error_message:
105
105
  raise lf.TemporaryLMError(error_message) from e
106
+ if 'UNREACHABLE_NO_RESPONSE' in error_message:
107
+ raise lf.TemporaryLMError(error_message) from e
106
108
  if 'UNREACHABLE_ERROR' in error_message:
107
109
  raise lf.TemporaryLMError(error_message) from e
108
110
  raise lf.LMError(error_message) from e
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langfun
3
- Version: 0.1.2.dev202505270804
3
+ Version: 0.1.2.dev202505290804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -40,7 +40,7 @@ langfun/core/coding/python/generation.py,sha256=sA6t97qBflO3WtuL9axknEVQPgqXHeqa
40
40
  langfun/core/coding/python/generation_test.py,sha256=dcF5ef1UApzRfTpvICiChpynkzZ1mDsE0DvH0iMpTvg,2743
41
41
  langfun/core/coding/python/parsing.py,sha256=jvGDIwoaY3mdGXeFhjP27w0ukO0TtdCC7G4ODVNp8S4,4554
42
42
  langfun/core/coding/python/parsing_test.py,sha256=PIexYpSEhgNaSd4T6QYWzWHzm3sL4VhQJ4dhdvJAQk8,5005
43
- langfun/core/coding/python/sandboxing.py,sha256=yeEdydMkfHk3Hj3-5ykeROpYyLbRfZ4BwGWJYvFBmSI,4001
43
+ langfun/core/coding/python/sandboxing.py,sha256=bp_l9XVzDvuhrbxnpm0xDghKrPdqCxj7reL6cCxFTIo,4729
44
44
  langfun/core/coding/python/sandboxing_test.py,sha256=H_0_pd-_uS-ci5yYhmDTR6-hyzosAFkExziAHndfdDo,2023
45
45
  langfun/core/data/__init__.py,sha256=qllw9ST1vveZv-1E0VM5hezn1YH-OcqGI-yFqQYnWgI,732
46
46
  langfun/core/data/conversion/__init__.py,sha256=ZcGntBruvvZSfESO-Tha1nzHfgWEK7I1u78Jw8gsoVU,883
@@ -104,7 +104,7 @@ langfun/core/llms/openai.py,sha256=LxENwsuGh-h1LXMu2Ub8Rjp1g1WNpm1NHBrwhkD-M4Q,4
104
104
  langfun/core/llms/openai_compatible.py,sha256=JlFUTiK4e3ox2DGeGBcAD-cXkxmBdx5g6LrYkyMIaps,5777
105
105
  langfun/core/llms/openai_compatible_test.py,sha256=KwOMA7tsmOxFBjezltkBDSU77AvOQkI23dO2nHLAlB4,17689
106
106
  langfun/core/llms/openai_test.py,sha256=gwuO6aoa296iM2welWV9ua4KF8gEVGsEPakgbtkWkFQ,2687
107
- langfun/core/llms/rest.py,sha256=MCybcHApJcf49lubLnDzScN9Oc2IWY_JnMHIGdbDOuU,4474
107
+ langfun/core/llms/rest.py,sha256=mY9n0sMAtf0RsvTBgbYHDxGzGD9WLIkocALEHXAL5r4,4583
108
108
  langfun/core/llms/rest_test.py,sha256=_zM7nV8DEVyoXNiQOnuwJ917mWjki0614H88rNmDboE,5020
109
109
  langfun/core/llms/vertexai.py,sha256=OqtSyq2PqQuFHva3ewhU_pt74sKxCAZMRKA5x1KyDcM,19353
110
110
  langfun/core/llms/vertexai_test.py,sha256=_e-acnNBAf9C3WO6i1b2J_mhRzdDdYQTorD9hIVZKOg,5034
@@ -156,8 +156,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
156
156
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
157
157
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
158
158
  langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
159
- langfun-0.1.2.dev202505270804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
160
- langfun-0.1.2.dev202505270804.dist-info/METADATA,sha256=gCxzpayu2eaMOcwdR38vuYTFlCOrgzxYIuOx00Xm9ak,8178
161
- langfun-0.1.2.dev202505270804.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
162
- langfun-0.1.2.dev202505270804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
163
- langfun-0.1.2.dev202505270804.dist-info/RECORD,,
159
+ langfun-0.1.2.dev202505290804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
160
+ langfun-0.1.2.dev202505290804.dist-info/METADATA,sha256=UhUvpJZX9p3ZPnZ1E8KpqOJt5HfpgCblYZ0SM4Rj7HM,8178
161
+ langfun-0.1.2.dev202505290804.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
162
+ langfun-0.1.2.dev202505290804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
163
+ langfun-0.1.2.dev202505290804.dist-info/RECORD,,