langfun 0.0.2.dev20240508__py3-none-any.whl → 0.0.2.dev20240509__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.
@@ -233,8 +233,9 @@ class OpenAI(lf.LanguageModel):
233
233
  for chunk in prompt.chunk():
234
234
  if isinstance(chunk, str):
235
235
  item = dict(type='text', text=chunk)
236
- elif isinstance(chunk, lf_modalities.Image) and chunk.uri:
237
- item = dict(type='image_url', image_url=dict(url=chunk.uri))
236
+ elif isinstance(chunk, lf_modalities.Image):
237
+ uri = chunk.uri or chunk.content_uri
238
+ item = dict(type='image_url', image_url=dict(url=uri))
238
239
  else:
239
240
  raise ValueError(f'Unsupported modality object: {chunk!r}.')
240
241
  content.append(item)
@@ -13,7 +13,6 @@
13
13
  # limitations under the License.
14
14
  """Image modality."""
15
15
 
16
- import base64
17
16
  import imghdr
18
17
  from typing import cast
19
18
  from langfun.core.modalities import mime
@@ -36,5 +35,4 @@ class Image(mime.MimeType):
36
35
  def _repr_html_(self) -> str:
37
36
  if self.uri and self.uri.lower().startswith(('http:', 'https:', 'ftp:')):
38
37
  return f'<img src="{self.uri}">'
39
- image_raw = base64.b64encode(self.to_bytes()).decode()
40
- return f'<img src="data:image/{self.image_format};base64,{image_raw}">'
38
+ return f'<img src="{self.content_uri}">'
@@ -14,6 +14,7 @@
14
14
  """MIME type data."""
15
15
 
16
16
  import abc
17
+ import base64
17
18
  from typing import Annotated, Union
18
19
  import langfun.core as lf
19
20
  import pyglove as pg
@@ -54,6 +55,11 @@ class MimeType(lf.Modality):
54
55
  self.rebind(content=content, skip_notification=True)
55
56
  return self.content
56
57
 
58
+ @property
59
+ def content_uri(self) -> str:
60
+ base64_content = base64.b64encode(self.to_bytes()).decode()
61
+ return f'data:{self.mime_type};base64,{base64_content}'
62
+
57
63
  @classmethod
58
64
  def from_uri(cls, uri: str, **kwargs) -> 'MimeType':
59
65
  return cls(uri=uri, content=None, **kwargs)
@@ -13,7 +13,6 @@
13
13
  # limitations under the License.
14
14
  """Video modality."""
15
15
 
16
- import base64
17
16
  from typing import cast
18
17
  from langfun.core.modalities import mime
19
18
 
@@ -40,8 +39,7 @@ class Video(mime.MimeType):
40
39
  def _repr_html_(self) -> str:
41
40
  if self.uri and self.uri.lower().startswith(('http:', 'https:', 'ftp:')):
42
41
  return f'<video controls> <source src="{self.uri}"> </video>'
