langfun 0.1.2.dev202503230803__py3-none-any.whl → 0.1.2.dev202503250804__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.
@@ -152,12 +152,33 @@ class Mime(lf.Modality):
152
152
 
153
153
  @classmethod
154
154
  def from_uri(cls, uri: str, **kwargs) -> 'Mime':
155
+ if uri.startswith('data:'):
156
+ mime_type, content = cls._parse_data_uri(uri)
157
+ return cls.class_from_mime_type(mime_type).from_bytes(content, **kwargs)
158
+
155
159
  if cls is Mime:
156
160
  content = cls.download(uri)
157
161
  mime = from_buffer(content, mime=True).lower()
158
162
  return cls.class_from_mime_type(mime)(uri=uri, content=content, **kwargs)
159
163
  return cls(uri=uri, content=None, **kwargs)
160
164
 
165
+ @classmethod
166
+ def _parse_data_uri(cls, uri: str) -> tuple[str, bytes]:
167
+ """Returns the MIME type and content from the given data URI."""
168
+ assert uri.startswith('data:'), uri
169
+ mime_end_pos = uri.find(';', 0)
170
+ if mime_end_pos == -1:
171
+ raise ValueError(f'Invalid data URI: {uri!r}.')
172
+ mime_type = uri[5: mime_end_pos].strip().lower()
173
+ encoding_end_pos = uri.find(',', mime_end_pos + 1)
174
+ if encoding_end_pos == -1:
175
+ raise ValueError(f'Invalid data URI: {uri!r}.')
176
+ encoding = uri[mime_end_pos + 1: encoding_end_pos].strip().lower()
177
+ if encoding != 'base64':
178
+ raise ValueError(f'Unsupported encoding: {encoding!r}.')
179
+ base64_content = uri[encoding_end_pos + 1:].strip().encode()
180
+ return mime_type, base64.b64decode(base64_content)
181
+
161
182
  @classmethod
162
183
  def from_bytes(cls, content: bytes | str, **kwargs) -> 'Mime':
163
184
  if cls is Mime:
@@ -93,6 +93,22 @@ class CustomMimeTest(unittest.TestCase):
93
93
  self.assertEqual(content.to_bytes(), b'bar')
94
94
  self.assertEqual(content.mime_type, 'text/plain')
95
95
 
96
+ content = mime.Mime.from_uri('data:text/plain;base64,Zm9v')
97
+ self.assertIsNone(content.uri)
98
+ self.assertEqual(content.mime_type, 'text/plain')
99
+ self.assertEqual(content.content, b'foo')
100
+ self.assertEqual(content.content_uri, 'data:text/plain;base64,Zm9v')
101
+ self.assertEqual(content.embeddable_uri, 'data:text/plain;base64,Zm9v')
102
+
103
+ with self.assertRaisesRegex(ValueError, 'Invalid data URI'):
104
+ mime.Mime.from_uri('data:text/plain')
105
+
106
+ with self.assertRaisesRegex(ValueError, 'Invalid data URI'):
107
+ mime.Mime.from_uri('data:text/plain;abcd')
108
+
109
+ with self.assertRaisesRegex(ValueError, 'Unsupported encoding'):
110
+ mime.Mime.from_uri('data:text/plain;base16,abcd')
111
+
96
112
  def assert_html_content(self, html, expected):
97
113
  expected = inspect.cleandoc(expected).strip()
98
114
  actual = html.content.strip()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langfun
3
- Version: 0.1.2.dev202503230803
3
+ Version: 0.1.2.dev202503250804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -1,5 +1,5 @@
1
- langfun/__init__.py,sha256=fhfPXpHN7GoGqixpFfqhQkYxFs_siP_LhbjZhd3lhio,2497
2
- langfun/core/__init__.py,sha256=S6YS15fLy5M3L3qaSa3XhDgku-klUm1LJxFPB-Wl-tY,4596
1
+ langfun/__init__.py,sha256=LuB1difPJsI8V9H4kmUJM2DAEmMEV_WtaBLGYp3qEFM,2527
2
+ langfun/core/__init__.py,sha256=-pTwNDzB_Ljs9vX272AO5WzopqjEJosO3sZTwNQdJ0Y,4647
3
3
  langfun/core/component.py,sha256=g1kQM0bryYYYWVDrSMnHfc74wIBbpfe5_B3s-UIP5GE,3028
4
4
  langfun/core/component_test.py,sha256=0CxTgjAud3aj8wBauFhG2FHDqrxCTl4OI4gzQTad-40,9254
