langfun 0.0.2.dev20240209__py3-none-any.whl → 0.0.2.dev20240210__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.
@@ -26,7 +26,7 @@ class QueryStructure(mapping.Mapping):
26
26
  """Query an object out from a natural language text."""
27
27
 
28
28
  context_title = 'CONTEXT'
29
- input_title = 'USER_REQUEST'
29
+ input_title = 'INPUT_OBJECT'
30
30
 
31
31
  # Mark schema as required.
32
32
  schema: pg.typing.Annotated[
@@ -65,11 +65,6 @@ class QueryStructurePython(QueryStructure):
65
65
  preamble = """
66
66
  Please respond to the last {{ input_title }} with {{ output_title }} according to {{ schema_title }}.
67
67
 
68
- INSTRUCTIONS:
69
- 1. Only respond with the required {{ output_title }} encapsulated with python markdown as illustrated by the given example.
70
- 2. Don't add any comments in the response.
71
- 3. {{ output_title }} must strictly follow the {{ schema_title }}.
72
-
73
68
  {{ input_title }}:
74
69
  1 + 1 =
75
70
 
@@ -87,8 +82,8 @@ class QueryStructurePython(QueryStructure):
87
82
  ```
88
83
  """
89
84
  protocol = 'python'
90
- schema_title = 'RESULT_TYPE'
91
- output_title = 'RESULT_OBJECT'
85
+ schema_title = 'OUTPUT_TYPE'
86
+ output_title = 'OUTPUT_OBJECT'
92
87
 
93
88
 
94
89
  def _query_structure_cls(
@@ -115,7 +115,14 @@ class QueryTest(unittest.TestCase):
115
115
  x=1,
116
116
  y=2,
117
117
  lm=lm.clone(),
118
- expected_snippet='\n\nUSER_REQUEST:\n What is 1 + 2?\n\n',
118
+ expected_snippet=(
119
+ 'Please respond to the last INPUT_OBJECT with OUTPUT_OBJECT'
120
+ ' according to OUTPUT_TYPE.\n\nINPUT_OBJECT:\n 1 + 1'
121
+ ' =\n\nOUTPUT_TYPE:\n Answer\n\n ```python\n class Answer:\n '
122
+ ' final_answer: int\n ```\n\nOUTPUT_OBJECT:\n ```python\n '
123
+ ' Answer(final_answer=2)\n ```\n\nINPUT_OBJECT:\n What is 1 +'
124
+ ' 2?\n\nOUTPUT_TYPE:\n int\n\nOUTPUT_OBJECT:'
125
+ ),
119
126
  )
120
127
 
121
128
  def test_str_to_str_render(self):
@@ -139,7 +146,7 @@ class QueryTest(unittest.TestCase):
139
146
  y=2,
140
147
  lm=lm.clone(),
141
148
  expected_snippet=(
142
- '\n\nUSER_REQUEST:\n ```python\n [\n 1\n ]\n ```\n\n'
149
+ '\n\nINPUT_OBJECT:\n ```python\n [\n 1\n ]\n ```\n\n'
143
150
  ),
144
151
  )
145
152
 
@@ -155,7 +162,7 @@ class QueryTest(unittest.TestCase):
155
162
  modalities.Image.from_bytes(b'mock_image'),
156
163
  int,
157
164
  lm=lm,
158
- expected_snippet='\n\nUSER_REQUEST:\n {{input}}\n\n',
165
+ expected_snippet='\n\nINPUT_OBJECT:\n {{input}}\n\n',
159
166
  expected_modalities=1,
160
167
  )
161
168
 
@@ -207,7 +214,7 @@ class QueryTest(unittest.TestCase):
207
214
  list[str],
208
215
  lm=lm,
