langfun 0.1.2.dev202501090804__py3-none-any.whl → 0.1.2.dev202501110804__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 +3 -0
- langfun/core/llms/deepseek.py +8 -152
- langfun/core/llms/deepseek_test.py +12 -389
- langfun/core/llms/groq.py +12 -99
- langfun/core/llms/groq_test.py +31 -137
- langfun/core/llms/llama_cpp.py +17 -54
- langfun/core/llms/llama_cpp_test.py +2 -34
- langfun/core/llms/openai.py +9 -147
- langfun/core/llms/openai_compatible.py +179 -0
- langfun/core/llms/openai_compatible_test.py +480 -0
- langfun/core/llms/openai_test.py +13 -423
- langfun/core/modalities/mime.py +8 -0
- langfun/core/modalities/mime_test.py +19 -4
- langfun/core/modality_test.py +0 -1
- {langfun-0.1.2.dev202501090804.dist-info → langfun-0.1.2.dev202501110804.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202501090804.dist-info → langfun-0.1.2.dev202501110804.dist-info}/RECORD +19 -17
- {langfun-0.1.2.dev202501090804.dist-info → langfun-0.1.2.dev202501110804.dist-info}/LICENSE +0 -0
- {langfun-0.1.2.dev202501090804.dist-info → langfun-0.1.2.dev202501110804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202501090804.dist-info → langfun-0.1.2.dev202501110804.dist-info}/top_level.txt +0 -0
langfun/core/llms/openai_test.py
CHANGED
@@ -13,102 +13,9 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
"""Tests for OpenAI models."""
|
15
15
|
|
16
|
-
from typing import Any
|
17
16
|
import unittest
|
18
|
-
from unittest import mock
|
19
|
-
|
20
17
|
import langfun.core as lf
|
21
|
-
from langfun.core import modalities as lf_modalities
|
22
18
|
from langfun.core.llms import openai
|
23
|
-
import pyglove as pg
|
24
|
-
import requests
|
25
|
-
|
26
|
-
|
27
|
-
def mock_chat_completion_request(url: str, json: dict[str, Any], **kwargs):
|
28
|
-
del url, kwargs
|
29
|
-
messages = json['messages']
|
30
|
-
if len(messages) > 1:
|
31
|
-
system_message = f' system={messages[0]["content"]}'
|
32
|
-
else:
|
33
|
-
system_message = ''
|
34
|
-
|
35
|
-
if 'response_format' in json:
|
36
|
-
response_format = f' format={json["response_format"]["type"]}'
|
37
|
-
else:
|
38
|
-
response_format = ''
|
39
|
-
|
40
|
-
choices = []
|
41
|
-
for k in range(json['n']):
|
42
|
-
if json.get('logprobs'):
|
43
|
-
logprobs = dict(
|
44
|
-
content=[
|
45
|
-
dict(
|
46
|
-
token='chosen_token',
|
47
|
-
logprob=0.5,
|
48
|
-
top_logprobs=[
|
49
|
-
dict(
|
50
|
-
token=f'alternative_token_{i + 1}',
|
51
|
-
logprob=0.1
|
52
|
-
) for i in range(3)
|
53
|
-
]
|
54
|
-
)
|
55
|
-
]
|
56
|
-
)
|
57
|
-
else:
|
58
|
-
logprobs = None
|
59
|
-
|
60
|
-
choices.append(dict(
|
61
|
-
message=dict(
|
62
|
-
content=(
|
63
|
-
f'Sample {k} for message.{system_message}{response_format}'
|
64
|
-
)
|
65
|
-
),
|
66
|
-
logprobs=logprobs,
|
67
|
-
))
|
68
|
-
response = requests.Response()
|
69
|
-
response.status_code = 200
|
70
|
-
response._content = pg.to_json_str(
|
71
|
-
dict(
|
72
|
-
choices=choices,
|
73
|
-
usage=lf.LMSamplingUsage(
|
74
|
-
prompt_tokens=100,
|
75
|
-
completion_tokens=100,
|
76
|
-
total_tokens=200,
|
77
|
-
),
|
78
|
-
)
|
79
|
-
).encode()
|
80
|
-
return response
|
81
|
-
|
82
|
-
|
83
|
-
def mock_chat_completion_request_vision(
|
84
|
-
url: str, json: dict[str, Any], **kwargs
|
85
|
-
):
|
86
|
-
del url, kwargs
|
87
|
-
choices = []
|
88
|
-
urls = [
|
89
|
-
c['image_url']['url']
|
90
|
-
for c in json['messages'][0]['content'] if c['type'] == 'image_url'
|
91
|
-
]
|
92
|
-
for k in range(json['n']):
|
93
|
-
choices.append(pg.Dict(
|
94
|
-
message=pg.Dict(
|
95
|
-
content=f'Sample {k} for message: {"".join(urls)}'
|
96
|
-
),
|
97
|
-
logprobs=None,
|
98
|
-
))
|
99
|
-
response = requests.Response()
|
100
|
-
response.status_code = 200
|
101
|
-
response._content = pg.to_json_str(
|
102
|
-
dict(
|
103
|
-
choices=choices,
|
104
|
-
usage=lf.LMSamplingUsage(
|
105
|
-
prompt_tokens=100,
|
106
|
-
completion_tokens=100,
|
107
|
-
total_tokens=200,
|
108
|
-
),
|
109
|
-
)
|
110
|
-
).encode()
|
111
|
-
return response
|
112
19
|
|
113
20
|
|
114
21
|
class OpenAITest(unittest.TestCase):
|
@@ -130,6 +37,15 @@ class OpenAITest(unittest.TestCase):
|
|
130
37
|
openai.Gpt35(api_key='test_key').resource_id, 'OpenAI(text-davinci-003)'
|
131
38
|
)
|
132
39
|
|
40
|
+
def test_headers(self):
|
41
|
+
self.assertEqual(
|
42
|
+
openai.Gpt35(api_key='test_key').headers,
|
43
|
+
{
|
44
|
+
'Content-Type': 'application/json',
|
45
|
+
'Authorization': 'Bearer test_key',
|
46
|
+
},
|
47
|
+
)
|
48
|
+
|
133
49
|
def test_max_concurrency(self):
|
134
50
|
self.assertGreater(openai.Gpt35(api_key='test_key').max_concurrency, 0)
|
135
51
|
|
@@ -156,340 +72,14 @@ class OpenAITest(unittest.TestCase):
|
|
156
72
|
)
|
157
73
|
)
|
158
74
|
|
159
|
-
def
|
160
|
-
with mock.patch('requests.Session.post') as mock_request:
|
161
|
-
mock_request.side_effect = mock_chat_completion_request
|
162
|
-
lm = openai.OpenAI(
|
163
|
-
model='gpt-4',
|
164
|
-
api_key='test_key',
|
165
|
-
organization='my_org',
|
166
|
-
project='my_project'
|
167
|
-
)
|
168
|
-
self.assertEqual(
|
169
|
-
lm('hello', sampling_options=lf.LMSamplingOptions(n=2)),
|
170
|
-
'Sample 0 for message.',
|
171
|
-
)
|
172
|
-
|
173
|
-
def test_call_chat_completion_with_logprobs(self):
|
174
|
-
with mock.patch('requests.Session.post') as mock_request:
|
175
|
-
mock_request.side_effect = mock_chat_completion_request
|
176
|
-
lm = openai.OpenAI(
|
177
|
-
model='gpt-4',
|
178
|
-
api_key='test_key',
|
179
|
-
organization='my_org',
|
180
|
-
project='my_project'
|
181
|
-
)
|
182
|
-
results = lm.sample(['hello'], logprobs=True)
|
183
|
-
self.assertEqual(len(results), 1)
|
184
|
-
self.assertEqual(
|
185
|
-
results[0],
|
186
|
-
lf.LMSamplingResult(
|
187
|
-
[
|
188
|
-
lf.LMSample(
|
189
|
-
response=lf.AIMessage(
|
190
|
-
text='Sample 0 for message.',
|
191
|
-
metadata={
|
192
|
-
'score': 0.0,
|
193
|
-
'logprobs': [(
|
194
|
-
'chosen_token',
|
195
|
-
0.5,
|
196
|
-
[
|
197
|
-
('alternative_token_1', 0.1),
|
198
|
-
('alternative_token_2', 0.1),
|
199
|
-
('alternative_token_3', 0.1),
|
200
|
-
],
|
201
|
-
)],
|
202
|
-
'is_cached': False,
|
203
|
-
'usage': lf.LMSamplingUsage(
|
204
|
-
prompt_tokens=100,
|
205
|
-
completion_tokens=100,
|
206
|
-
total_tokens=200,
|
207
|
-
estimated_cost=0.009,
|
208
|
-
),
|
209
|
-
},
|
210
|
-
tags=['lm-response'],
|
211
|
-
),
|
212
|
-
logprobs=[(
|
213
|
-
'chosen_token',
|
214
|
-
0.5,
|
215
|
-
[
|
216
|
-
('alternative_token_1', 0.1),
|
217
|
-
('alternative_token_2', 0.1),
|
218
|
-
('alternative_token_3', 0.1),
|
219
|
-
],
|
220
|
-
)],
|
221
|
-
)
|
222
|
-
],
|
223
|
-
usage=lf.LMSamplingUsage(
|
224
|
-
prompt_tokens=100,
|
225
|
-
completion_tokens=100,
|
226
|
-
total_tokens=200,
|
227
|
-
estimated_cost=0.009,
|
228
|
-
),
|
229
|
-
),
|
230
|
-
)
|
231
|
-
|
232
|
-
def test_call_chat_completion_vision(self):
|
233
|
-
with mock.patch('requests.Session.post') as mock_request:
|
234
|
-
mock_request.side_effect = mock_chat_completion_request_vision
|
235
|
-
lm_1 = openai.Gpt4Turbo(api_key='test_key')
|
236
|
-
lm_2 = openai.Gpt4VisionPreview(api_key='test_key')
|
237
|
-
for lm in (lm_1, lm_2):
|
238
|
-
self.assertEqual(
|
239
|
-
lm(
|
240
|
-
lf.UserMessage(
|
241
|
-
'hello <<[[image]]>>',
|
242
|
-
image=lf_modalities.Image.from_uri('https://fake/image')
|
243
|
-
),
|
244
|
-
sampling_options=lf.LMSamplingOptions(n=2)
|
245
|
-
),
|
246
|
-
'Sample 0 for message: https://fake/image',
|
247
|
-
)
|
248
|
-
lm_3 = openai.Gpt35Turbo(api_key='test_key')
|
249
|
-
with self.assertRaisesRegex(ValueError, 'Unsupported modality'):
|
250
|
-
lm_3(
|
251
|
-
lf.UserMessage(
|
252
|
-
'hello <<[[image]]>>',
|
253
|
-
image=lf_modalities.Image.from_uri('https://fake/image')
|
254
|
-
),
|
255
|
-
)
|
256
|
-
|
257
|
-
def test_sample_chat_completion(self):
|
258
|
-
with mock.patch('requests.Session.post') as mock_request:
|
259
|
-
mock_request.side_effect = mock_chat_completion_request
|
260
|
-
openai.SUPPORTED_MODELS_AND_SETTINGS['gpt-4'].update({
|
261
|
-
'cost_per_1k_input_tokens': 1.0,
|
262
|
-
'cost_per_1k_output_tokens': 1.0,
|
263
|
-
})
|
264
|
-
lm = openai.OpenAI(api_key='test_key', model='gpt-4')
|
265
|
-
results = lm.sample(
|
266
|
-
['hello', 'bye'], sampling_options=lf.LMSamplingOptions(n=3)
|
267
|
-
)
|
268
|
-
|
269
|
-
self.assertEqual(len(results), 2)
|
270
|
-
print(results[0])
|
271
|
-
self.assertEqual(
|
272
|
-
results[0],
|
273
|
-
lf.LMSamplingResult(
|
274
|
-
[
|
275
|
-
lf.LMSample(
|
276
|
-
lf.AIMessage(
|
277
|
-
'Sample 0 for message.',
|
278
|
-
score=0.0,
|
279
|
-
logprobs=None,
|
280
|
-
is_cached=False,
|
281
|
-
usage=lf.LMSamplingUsage(
|
282
|
-
prompt_tokens=33,
|
283
|
-
completion_tokens=33,
|
284
|
-
total_tokens=66,
|
285
|
-
estimated_cost=0.2 / 3,
|
286
|
-
),
|
287
|
-
tags=[lf.Message.TAG_LM_RESPONSE],
|
288
|
-
),
|
289
|
-
score=0.0,
|
290
|
-
logprobs=None,
|
291
|
-
),
|
292
|
-
lf.LMSample(
|
293
|
-
lf.AIMessage(
|
294
|
-
'Sample 1 for message.',
|
295
|
-
score=0.0,
|
296
|
-
logprobs=None,
|
297
|
-
is_cached=False,
|
298
|
-
usage=lf.LMSamplingUsage(
|
299
|
-
prompt_tokens=33,
|
300
|
-
completion_tokens=33,
|
301
|
-
total_tokens=66,
|
302
|
-
estimated_cost=0.2 / 3,
|
303
|
-
),
|
304
|
-
tags=[lf.Message.TAG_LM_RESPONSE],
|
305
|
-
),
|
306
|
-
score=0.0,
|
307
|
-
logprobs=None,
|
308
|
-
),
|
309
|
-
lf.LMSample(
|
310
|
-
lf.AIMessage(
|
311
|
-
'Sample 2 for message.',
|
312
|
-
score=0.0,
|
313
|
-
logprobs=None,
|
314
|
-
is_cached=False,
|
315
|
-
usage=lf.LMSamplingUsage(
|
316
|
-
prompt_tokens=33,
|
317
|
-
completion_tokens=33,
|
318
|
-
total_tokens=66,
|
319
|
-
estimated_cost=0.2 / 3,
|
320
|
-
),
|
321
|
-
tags=[lf.Message.TAG_LM_RESPONSE],
|
322
|
-
),
|
323
|
-
score=0.0,
|
324
|
-
logprobs=None,
|
325
|
-
),
|
326
|
-
],
|
327
|
-
usage=lf.LMSamplingUsage(
|
328
|
-
prompt_tokens=100, completion_tokens=100, total_tokens=200,
|
329
|
-
estimated_cost=0.2,
|
330
|
-
),
|
331
|
-
),
|
332
|
-
)
|
75
|
+
def test_estimate_cost(self):
|
333
76
|
self.assertEqual(
|
334
|
-
|
335
|
-
|
336
|
-
[
|
337
|
-
lf.LMSample(
|
338
|
-
lf.AIMessage(
|
339
|
-
'Sample 0 for message.',
|
340
|
-
score=0.0,
|
341
|
-
logprobs=None,
|
342
|
-
is_cached=False,
|
343
|
-
usage=lf.LMSamplingUsage(
|
344
|
-
prompt_tokens=33,
|
345
|
-
completion_tokens=33,
|
346
|
-
total_tokens=66,
|
347
|
-
estimated_cost=0.2 / 3,
|
348
|
-
),
|
349
|
-
tags=[lf.Message.TAG_LM_RESPONSE],
|
350
|
-
),
|
351
|
-
score=0.0,
|
352
|
-
logprobs=None,
|
353
|
-
),
|
354
|
-
lf.LMSample(
|
355
|
-
lf.AIMessage(
|
356
|
-
'Sample 1 for message.',
|
357
|
-
score=0.0,
|
358
|
-
logprobs=None,
|
359
|
-
is_cached=False,
|
360
|
-
usage=lf.LMSamplingUsage(
|
361
|
-
prompt_tokens=33,
|
362
|
-
completion_tokens=33,
|
363
|
-
total_tokens=66,
|
364
|
-
estimated_cost=0.2 / 3,
|
365
|
-
),
|
366
|
-
tags=[lf.Message.TAG_LM_RESPONSE],
|
367
|
-
),
|
368
|
-
score=0.0,
|
369
|
-
logprobs=None,
|
370
|
-
),
|
371
|
-
lf.LMSample(
|
372
|
-
lf.AIMessage(
|
373
|
-
'Sample 2 for message.',
|
374
|
-
score=0.0,
|
375
|
-
logprobs=None,
|
376
|
-
is_cached=False,
|
377
|
-
usage=lf.LMSamplingUsage(
|
378
|
-
prompt_tokens=33,
|
379
|
-
completion_tokens=33,
|
380
|
-
total_tokens=66,
|
381
|
-
estimated_cost=0.2 / 3,
|
382
|
-
),
|
383
|
-
tags=[lf.Message.TAG_LM_RESPONSE],
|
384
|
-
),
|
385
|
-
score=0.0,
|
386
|
-
logprobs=None,
|
387
|
-
),
|
388
|
-
],
|
389
|
-
usage=lf.LMSamplingUsage(
|
390
|
-
prompt_tokens=100, completion_tokens=100, total_tokens=200,
|
391
|
-
estimated_cost=0.2,
|
392
|
-
),
|
77
|
+
openai.Gpt4(api_key='test_key').estimate_cost(
|
78
|
+
num_input_tokens=100, num_output_tokens=100
|
393
79
|
),
|
80
|
+
0.009
|
394
81
|
)
|
395
82
|
|
396
|
-
def test_sample_with_contextual_options(self):
|
397
|
-
with mock.patch('requests.Session.post') as mock_request:
|
398
|
-
mock_request.side_effect = mock_chat_completion_request
|
399
|
-
lm = openai.OpenAI(api_key='test_key', model='text-davinci-003')
|
400
|
-
with lf.use_settings(sampling_options=lf.LMSamplingOptions(n=2)):
|
401
|
-
results = lm.sample(['hello'])
|
402
|
-
|
403
|
-
self.assertEqual(len(results), 1)
|
404
|
-
self.assertEqual(
|
405
|
-
results[0],
|
406
|
-
lf.LMSamplingResult(
|
407
|
-
[
|
408
|
-
lf.LMSample(
|
409
|
-
lf.AIMessage(
|
410
|
-
'Sample 0 for message.',
|
411
|
-
score=0.0,
|
412
|
-
logprobs=None,
|
413
|
-
is_cached=False,
|
414
|
-
usage=lf.LMSamplingUsage(
|
415
|
-
prompt_tokens=50,
|
416
|
-
completion_tokens=50,
|
417
|
-
total_tokens=100,
|
418
|
-
),
|
419
|
-
tags=[lf.Message.TAG_LM_RESPONSE],
|
420
|
-
),
|
421
|
-
score=0.0,
|
422
|
-
logprobs=None,
|
423
|
-
),
|
424
|
-
lf.LMSample(
|
425
|
-
lf.AIMessage(
|
426
|
-
'Sample 1 for message.',
|
427
|
-
score=0.0,
|
428
|
-
logprobs=None,
|
429
|
-
is_cached=False,
|
430
|
-
usage=lf.LMSamplingUsage(
|
431
|
-
prompt_tokens=50,
|
432
|
-
completion_tokens=50,
|
433
|
-
total_tokens=100,
|
434
|
-
),
|
435
|
-
tags=[lf.Message.TAG_LM_RESPONSE],
|
436
|
-
),
|
437
|
-
score=0.0,
|
438
|
-
logprobs=None,
|
439
|
-
),
|
440
|
-
],
|
441
|
-
usage=lf.LMSamplingUsage(
|
442
|
-
prompt_tokens=100, completion_tokens=100, total_tokens=200
|
443
|
-
),
|
444
|
-
)
|
445
|
-
)
|
446
|
-
|
447
|
-
def test_call_with_system_message(self):
|
448
|
-
with mock.patch('requests.Session.post') as mock_request:
|
449
|
-
mock_request.side_effect = mock_chat_completion_request
|
450
|
-
lm = openai.OpenAI(api_key='test_key', model='gpt-4')
|
451
|
-
self.assertEqual(
|
452
|
-
lm(
|
453
|
-
lf.UserMessage(
|
454
|
-
'hello',
|
455
|
-
system_message='hi',
|
456
|
-
),
|
457
|
-
sampling_options=lf.LMSamplingOptions(n=2)
|
458
|
-
),
|
459
|
-
'''Sample 0 for message. system=[{'type': 'text', 'text': 'hi'}]''',
|
460
|
-
)
|
461
|
-
|
462
|
-
def test_call_with_json_schema(self):
|
463
|
-
with mock.patch('requests.Session.post') as mock_request:
|
464
|
-
mock_request.side_effect = mock_chat_completion_request
|
465
|
-
lm = openai.OpenAI(api_key='test_key', model='gpt-4')
|
466
|
-
self.assertEqual(
|
467
|
-
lm(
|
468
|
-
lf.UserMessage(
|
469
|
-
'hello',
|
470
|
-
json_schema={
|
471
|
-
'type': 'object',
|
472
|
-
'properties': {
|
473
|
-
'name': {'type': 'string'},
|
474
|
-
},
|
475
|
-
'required': ['name'],
|
476
|
-
'title': 'Person',
|
477
|
-
}
|
478
|
-
),
|
479
|
-
sampling_options=lf.LMSamplingOptions(n=2)
|
480
|
-
),
|
481
|
-
'Sample 0 for message. format=json_schema',
|
482
|
-
)
|
483
|
-
|
484
|
-
# Test bad json schema.
|
485
|
-
with self.assertRaisesRegex(ValueError, '`json_schema` must be a dict'):
|
486
|
-
lm(lf.UserMessage('hello', json_schema='foo'))
|
487
|
-
|
488
|
-
with self.assertRaisesRegex(
|
489
|
-
ValueError, 'The root of `json_schema` must have a `title` field'
|
490
|
-
):
|
491
|
-
lm(lf.UserMessage('hello', json_schema={}))
|
492
|
-
|
493
83
|
|
494
84
|
if __name__ == '__main__':
|
495
85
|
unittest.main()
|
langfun/core/modalities/mime.py
CHANGED
@@ -138,9 +138,17 @@ class Mime(lf.Modality):
|
|
138
138
|
|
139
139
|
@property
|
140
140
|
def content_uri(self) -> str:
|
141
|
+
"""Returns the URI with encoded content."""
|
141
142
|
base64_content = base64.b64encode(self.to_bytes()).decode()
|
142
143
|
return f'data:{self.mime_type};base64,{base64_content}'
|
143
144
|
|
145
|
+
@property
|
146
|
+
def embeddable_uri(self) -> str:
|
147
|
+
"""Returns the URI that can be embedded in HTML."""
|
148
|
+
if self.uri and self.uri.lower().startswith(('http:', 'https:', 'ftp:')):
|
149
|
+
return self.uri
|
150
|
+
return self.content_uri
|
151
|
+
|
144
152
|
@classmethod
|
145
153
|
def from_uri(cls, uri: str, **kwargs) -> 'Mime':
|
146
154
|
if cls is Mime:
|
@@ -23,12 +23,12 @@ import pyglove as pg
|
|
23
23
|
|
24
24
|
def mock_request(*args, **kwargs):
|
25
25
|
del args, kwargs
|
26
|
-
return pg.Dict(content='foo')
|
26
|
+
return pg.Dict(content=b'foo')
|
27
27
|
|
28
28
|
|
29
29
|
def mock_readfile(*args, **kwargs):
|
30
30
|
del args, kwargs
|
31
|
-
return 'bar'
|
31
|
+
return b'bar'
|
32
32
|
|
33
33
|
|
34
34
|
class CustomMimeTest(unittest.TestCase):
|
@@ -65,17 +65,32 @@ class CustomMimeTest(unittest.TestCase):
|
|
65
65
|
):
|
66
66
|
mime.Custom('text/plain')
|
67
67
|
|
68
|
+
def test_uri(self):
|
69
|
+
content = mime.Custom.from_uri('http://mock/web/a.txt', mime='text/plain')
|
70
|
+
with mock.patch('requests.get') as mock_requests_stub:
|
71
|
+
mock_requests_stub.side_effect = mock_request
|
72
|
+
self.assertEqual(content.uri, 'http://mock/web/a.txt')
|
73
|
+
self.assertEqual(content.content_uri, 'data:text/plain;base64,Zm9v')
|
74
|
+
self.assertEqual(content.embeddable_uri, 'http://mock/web/a.txt')
|
75
|
+
|
76
|
+
content = mime.Custom.from_uri('a.txt', mime='text/plain')
|
77
|
+
with mock.patch('pyglove.io.readfile') as mock_readfile_stub:
|
78
|
+
mock_readfile_stub.side_effect = mock_readfile
|
79
|
+
self.assertEqual(content.uri, 'a.txt')
|
80
|
+
self.assertEqual(content.content_uri, 'data:text/plain;base64,YmFy')
|
81
|
+
self.assertEqual(content.embeddable_uri, 'data:text/plain;base64,YmFy')
|
82
|
+
|
68
83
|
def test_from_uri(self):
|
69
84
|
content = mime.Custom.from_uri('http://mock/web/a.txt', mime='text/plain')
|
70
85
|
with mock.patch('requests.get') as mock_requests_stub:
|
71
86
|
mock_requests_stub.side_effect = mock_request
|
72
|
-
self.assertEqual(content.to_bytes(), 'foo')
|
87
|
+
self.assertEqual(content.to_bytes(), b'foo')
|
73
88
|
self.assertEqual(content.mime_type, 'text/plain')
|
74
89
|
|
75
90
|
content = mime.Custom.from_uri('a.txt', mime='text/plain')
|
76
91
|
with mock.patch('pyglove.io.readfile') as mock_readfile_stub:
|
77
92
|
mock_readfile_stub.side_effect = mock_readfile
|
78
|
-
self.assertEqual(content.to_bytes(), 'bar')
|
93
|
+
self.assertEqual(content.to_bytes(), b'bar')
|
79
94
|
self.assertEqual(content.mime_type, 'text/plain')
|
80
95
|
|
81
96
|
def assert_html_content(self, html, expected):
|
langfun/core/modality_test.py
CHANGED
@@ -11,7 +11,6 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
-
"""Tests for modality."""
|
15
14
|
from typing import Any
|
16
15
|
import unittest
|
17
16
|
|
@@ -16,7 +16,7 @@ langfun/core/memory.py,sha256=f-asN1F7Vehgdn_fK84v73GrEUOxRtaW934keutTKjk,2416
|
|
16
16
|
langfun/core/message.py,sha256=16oiMpg9O9VKrgpfrvJrfvga3n3FzUuD_zdWb9nvSWA,25686
|
17
17
|
langfun/core/message_test.py,sha256=jtZoNBNbA99i2fjoKg5vTRgoUe84J4MH8ZMGakGmTHs,32577
|
18
18
|
langfun/core/modality.py,sha256=K8pUGuMpfWcOtVcXC_OqVjro1-RhHF6ddQni61DuYzM,4166
|
19
|
-
langfun/core/modality_test.py,sha256=
|
19
|
+
langfun/core/modality_test.py,sha256=0WL_yd3B4K-FviWdSpDnOwj0f9TQI0v9t6X0vWvvJbo,2415
|
20
20
|
langfun/core/natural_language.py,sha256=3ynSnaYQnjE60LIPK5fyMgdIjubnPYZwzGq4rWPeloE,1177
|
21
21
|
langfun/core/natural_language_test.py,sha256=LHGU_1ytbkGuSZQFIFP7vP3dBlcY4-A12fT6dbjUA0E,1424
|
22
22
|
langfun/core/sampling.py,sha256=SCnS5PFJWNVxSKvSkSCNRUmruvScun8UcNN4gafuXcw,5866
|
@@ -75,25 +75,27 @@ langfun/core/eval/v2/reporting.py,sha256=QOp5jX761Esvi5w_UIRLDqPY_XRO6ru02-DOrdq
|
|
75
75
|
langfun/core/eval/v2/reporting_test.py,sha256=UmYSAQvD3AIXsSyWQ-WD2uLtEISYpmBeoKY5u5Qwc8E,5696
|
76
76
|
langfun/core/eval/v2/runners.py,sha256=DKEmSlGXjOXKWFdBhTpLy7tMsBHZHd1Brl3hWIngsSQ,15931
|
77
77
|
langfun/core/eval/v2/runners_test.py,sha256=A37fKK2MvAVTiShsg_laluJzJ9AuAQn52k7HPbfD0Ks,11666
|
78
|
-
langfun/core/llms/__init__.py,sha256=
|
78
|
+
langfun/core/llms/__init__.py,sha256=Ntr0kvHc17VEZ5EV9fCoYY1kzRvQxCoZrtDRYNiMWCs,6742
|
79
79
|
langfun/core/llms/anthropic.py,sha256=a5MmnFsBA0CbfvwzXT1v_0fqLRMrhUNdh1tx6469PQ4,14357
|
80
80
|
langfun/core/llms/anthropic_test.py,sha256=-2U4kc_pgBM7wqxu8RuxzyHPGww1EAWqKUvN4PW8Btw,8058
|
81
81
|
langfun/core/llms/compositional.py,sha256=csW_FLlgL-tpeyCOTVvfUQkMa_zCN5Y2I-YbSNuK27U,2872
|
82
82
|
langfun/core/llms/compositional_test.py,sha256=4eTnOer-DncRKGaIJW2ZQQMLnt5r2R0UIx_DYOvGAQo,2027
|
83
|
-
langfun/core/llms/deepseek.py,sha256=
|
84
|
-
langfun/core/llms/deepseek_test.py,sha256=
|
83
|
+
langfun/core/llms/deepseek.py,sha256=Y7DlLUWrukbPVyBMesppd-m75Q-PxD0b3KnMKaoY_8I,3744
|
84
|
+
langfun/core/llms/deepseek_test.py,sha256=dS72i52bwMpCN4dJDvpJI59AnNChpwxS5eYYFrhGh90,1843
|
85
85
|
langfun/core/llms/fake.py,sha256=gCHBYBLvBCsC78HI1hpoqXCS-p1FMTgY1P1qh_sGBPk,3070
|
86
86
|
langfun/core/llms/fake_test.py,sha256=2h13qkwEz_JR0mtUDPxdAhQo7MueXaFSwsD2DIRDW9g,7653
|
87
87
|
langfun/core/llms/gemini.py,sha256=tfM4vrt0WnvnrxRhWXZWh7Gp8dYYfMnSbi9uOstkSak,17399
|
88
88
|
langfun/core/llms/gemini_test.py,sha256=2ERhYWCJwnfDTQbCaZHFuB1TdWJFrOBS7yyCBInIdQk,6129
|
89
89
|
langfun/core/llms/google_genai.py,sha256=85Vmx5QmsziON03PRsFQINSu5NF6pAAuFFhUdDteWGc,3662
|
90
90
|
langfun/core/llms/google_genai_test.py,sha256=JZf_cbQ4GGGpwiQCLjFJn7V4jxBBqgZhIx91AzbGKVo,1250
|
91
|
-
langfun/core/llms/groq.py,sha256=
|
92
|
-
langfun/core/llms/groq_test.py,sha256=
|
93
|
-
langfun/core/llms/llama_cpp.py,sha256=
|
94
|
-
langfun/core/llms/llama_cpp_test.py,sha256=
|
95
|
-
langfun/core/llms/openai.py,sha256=
|
96
|
-
langfun/core/llms/
|
91
|
+
langfun/core/llms/groq.py,sha256=oGxyyCi5TtMVu2POdO8pXS7pK4Es56FtqjghZIGYopc,7579
|
92
|
+
langfun/core/llms/groq_test.py,sha256=9aOD3nO4dEoH57B-5iOr5DQjG0vyv1jzFtAe7HfoiNg,1963
|
93
|
+
langfun/core/llms/llama_cpp.py,sha256=Z7P3gc4xeIjc2bX0Ey1y5EUYJVMnMa2Q67PZ9iye9sE,1409
|
94
|
+
langfun/core/llms/llama_cpp_test.py,sha256=wfTO7nmUwL65U2kK9P9fcMt92JjNDuVia4G1E7znf_4,1086
|
95
|
+
langfun/core/llms/openai.py,sha256=CHUg8c0FE30LZkhvj0Kc8w0oqckbZhrp45GA94HWPs8,16614
|
96
|
+
langfun/core/llms/openai_compatible.py,sha256=MF9JCc0uTPkIK95uvQTMIBXk4z_xKQMZqQHFaVmXwcA,5898
|
97
|
+
langfun/core/llms/openai_compatible_test.py,sha256=TSEKhwy7eg-BW5tgRHwoprngE4j5F9HzEVuRoPK8sWw,16183
|
98
|
+
langfun/core/llms/openai_test.py,sha256=m85YjGCvWvV5ZYagjC0FqI0FcqyCEVCbUUs8Wm3iUrc,2475
|
97
99
|
langfun/core/llms/rest.py,sha256=sWbYUV8S3SuOg9giq7xwD-xDRfaF7NP_ig7bI52-Rj4,3442
|
98
100
|
langfun/core/llms/rest_test.py,sha256=NZ3Nf0XQVpT9kLP5cBVo_yBHLI7vWTYhWQxYEJVMGs4,3472
|
99
101
|
langfun/core/llms/vertexai.py,sha256=MuwLPTJ6-9x2uRDCSM1_biPK6M76FFlL1ezf5OmobDA,5504
|
@@ -110,8 +112,8 @@ langfun/core/modalities/audio.py,sha256=qCrVCX690SG0ps-ZfOtNWvHn_CmdJsmxF7GySScW
|
|
110
112
|
langfun/core/modalities/audio_test.py,sha256=yyGEBYqMXmNs_F2dEtj-PX8HE040vqh-YQppsvdxPw4,2025
|
111
113
|
langfun/core/modalities/image.py,sha256=ovcX8NLBNv8WzxAdhQ-u4VQfHVBkWijRj_oiNwhE9lk,1768
|
112
114
|
langfun/core/modalities/image_test.py,sha256=XMgtJXY75R5eo0CZ222D1QUy57_hESnttmCGWwDLt7k,3824
|
113
|
-
langfun/core/modalities/mime.py,sha256=
|
114
|
-
langfun/core/modalities/mime_test.py,sha256=
|
115
|
+
langfun/core/modalities/mime.py,sha256=xZpnENHqwIUBLbT3s3izJvAPnw3XTtXe2v1y4mz9UkI,7856
|
116
|
+
langfun/core/modalities/mime_test.py,sha256=Lg21nKFi--a884gnI7tFS4cHnwByEEhWg4Ugsr-UCbw,5277
|
115
117
|
langfun/core/modalities/ms_office.py,sha256=0PnM6W9SovVfJNd4XCpUfOcGBuvj4hlA1zqPjdsJNFM,3725
|
116
118
|
langfun/core/modalities/ms_office_test.py,sha256=rrDBx51ELAqRaUX6Y6tgg0k3tEFHOlRMfUpeULD7mlo,87868
|
117
119
|
langfun/core/modalities/pdf.py,sha256=mfaeCbUA4JslFVTARiJh8hW7imvL4tLVw9gUhO5bAZA,727
|
@@ -148,8 +150,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
|
|
148
150
|
langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
|
149
151
|
langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
|
150
152
|
langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
|
151
|
-
langfun-0.1.2.
|
152
|
-
langfun-0.1.2.
|
153
|
-
langfun-0.1.2.
|
154
|
-
langfun-0.1.2.
|
155
|
-
langfun-0.1.2.
|
153
|
+
langfun-0.1.2.dev202501110804.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
154
|
+
langfun-0.1.2.dev202501110804.dist-info/METADATA,sha256=U4RBtp5S0e6UddQqFSW3ywZeLG_2vJRmcFTR7m5cOCQ,8172
|
155
|
+
langfun-0.1.2.dev202501110804.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
156
|
+
langfun-0.1.2.dev202501110804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
|
157
|
+
langfun-0.1.2.dev202501110804.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{langfun-0.1.2.dev202501090804.dist-info → langfun-0.1.2.dev202501110804.dist-info}/top_level.txt
RENAMED
File without changes
|