43
- video_raw = base64.b64encode(self.to_bytes()).decode()
44
42
  return (
45
43
  '<video controls> <source'
46
- f' src="data:video/{self.video_format};base64,{video_raw}"> </video>'
44
+ f' src="data:video/{self.content_uri}"> </video>'
47
45
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.0.2.dev20240508
3
+ Version: 0.0.2.dev20240509
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -59,7 +59,7 @@ langfun/core/llms/groq.py,sha256=NaGItVL_pkOpqPpI4bPGU27xLFRoaeizZ49v2s-4ERs,784
59
59
  langfun/core/llms/groq_test.py,sha256=M6GtlrsOvDun_j-sR8cPh4W_moHWZNSTiThu3kuwbbc,5281
60
60
  langfun/core/llms/llama_cpp.py,sha256=Y_KkMUf3Xfac49koMUtUslKl3h-HWp3-ntq7Jaa3bdo,2385
61
61
  langfun/core/llms/llama_cpp_test.py,sha256=ZxC6defGd_HX9SFRU9U4cJiQnBKundbOrchbXuC1Z2M,1683
62
- langfun/core/llms/openai.py,sha256=rPwO4qPGEwbB4O7TaQD0spg_PXIfF2ioRI_ilE3Pg6Y,13257
62
+ langfun/core/llms/openai.py,sha256=u2lqYcKFjFxLfWYD0KLT3YThqcoo66rWs3n0bcuSYBs,13286
63
63
  langfun/core/llms/openai_test.py,sha256=asSA1sVy_7hnXioD_2HTxtSDpVTKBUO_EjZuyHpwbn0,14854
64
64
  langfun/core/llms/cache/__init__.py,sha256=QAo3InUMDM_YpteNnVCSejI4zOsnjSMWKJKzkb3VY64,993
65
65
  langfun/core/llms/cache/base.py,sha256=cFfYvOIUae842pncqCAsRvqXCk2AnAsRYVx0mcIoAeY,3338
@@ -69,11 +69,11 @@ langfun/core/memories/__init__.py,sha256=HpghfZ-w1NQqzJXBx8Lz0daRhB2rcy2r9Xm491S
69
69
  langfun/core/memories/conversation_history.py,sha256=c9amD8hCxGFiZuVAzkP0dOMWSp8L90uvwkOejjuBqO0,1835
70
70
  langfun/core/memories/conversation_history_test.py,sha256=AaW8aNoFjxNusanwJDV0r3384Mg0eAweGmPx5DIkM0Y,2052
71
71
  langfun/core/modalities/__init__.py,sha256=ldCbs1HHAHAJECNu19vppA0sWEidI40xBs4W1F_YOlo,1073
72
- langfun/core/modalities/image.py,sha256=zNpLHwJi6PJMeeAcVQG6vn0oYIbilTuJq6xu-TvrArM,1358
72
+ langfun/core/modalities/image.py,sha256=MUqRCQYyP7Gcf3dmzjU9J9ZEpfI08gAli9ZDmk0bJEk,1254
73
73
  langfun/core/modalities/image_test.py,sha256=YxDRvC49Bjwyyndd_P7y6XjyS7dOft0Zewwxk-7q4kE,2301
74
- langfun/core/modalities/mime.py,sha256=wVfaYflhGz1W4v3m972rAplW3OGOFtjFpHDYIaUD5D0,2238
74
+ langfun/core/modalities/mime.py,sha256=RatBOPqYEneYMe-lfgRxJp5T3yvgV6vBMNY8lK2WU8k,2421
75
75
  langfun/core/modalities/mime_test.py,sha256=cVHxRvJ1QXC1SVhBmWkJdWGpL9Xl0UNfTQq6j0OGGL4,1881
76
- langfun/core/modalities/video.py,sha256=25M4XsNG5XEWRy57LYT_a6_aMURMPAgC41B3weEXFsY,1747
76
+ langfun/core/modalities/video.py,sha256=bzJLeBDF6FIVHyrAvRqYcQq2pCLBqN-UIgX_f3lM3E0,1654
77
77
  langfun/core/modalities/video_test.py,sha256=jYuI2m8S8zDCAVBPEUbbpP205dXAht90A2_PHWo4-r8,2039
78
78
  langfun/core/structured/__init__.py,sha256=Qg1ocwsb60od8fJky3F3JAOhwjwT9WA7IX3C2j2s3zA,3707
79
79
  langfun/core/structured/completion.py,sha256=skBxt6V_fv2TBUKnzFgnPMbVY8HSYn8sY04MLok2yvs,7299
@@ -103,8 +103,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
103
103
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
104
104
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
105
105
  langfun/core/templates/selfplay_test.py,sha256=DYVrkk7uNKCqJGEHH31HssU2BPuMItU1vJLzfcXIlYg,2156
106
- langfun-0.0.2.dev20240508.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
107
- langfun-0.0.2.dev20240508.dist-info/METADATA,sha256=-kG5pyZ6wAFJRP0hINq-JUhoEnKJsXrn2YCZbZuAFhY,3405
108
- langfun-0.0.2.dev20240508.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
109
- langfun-0.0.2.dev20240508.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
110
- langfun-0.0.2.dev20240508.dist-info/RECORD,,
106
+ langfun-0.0.2.dev20240509.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
107
+ langfun-0.0.2.dev20240509.dist-info/METADATA,sha256=6MAMP6ZRzEu4KKmEmOUV8Z0rEdOnoKORXlkojvl0KZg,3405
108
+ langfun-0.0.2.dev20240509.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
109
+ langfun-0.0.2.dev20240509.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
110
+ langfun-0.0.2.dev20240509.dist-info/RECORD,,