5
5
  langfun/core/concurrent.py,sha256=zY-pXqlGqss_GI20tM1gXvyW8QepVPUuFNmutcIdhbI,32760
@@ -13,8 +13,8 @@ langfun/core/language_model_test.py,sha256=iA5uo7rIj2jAtCYzMzhyNg1fWqE2Onn60bOO5
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
16
- langfun/core/message.py,sha256=16oiMpg9O9VKrgpfrvJrfvga3n3FzUuD_zdWb9nvSWA,25686
17
- langfun/core/message_test.py,sha256=AAKOZitp-Pu_w2x98zV6hQhll2ZTmWdtW0vmT3MyOjI,36165
16
+ langfun/core/message.py,sha256=1QOs_jIbehBKumQxVQigOXgN03kcGCBt5K706xHkbqg,32750
17
+ langfun/core/message_test.py,sha256=X7YoovahWQpLBYbSBdhIw-_SyGgbZEl1TAAhiQ3JNb4,39776
18
18
  langfun/core/modality.py,sha256=K8pUGuMpfWcOtVcXC_OqVjro1-RhHF6ddQni61DuYzM,4166
19
19
  langfun/core/modality_test.py,sha256=0WL_yd3B4K-FviWdSpDnOwj0f9TQI0v9t6X0vWvvJbo,2415
20
20
  langfun/core/natural_language.py,sha256=3ynSnaYQnjE60LIPK5fyMgdIjubnPYZwzGq4rWPeloE,1177
@@ -42,6 +42,14 @@ langfun/core/coding/python/parsing.py,sha256=jvGDIwoaY3mdGXeFhjP27w0ukO0TtdCC7G4
42
42
  langfun/core/coding/python/parsing_test.py,sha256=PIexYpSEhgNaSd4T6QYWzWHzm3sL4VhQJ4dhdvJAQk8,5005
43
43
  langfun/core/coding/python/sandboxing.py,sha256=yeEdydMkfHk3Hj3-5ykeROpYyLbRfZ4BwGWJYvFBmSI,4001
44
44
  langfun/core/coding/python/sandboxing_test.py,sha256=H_0_pd-_uS-ci5yYhmDTR6-hyzosAFkExziAHndfdDo,2023
45
+ langfun/core/data/__init__.py,sha256=qllw9ST1vveZv-1E0VM5hezn1YH-OcqGI-yFqQYnWgI,732
46
+ langfun/core/data/conversion/__init__.py,sha256=bSml7RCnr8Zmo0QHtSXGli_jHo58SEi2tuO5HJm74RI,839
47
+ langfun/core/data/conversion/anthropic.py,sha256=NzMPvgof27BdvDx9-8s8cpkauUcA_V_BVPdFa0-hsqE,4423
48
+ langfun/core/data/conversion/anthropic_test.py,sha256=R43PyveNUCHNCvfu6RFsTk0EIKK8M1Gzng0Kay8TlE8,8534
49
+ langfun/core/data/conversion/gemini.py,sha256=_PZ5LIhuxJuwl3UVxkSYvAw1LyR3Lopz4lwRJOITDsU,5502
50
+ langfun/core/data/conversion/gemini_test.py,sha256=KIaWdY8CIn0YMaSomxTizvwCrljvt7lbDi3WSEbb1FE,7637
51
+ langfun/core/data/conversion/openai.py,sha256=OPnlMOaL43GaHbBFnCoRqzaTybBJiZVKcaHt0JLvJrw,4173
52
+ langfun/core/data/conversion/openai_test.py,sha256=38WV_3ofFZiUF10bTKnZp4VyuDP5-81aR3h3Q0HlBm0,5283
45
53
  langfun/core/eval/__init__.py,sha256=OEXr1ZRuvLuhJJfuQ1ZWQ-SvYzjyrtiAAEogYaB7E6o,1933
46
54
  langfun/core/eval/base.py,sha256=qIJnrO1jX5pzY8yoQTtcTn5lGdD9adz5U6C_jla1BV4,75806
47
55
  langfun/core/eval/base_test.py,sha256=UJBsfsXNAfZpSSI6oEF7_VxPp13SzRRLRfuCnU7a4JM,27189
@@ -67,14 +75,14 @@ langfun/core/eval/v2/metrics.py,sha256=bl8i6u-ZHRBz4hAc3LzsZ2Dc7ZRQcuTYeUhhH-Gxf
67
75
  langfun/core/eval/v2/metrics_test.py,sha256=p4FzLJsE8XAzAQuyP9hfEf9YeKWZ__PO_ue8a9P0-cc,6082