209
216
  expected_snippet=inspect.cleandoc("""
210
- USER_REQUEST:
217
+ INPUT_OBJECT:
211
218
  ```python
212
219
  [
213
220
  ModalityRef(
@@ -238,17 +245,12 @@ class QueryStructurePythonTest(unittest.TestCase):
238
245
  self.assertEqual(
239
246
  l.render().text,
240
247
  inspect.cleandoc("""
241
- Please respond to the last USER_REQUEST with RESULT_OBJECT according to RESULT_TYPE.
242
-
243
- INSTRUCTIONS:
244
- 1. Only respond with the required RESULT_OBJECT encapsulated with python markdown as illustrated by the given example.
245
- 2. Don't add any comments in the response.
246
- 3. RESULT_OBJECT must strictly follow the RESULT_TYPE.
248
+ Please respond to the last INPUT_OBJECT with OUTPUT_OBJECT according to OUTPUT_TYPE.
247
249
 
248
- USER_REQUEST:
250
+ INPUT_OBJECT:
249
251
  1 + 1 =
250
252
 
251
- RESULT_TYPE:
253
+ OUTPUT_TYPE:
252
254
  Answer
253
255
 
254
256
  ```python
@@ -256,18 +258,18 @@ class QueryStructurePythonTest(unittest.TestCase):
256
258
  final_answer: int
257
259
  ```
258
260
 
259
- RESULT_OBJECT:
261
+ OUTPUT_OBJECT:
260
262
  ```python
261
263
  Answer(final_answer=2)
262
264
  ```
263
265
 
264
- USER_REQUEST:
266
+ INPUT_OBJECT:
265
267
  Compute 12 / 6 + 2.
266
268
 
267
- RESULT_TYPE:
269
+ OUTPUT_TYPE:
268
270
  int
269
271
 
270
- RESULT_OBJECT:
272
+ OUTPUT_OBJECT:
271
273
  """),
272
274
  )
273
275
 
@@ -287,17 +289,12 @@ class QueryStructurePythonTest(unittest.TestCase):
287
289
  self.assertEqual(
288
290
  l.render().text,
289
291
  inspect.cleandoc("""
290
- Please respond to the last USER_REQUEST with RESULT_OBJECT according to RESULT_TYPE.
291
-
292
- INSTRUCTIONS:
293
- 1. Only respond with the required RESULT_OBJECT encapsulated with python markdown as illustrated by the given example.
294
- 2. Don't add any comments in the response.
295
- 3. RESULT_OBJECT must strictly follow the RESULT_TYPE.
292
+ Please respond to the last INPUT_OBJECT with OUTPUT_OBJECT according to OUTPUT_TYPE.
296
293
 
297
- USER_REQUEST:
294
+ INPUT_OBJECT:
298
295
  1 + 1 =
299
296
 
300
- RESULT_TYPE:
297
+ OUTPUT_TYPE:
301
298
  Answer
302
299
 
303
300
  ```python
@@ -305,41 +302,41 @@ class QueryStructurePythonTest(unittest.TestCase):
305
302
  final_answer: int
306
303
  ```
307
304
 
308
- RESULT_OBJECT:
305
+ OUTPUT_OBJECT:
309
306
  ```python
310
307
  Answer(final_answer=2)
311
308
  ```
312
309
 
313
- USER_REQUEST:
310
+ INPUT_OBJECT:
314
311
  What is the answer of 1 plus 1?
315
312
 
316
- RESULT_TYPE:
313
+ OUTPUT_TYPE:
317
314
  int
318
315
 
319
- RESULT_OBJECT:
316
+ OUTPUT_OBJECT:
320
317
  ```python
321
318
  2
322
319
  ```
323
320
 
324
- USER_REQUEST:
321
+ INPUT_OBJECT:
325
322
  Compute the value of 3 + (2 * 6).
326
323
 
327
- RESULT_TYPE:
324
+ OUTPUT_TYPE:
328
325
  int
329
326
 
330
- RESULT_OBJECT:
327
+ OUTPUT_OBJECT:
331
328
  ```python
332
329
  15
333
330
  ```
334
331
 
335
332
 
336
- USER_REQUEST:
333
+ INPUT_OBJECT:
337
334
  Compute 12 / 6 + 2.
338
335
 
339
- RESULT_TYPE:
336
+ OUTPUT_TYPE:
340
337
  int
341
338
 
342
- RESULT_OBJECT:
339
+ OUTPUT_OBJECT:
343
340
  """),
344
341
  )
345
342
 
@@ -445,13 +442,13 @@ class QueryStructureJsonTest(unittest.TestCase):
445
442
  self.assertEqual(
446
443
  l.render().text,
447
444
  inspect.cleandoc("""
448
- Please respond to the last USER_REQUEST with JSON according to SCHEMA:
445
+ Please respond to the last INPUT_OBJECT with JSON according to SCHEMA:
449
446
 
450
447
  INSTRUCTIONS:
451
448
  1. If the schema has `_type`, carry it over to the JSON output.
452
449
  2. If a field from the schema cannot be extracted from the response, use null as the JSON value.
453
450
 
454
- USER_REQUEST:
451
+ INPUT_OBJECT:
455
452
  1 + 1 =
456
453
 
457
454
  SCHEMA:
@@ -460,7 +457,7 @@ class QueryStructureJsonTest(unittest.TestCase):
460
457
  JSON:
461
458
  {"result": {"_type": "langfun.core.structured.prompting.Answer", "final_answer": 2}}
462
459
 
463
- USER_REQUEST:
460
+ INPUT_OBJECT:
464
461
  Compute 12 / 6 + 2.
465
462
 
466
463
  SCHEMA:
@@ -482,13 +479,13 @@ class QueryStructureJsonTest(unittest.TestCase):
482
479
  self.assertEqual(
483
480
  l.render().text,
484
481
  inspect.cleandoc("""
485
- Please respond to the last USER_REQUEST with JSON according to SCHEMA:
482
+ Please respond to the last INPUT_OBJECT with JSON according to SCHEMA:
486
483
 
487
484
  INSTRUCTIONS:
488
485
  1. If the schema has `_type`, carry it over to the JSON output.
489
486
  2. If a field from the schema cannot be extracted from the response, use null as the JSON value.
490
487
 
491
- USER_REQUEST:
488
+ INPUT_OBJECT:
492
489
  1 + 1 =
493
490
 
494
491
  SCHEMA:
@@ -497,7 +494,7 @@ class QueryStructureJsonTest(unittest.TestCase):
497
494
  JSON:
498
495
  {"result": {"_type": "langfun.core.structured.prompting.Answer", "final_answer": 2}}
499
496
 
500
- USER_REQUEST:
497
+ INPUT_OBJECT:
501
498
  What is the answer of 1 plus 1?
502
499
 
503
500
  SCHEMA:
@@ -506,7 +503,7 @@ class QueryStructureJsonTest(unittest.TestCase):
506
503
  JSON:
507
504
  {"result": 2}
508
505
 
509
- USER_REQUEST:
506
+ INPUT_OBJECT:
510
507
  Compute the value of 3 + (2 * 6).
511
508
 
512
509
  SCHEMA:
@@ -516,7 +513,7 @@ class QueryStructureJsonTest(unittest.TestCase):
516
513
  {"result": 15}
517
514
 
518
515
 
519
- USER_REQUEST:
516
+ INPUT_OBJECT:
520
517
  Compute 12 / 6 + 2.
521
518
 
522
519
  SCHEMA:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.0.2.dev20240209
3
+ Version: 0.0.2.dev20240210
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -74,8 +74,8 @@ langfun/core/structured/mapping.py,sha256=lGkjhmvVdhBGgJmc5KbfT2xQjC1MuU4OCcCfsA
74
74
  langfun/core/structured/mapping_test.py,sha256=07DDCGbwytQHSMm7fCi5-Ly-JNgdV4ubHZq0wthX4A4,3338
75
75
  langfun/core/structured/parsing.py,sha256=V3i8-AuBI4zdpsi_f6H-mbQ3h0HPgCle2OnDQolWJnA,10244
76
76
  langfun/core/structured/parsing_test.py,sha256=2_Uf3LYNRON1-5ysEr75xiG_cAxR3ZiixSfvUQu6mOQ,20846
77
- langfun/core/structured/prompting.py,sha256=wTnbb2gO4MZ7RdwUTY6f7cR35qq8sSM0iZcyTPjwfA8,6663
78
- langfun/core/structured/prompting_test.py,sha256=8lakKCidYuRlf-U1KexTOqQdKrBXUt8fb2J7epCdt84,19143
77
+ langfun/core/structured/prompting.py,sha256=P8in3qHXCuwjfzLpplS5woQSHV5aheXgm2mFiqVQD4g,6384
78
+ langfun/core/structured/prompting_test.py,sha256=5lPsxUzyHEjOh0D5V5GEYjFFJZvUrebLV1aCCJS4H3Y,18971
79
79
  langfun/core/structured/schema.py,sha256=5DKba0LrvXCJFRY-NVfER3p54BLOB7M3Yi2-u5IAJTw,24115
80
80
  langfun/core/structured/schema_test.py,sha256=LEtCST5Bfwoke59I6Q1mnOJLf2cFXQwKwTeAkI2hgqM,20912
81
81
  langfun/core/templates/__init__.py,sha256=bO0eMsVJbi7sxEB2YlInKRQ2EVP-RyyKUwcD-8msuN4,927
@@ -87,8 +87,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
87
87
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
88
88
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
89
89
  langfun/core/templates/selfplay_test.py,sha256=IB5rWbjK_9CTkqEo1BclQPzFAKcIiusJckH8J19HFgI,2096
90
- langfun-0.0.2.dev20240209.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
91
- langfun-0.0.2.dev20240209.dist-info/METADATA,sha256=7arY2SNgfb7JcbwaIKwgOwTeRHElh_KNrWKiscHLdiM,3368
92
- langfun-0.0.2.dev20240209.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
93
- langfun-0.0.2.dev20240209.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
94
- langfun-0.0.2.dev20240209.dist-info/RECORD,,
90
+ langfun-0.0.2.dev20240210.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
91
+ langfun-0.0.2.dev20240210.dist-info/METADATA,sha256=ElQEyYI0rdK4qXwsFpYV7Vn91IZ4tdMBZJKYr4e1Omk,3368
92
+ langfun-0.0.2.dev20240210.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
93
+ langfun-0.0.2.dev20240210.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
94
+ langfun-0.0.2.dev20240210.dist-info/RECORD,,