langfun 0.1.1.dev20240723__py3-none-any.whl → 0.1.1.dev20240725__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/llms/__init__.py +1 -0
- langfun/core/modalities/image.py +11 -0
- langfun/core/modalities/image_test.py +15 -1
- {langfun-0.1.1.dev20240723.dist-info → langfun-0.1.1.dev20240725.dist-info}/METADATA +1 -1
- {langfun-0.1.1.dev20240723.dist-info → langfun-0.1.1.dev20240725.dist-info}/RECORD +8 -8
- {langfun-0.1.1.dev20240723.dist-info → langfun-0.1.1.dev20240725.dist-info}/LICENSE +0 -0
- {langfun-0.1.1.dev20240723.dist-info → langfun-0.1.1.dev20240725.dist-info}/WHEEL +0 -0
- {langfun-0.1.1.dev20240723.dist-info → langfun-0.1.1.dev20240725.dist-info}/top_level.txt +0 -0
langfun/core/llms/__init__.py
CHANGED
@@ -29,6 +29,7 @@ from langfun.core.llms.rest import REST
|
|
29
29
|
|
30
30
|
# Gemini models.
|
31
31
|
from langfun.core.llms.google_genai import GenAI
|
32
|
+
from langfun.core.llms.google_genai import GeminiFlash1_5
|
32
33
|
from langfun.core.llms.google_genai import GeminiPro
|
33
34
|
from langfun.core.llms.google_genai import GeminiPro1_5
|
34
35
|
from langfun.core.llms.google_genai import GeminiProVision
|
langfun/core/modalities/image.py
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
|
16
16
|
import functools
|
17
17
|
import io
|
18
|
+
|
18
19
|
from langfun.core.modalities import mime
|
19
20
|
from PIL import Image as pil_image
|
20
21
|
|
@@ -31,6 +32,16 @@ class Image(mime.Mime):
|
|
31
32
|
def _html(self, uri: str) -> str:
|
32
33
|
return f'<img src="{uri}">'
|
33
34
|
|
35
|
+
@functools.cached_property
|
34
36
|
def size(self) -> tuple[int, int]:
|
35
37
|
img = pil_image.open(io.BytesIO(self.to_bytes()))
|
36
38
|
return img.size
|
39
|
+
|
40
|
+
def to_pil_image(self) -> pil_image.Image:
|
41
|
+
return pil_image.open(io.BytesIO(self.to_bytes()))
|
42
|
+
|
43
|
+
@classmethod
|
44
|
+
def from_pil_image(cls, img: pil_image.Image) -> 'Image':
|
45
|
+
buf = io.BytesIO()
|
46
|
+
img.save(buf, format='PNG')
|
47
|
+
return cls.from_bytes(buf.getvalue())
|
@@ -12,12 +12,14 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
"""Image tests."""
|
15
|
+
import io
|
15
16
|
import unittest
|
16
17
|
from unittest import mock
|
17
18
|
|
18
19
|
import langfun.core as lf
|
19
20
|
from langfun.core.modalities import image as image_lib
|
20
21
|
from langfun.core.modalities import mime as mime_lib
|
22
|
+
import PIL.Image as pil_image
|
21
23
|
import pyglove as pg
|
22
24
|
|
23
25
|
|
@@ -81,7 +83,19 @@ class ImageTest(unittest.TestCase):
|
|
81
83
|
image = image_lib.Image.from_uri('http://mock/web/a.png')
|
82
84
|
with mock.patch('requests.get') as mock_requests_get:
|
83
85
|
mock_requests_get.side_effect = mock_request
|
84
|
-
self.assertEqual(image.size
|
86
|
+
self.assertEqual(image.size, (24, 24))
|
87
|
+
|
88
|
+
def test_to_pil_image(self):
|
89
|
+
image = image_lib.Image.from_uri('http://mock/web/a.png')
|
90
|
+
with mock.patch('requests.get') as mock_requests_get:
|
91
|
+
mock_requests_get.side_effect = mock_request
|
92
|
+
self.assertIsInstance(image.to_pil_image(), pil_image.Image)
|
93
|
+
|
94
|
+
def test_from_pil_image(self):
|
95
|
+
image = pil_image.open(io.BytesIO(image_content))
|
96
|
+
self.assertIsInstance(
|
97
|
+
image_lib.Image.from_pil_image(image), image_lib.Image
|
98
|
+
)
|
85
99
|
|
86
100
|
|
87
101
|
if __name__ == '__main__':
|
@@ -52,7 +52,7 @@ 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=1J7IATo-8FXUR0SBqk9icztHiM0lWkBFcWUo-vUURgQ,6376
|
54
54
|
langfun/core/eval/scoring_test.py,sha256=O8olHbrUEg60gMxwOkWzKBJZpZoUlmVnBANX5Se2SXM,4546
|
55
|
-
langfun/core/llms/__init__.py,sha256=
|
55
|
+
langfun/core/llms/__init__.py,sha256=sRD_PjfD5wKuzANCOCjChjuZHUn2Q1WruZeVflqej5M,4609
|
56
56
|
langfun/core/llms/anthropic.py,sha256=Gon3fOi31RhZFgNd0ijyTnKnUdp9hrWrCoSXyO4UaLw,7316
|
57
57
|
langfun/core/llms/anthropic_test.py,sha256=T-swuMkfnlgs8Fpif4rtXs579exGk0TsbLMirXDZCkg,5533
|
58
58
|
langfun/core/llms/fake.py,sha256=Dd7-6ka9pFf3fcWZyczamjOqQ91MOI-m7We3Oc9Ffmo,2927
|
@@ -79,8 +79,8 @@ langfun/core/memories/conversation_history_test.py,sha256=AaW8aNoFjxNusanwJDV0r3
|
|
79
79
|
langfun/core/modalities/__init__.py,sha256=F8P72IwFiTpEseTR2tYEJyQMlDW7fd9csvGJquLKJNg,1269
|
80
80
|
langfun/core/modalities/audio.py,sha256=Qxo7bYjLKQ1gVJVomr9RqR2SvxY826QgXhTzzk437Sk,952
|
81
81
|
langfun/core/modalities/audio_test.py,sha256=gWCB9h3FyrdGqro3ajBXqkw0lU0W1sBjOOq6wZbl7Fg,2027
|
82
|
-
langfun/core/modalities/image.py,sha256=
|
83
|
-
langfun/core/modalities/image_test.py,sha256=
|
82
|
+
langfun/core/modalities/image.py,sha256=uBSAwExnSD4MevhK9Z4qExPlLVFBQLUfjPOAldtWFOI,1387
|
83
|
+
langfun/core/modalities/image_test.py,sha256=A0aYblxpnKABDgm2OVPxF8iRq4qFVanM9TPcaewkAgA,3774
|
84
84
|
langfun/core/modalities/mime.py,sha256=7oYvwYZHb3uhjiL2rF6kvQWsWufY0UXl72wfDXC59ys,5918
|
85
85
|
langfun/core/modalities/mime_test.py,sha256=kmRiPP-3Py02NnKPu0oPexSIJ-MXaaE2UYY82ga0TV8,2913
|
86
86
|
langfun/core/modalities/ms_office.py,sha256=jOidMSdWCaV9RILpGz8VJkpTSpHJNoirD53jzQvcytM,3388
|
@@ -117,8 +117,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
117
117
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
118
118
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
119
119
|
langfun/core/templates/selfplay_test.py,sha256=rBW2Qr8yi-aWYwoTwRR-n1peKyMX9QXPZXURjLgoiRs,2264
|
120
|
-
langfun-0.1.1.
|
121
|
-
langfun-0.1.1.
|
122
|
-
langfun-0.1.1.
|
123
|
-
langfun-0.1.1.
|
124
|
-
langfun-0.1.1.
|
120
|
+
langfun-0.1.1.dev20240725.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
121
|
+
langfun-0.1.1.dev20240725.dist-info/METADATA,sha256=rdI4MR2Td7NQiXfjPyJpcIy1MEQl7W-RUce_eRqlZeQ,5247
|
122
|
+
langfun-0.1.1.dev20240725.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
|
123
|
+
langfun-0.1.1.dev20240725.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
124
|
+
langfun-0.1.1.dev20240725.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|