68
76
  langfun/core/eval/v2/progress.py,sha256=azZgssQgNdv3IgjKEaQBuGI5ucFDNbdi02P4z_nQ8GE,10292
69
77
  langfun/core/eval/v2/progress_test.py,sha256=YU7VHzmy5knPZwj9vpBN3rQQH2tukj9eKHkuBCI62h8,2540
70
- langfun/core/eval/v2/progress_tracking.py,sha256=l9fEkz4oP5McpZzf72Ua7PYm3lAWtRru7gRWNf8H0ms,6083
78
+ langfun/core/eval/v2/progress_tracking.py,sha256=zNhNPGlnJnHELEfFpbTMCSXFn8d1IJ57OOYkfFaBFfM,6097
71
79
  langfun/core/eval/v2/progress_tracking_test.py,sha256=fouMVJkFJqHjbhQJngGLGCmA9x3n0dU4USI2dY163mg,2291
72
80
  langfun/core/eval/v2/reporting.py,sha256=yUIPCAMnp7InIzpv1DDWrcLO-75iiOUTpscj7smkfrA,8335
73
81
  langfun/core/eval/v2/reporting_test.py,sha256=hcPJJaMtPulqERvHYTpId83WXdqDKnnexmULtK7WKwk,5686
74
82
  langfun/core/eval/v2/runners.py,sha256=De4d5QQ-Tpw0nPDODQexDPy0ti-FEgzHBvfH78zqdtg,15945
75
83
  langfun/core/eval/v2/runners_test.py,sha256=A37fKK2MvAVTiShsg_laluJzJ9AuAQn52k7HPbfD0Ks,11666
76
84
  langfun/core/llms/__init__.py,sha256=F2nqEv9Cc-1QALrlPnIEp-TZiSVTi6U8WWb1YwDt1w0,8038
77
- langfun/core/llms/anthropic.py,sha256=d6ncYfPbK1YjofebKdOgGu0un_AXdsKBgt0SFGwE70s,23391
85
+ langfun/core/llms/anthropic.py,sha256=K8la8U7g26ibvk_Cy9U7Z8or-kaqQIpaEJ4An9FrXPQ,21690
78
86
  langfun/core/llms/anthropic_test.py,sha256=SSK7OTx3gMYE1NMAi_PqQqeNsCkZAcVJvl_OCEOhyzk,7145
79
87
  langfun/core/llms/azure_openai.py,sha256=-KkSLaR54MlsIqz_XIwv0TnsBnvNTAxnjA2Q2O2u5KM,2733
80
88
  langfun/core/llms/azure_openai_test.py,sha256=lkMZkQdJBV97fTM4C4z8qNfvr6spgiN5G4hvVUIVr0M,1735
@@ -84,8 +92,8 @@ langfun/core/llms/deepseek.py,sha256=jvTxdXPr-vH6HNakn_Ootx1heDg8Fen2FUkUW36bpCs
84
92
  langfun/core/llms/deepseek_test.py,sha256=DvROWPlDuow5E1lfoSkhyGt_ELA19JoQoDsTnRgDtTg,1847
85
93
  langfun/core/llms/fake.py,sha256=xmgCkk9y0I4x0IT32SZ9_OT27aLadXH8PRiYNo5VTd4,3265
86
94
  langfun/core/llms/fake_test.py,sha256=2h13qkwEz_JR0mtUDPxdAhQo7MueXaFSwsD2DIRDW9g,7653
87
- langfun/core/llms/gemini.py,sha256=msTaDZcPBwZUMIHBXZUshexUJayIr3I7g-7z_uqtpqA,23095
88
- langfun/core/llms/gemini_test.py,sha256=ZzQmgB5bxJdtD2nVOz0WQ1zjNCea_jM5Yuqs8kchnGw,6621
95
+ langfun/core/llms/gemini.py,sha256=xBZEIPTKzWNscomrGhBVBxfEMuMSz48tl2FzCgtaWvU,21334
96
+ langfun/core/llms/gemini_test.py,sha256=WVdE1_X1cuicUEYd9YnIlV-dO_k_MMIHecBhWQtBNWE,5526
89
97
  langfun/core/llms/google_genai.py,sha256=mzUdWAShRzz2k_foUo0eIdNOyHs_xjEtbewqYyuD0k0,4768
90
98
  langfun/core/llms/google_genai_test.py,sha256=NKNtpebArQ9ZR7Qsnhd2prFIpMjleojy6o6VMXkJ1zY,1502
91
99
  langfun/core/llms/groq.py,sha256=S9V10kFo3cgX89qPgt_umq-SpRnxEDLTt_hJmpERfbo,12066
@@ -93,7 +101,7 @@ langfun/core/llms/groq_test.py,sha256=P4EgexCqsh4K2x11w0UL_vz-YYNaPdQU0WsDAdnTRQ
93
101
  langfun/core/llms/llama_cpp.py,sha256=Z7P3gc4xeIjc2bX0Ey1y5EUYJVMnMa2Q67PZ9iye9sE,1409
94
102
  langfun/core/llms/llama_cpp_test.py,sha256=wfTO7nmUwL65U2kK9P9fcMt92JjNDuVia4G1E7znf_4,1086
95
103
  langfun/core/llms/openai.py,sha256=zDi-wkV-r3vUZYoTFvU1gaNNVQVQytVuZ4CvTGLsRL8,39576
96
- langfun/core/llms/openai_compatible.py,sha256=lhq9_XLVUoGa5AIPXTbqGqWvm2P3dkHFSUQ7XnyLozw,5442
104
+ langfun/core/llms/openai_compatible.py,sha256=C4zA3WjYuj_ovoTOlUgHmh-22IS8_6OF9iJQuj4kdpw,5229
97
105
  langfun/core/llms/openai_compatible_test.py,sha256=I5WWL3lRo-WXnSoUKLkIEjXfwjoiHRX9o0dj0j09jsk,17024
98
106
  langfun/core/llms/openai_test.py,sha256=gwuO6aoa296iM2welWV9ua4KF8gEVGsEPakgbtkWkFQ,2687
99
107
  langfun/core/llms/rest.py,sha256=ucMKHXlmg6pYSIMhQSktLmTSGMSIiqO8fp1r_GiEhaU,4333
@@ -112,8 +120,8 @@ langfun/core/modalities/audio.py,sha256=qCrVCX690SG0ps-ZfOtNWvHn_CmdJsmxF7GySScW
112
120
  langfun/core/modalities/audio_test.py,sha256=yyGEBYqMXmNs_F2dEtj-PX8HE040vqh-YQppsvdxPw4,2025
113
121
  langfun/core/modalities/image.py,sha256=ovcX8NLBNv8WzxAdhQ-u4VQfHVBkWijRj_oiNwhE9lk,1768
114
122
  langfun/core/modalities/image_test.py,sha256=XMgtJXY75R5eo0CZ222D1QUy57_hESnttmCGWwDLt7k,3824
115
- langfun/core/modalities/mime.py,sha256=T00qHntL3uewF_DBVA-sJiV9mPK6bLAuBsg0bWSYKUQ,7919
116
- langfun/core/modalities/mime_test.py,sha256=Lg21nKFi--a884gnI7tFS4cHnwByEEhWg4Ugsr-UCbw,5277
123
+ langfun/core/modalities/mime.py,sha256=Hz6MnxQO_ccgrEryUf7dwyUGYj616I68NshLDK9PC_k,8860
124
+ langfun/core/modalities/mime_test.py,sha256=n084tOkeKHKMOVblCmi5s8nw4o7VYn3ynqvcrz8ww7c,5977
117
125
  langfun/core/modalities/pdf.py,sha256=mfaeCbUA4JslFVTARiJh8hW7imvL4tLVw9gUhO5bAZA,727
118
126
  langfun/core/modalities/pdf_test.py,sha256=ulZ0FbnlsU0wkrdckJ4ONZPTYRyMPO9Aob1UO6FXygk,1950
119
127
  langfun/core/modalities/video.py,sha256=vI9apcHIHGyp90i34Srg7S3G6IBDtDCk8qiXhwRQmkw,967
@@ -148,8 +156,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
148
156
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
149
157
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
150
158
  langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
151
- langfun-0.1.2.dev202503230803.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
152
- langfun-0.1.2.dev202503230803.dist-info/METADATA,sha256=DGtXmHPz9Cr-VDFtX-3qCBLtucdsTgIuNf4gDxTzMHY,7692
153
- langfun-0.1.2.dev202503230803.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
154
- langfun-0.1.2.dev202503230803.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
155
- langfun-0.1.2.dev202503230803.dist-info/RECORD,,
159
+ langfun-0.1.2.dev202503250804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
160
+ langfun-0.1.2.dev202503250804.dist-info/METADATA,sha256=ZK5cXCxwd6Usf6yVEEsm0nkAJ-FfqN5Yi8aLG4-l7PI,7692
161
+ langfun-0.1.2.dev202503250804.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
162
+ langfun-0.1.2.dev202503250804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
163
+ langfun-0.1.2.dev202503250804.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (78.0.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5