langfun 0.1.0__py3-none-any.whl → 0.1.1__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/__init__.py CHANGED
@@ -75,4 +75,4 @@ CodeError = coding.CodeError
75
75
  # pylint: enable=g-import-not-at-top
76
76
  # pylint: enable=g-bad-import-order
77
77
 
78
- __version__ = "0.1.0"
78
+ __version__ = "0.1.1"
@@ -161,7 +161,8 @@ class PythonCodeParser(lf.Component):
161
161
 
162
162
  # Peek forward to see if it could be a valid string.
163
163
  nt, nnt_start = _next_token(code_text, i + 1)
164
- if nt in (',', '[', ']', '}', ')', '+', '*', '%', '\n', ':'):
164
+ if (len(c) == 3
165
+ or nt in (',', '[', ']', '}', ')', '+', '*', '%', '\n', ':')):
165
166
  end_quote = True
166
167
  elif nt == ' ':
167
168
  # Detect if . could be a method invocation.
@@ -256,18 +256,18 @@ class ProgressBarTest(unittest.TestCase):
256
256
  with contextlib.redirect_stderr(string_io):
257
257
  bar_id = concurrent.ProgressBar.install(None, 4)
258
258
  concurrent.ProgressBar.update(bar_id, 1, postfix=None)
259
- self.assertIn('1/4', string_io.getvalue())
260
259
  concurrent.ProgressBar.update(bar_id, 1, postfix='hello')
261
- self.assertIn('2/4', string_io.getvalue())
262
- self.assertIn('hello', string_io.getvalue())
263
260
  concurrent.ProgressBar.update(bar_id, color='lightgreen')
264
- self.assertIn('2/4', string_io.getvalue())
265
261
  concurrent.ProgressBar.update(bar_id, 2, postfix=dict(x=1))
266
- self.assertIn('4/4', string_io.getvalue())
267
- self.assertIn('x=1', string_io.getvalue())
268
262
  with self.assertRaisesRegex(ValueError, 'Unsupported postfix'):
269
263
  concurrent.ProgressBar.update(bar_id, 0, postfix=1)
270
264
  concurrent.ProgressBar.uninstall(bar_id)
265
+ self.assertIn('1/4', string_io.getvalue())
266
+ self.assertIn('2/4', string_io.getvalue())
267
+ self.assertIn('hello', string_io.getvalue())
268
+ self.assertNotIn('3/4', string_io.getvalue())
269
+ self.assertIn('4/4', string_io.getvalue())
270
+ self.assertIn('x=1', string_io.getvalue())
271
271
 
272
272
 
273
273
  class ConcurrentMapTest(unittest.TestCase):
langfun/core/message.py CHANGED
@@ -318,7 +318,7 @@ class Message(natural_language.NaturalLanguageFormattable, pg.Object):
318
318
  while chunk_start < len(text):
319
319
  ref_start = text.find(modality.Modality.REF_START, ref_end)
320
320
  if ref_start == -1:
321
- add_text_chunk(text[chunk_start:].strip())
321
+ add_text_chunk(text[chunk_start:].strip(' '))
322
322
  break
323
323
 
324
324
  var_start = ref_start + len(modality.Modality.REF_START)
@@ -330,29 +330,31 @@ class Message(natural_language.NaturalLanguageFormattable, pg.Object):
330
330
  var_name = text[var_start:ref_end].strip()
331
331
  var_value = self.get_modality(var_name)
332
332
  if var_value is not None:
333
- add_text_chunk(text[chunk_start:ref_start].strip())
333
+ add_text_chunk(text[chunk_start:ref_start].strip(' '))
334
334
  chunks.append(var_value)
335
335
  chunk_start = ref_end + len(modality.Modality.REF_END)
336
336
  return chunks
337
337
 
338
338
  @classmethod
339
339
  def from_chunks(
340
- cls, chunks: list[str | modality.Modality], separator: str = '\n'
340
+ cls, chunks: list[str | modality.Modality], separator: str = ' '
341
341
  ) -> 'Message':
342
342
  """Assembly a message from a list of string or modality objects."""
343
343
  fused_text = io.StringIO()
344
344
  ref_index = 0
345
345
  metadata = dict()
346
-
346
+ last_char = None
347
347
  for i, chunk in enumerate(chunks):
348
- if i > 0:
348
+ if i > 0 and last_char not in ('\t', ' ', '\n'):
349
349
  fused_text.write(separator)
350
350
  if isinstance(chunk, str):
351
351
  fused_text.write(chunk)
352
+ last_char = chunk[-1]
352
353
  else:
353
354
  assert isinstance(chunk, modality.Modality), chunk
354
355
  var_name = f'obj{ref_index}'
355
356
  fused_text.write(modality.Modality.text_marker(var_name))
357
+ last_char = modality.Modality.REF_END[-1]
356
358
  # Make a reference if the chunk is already owned by another object
357
359
  # to avoid copy.
358
360
  metadata[var_name] = pg.maybe_ref(chunk)
@@ -295,7 +295,7 @@ class MessageTest(unittest.TestCase):
295
295
  [
296
296
  'Hi, this is',
297
297
  CustomModality('foo'),
298
- 'and this is {{b}}.',
298
+ 'and this is {{b}}.\n',
299
299
  CustomModality('bar'),
300
300
  '{{something else',
301
301
  ],
@@ -306,11 +306,8 @@ class MessageTest(unittest.TestCase):
306
306
  message.AIMessage.from_chunks(chunks),
307
307
  message.AIMessage(
308
308
  inspect.cleandoc("""
309
- Hi, this is
310
- <<[[obj0]]>>
311
- and this is {{b}}.
312
- <<[[obj1]]>>
313
- {{something else
309
+ Hi, this is <<[[obj0]]>> and this is {{b}}.
310
+ <<[[obj1]]>> {{something else
314
311
  """),
315
312
  obj0=pg.Ref(m.a),
316
313
  obj1=pg.Ref(m.x.c),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langfun
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -26,14 +26,14 @@ Requires-Dist: google-generativeai >=0.3.2
26
26
  Requires-Dist: jinja2 >=3.1.2
27
27
  Requires-Dist: openai ==0.27.2
28
28
  Requires-Dist: openpyxl >=3.1.0
29
- Requires-Dist: pandas >=2.1.4
29
+ Requires-Dist: pandas >=2.0.3
30
30
  Requires-Dist: pyglove >=0.4.5.dev20240423
31
31
  Requires-Dist: python-docx >=0.8.11
32
32
  Requires-Dist: python-magic >=0.4.27
33
33
  Requires-Dist: requests >=2.31.0
34
34
  Requires-Dist: termcolor ==1.1.0
35
35
  Requires-Dist: tqdm >=4.64.1
36
- Requires-Dist: pillow >=10.1.0
36
+ Requires-Dist: pillow >=10.0.0
37
37
 
38
38
  <div align="center">
39
39
  <img src="https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg" width="520px" alt="logo"></img>
@@ -82,12 +82,11 @@ Langfun is *simple and elegant*:
82
82
  import langfun as lf
83
83
  import pyglove as pg
84
84
 
85
- from typing import Literal
86
85
  from IPython import display
87
86
 
88
87
  class Item(pg.Object):
89
88
  name: str
90
- size: Literal['large', 'medium', 'small']
89
+ color: str
91
90
 
92
91
  class ImageDescription(pg.Object):
93
92
  items: list[Item]
@@ -1,9 +1,9 @@
1
- langfun/__init__.py,sha256=mPN6TszWxnQKhlnMGvEvu56etujXb1Zcy4DDMUy1IH8,2274
1
+ langfun/__init__.py,sha256=ZqERg4fvvtFwr5L41Lfev9FSuCBm8PbQrZmcKvvloxE,2274
2
2
  langfun/core/__init__.py,sha256=Mdp1a2YnXdSmfTfbUwuAnEWYbjA3rXXGtbxl5fljZyg,4812
3
3
  langfun/core/component.py,sha256=Icyoj9ICoJoK2r2PHbrFXbxnseOr9QZZOvKWklLWNo8,10276
4
4
  langfun/core/component_test.py,sha256=q15Xn51cVTu2RKxZ9U5VQgT3bm6RQ4638bKhWBtvW5o,8220
5
5
  langfun/core/concurrent.py,sha256=TRc49pJ3HQro2kb5FtcWkHjhBm8UcgE8RJybU5cU3-0,24537
6
- langfun/core/concurrent_test.py,sha256=mwFMZhDUdppnDr7vDSTwcbMHwrdsIoKJwRYNtl4ZWL4,15185
6
+ langfun/core/concurrent_test.py,sha256=9HWnS4ja5Ji1ALfJs2zIt7w4w0oNm9dOZM7bgzoX5ag,15176
7
7
  langfun/core/console.py,sha256=bk5rNPNm9rMGW5YT2HixxU04p2umnoabn5SDz6Dqe88,2317
8
8
  langfun/core/console_test.py,sha256=5SYJdxpJGLgdSSQqqMPoA1X6jpsLD8rgcyk-EgI65oE,1077
9
9
  langfun/core/langfunc.py,sha256=RvIcRjIq0jWYRu1xim-FYe4HSrt97r3GMBO_PuagUmw,11060
@@ -13,8 +13,8 @@ langfun/core/language_model_test.py,sha256=TlNmVUfBfDQZzIiiBqCBTrxgcoyj2qNp3kONv
13
13
  langfun/core/logging.py,sha256=FyZRxUy2TTF6tWLhQCRpCvfH55WGUdNgQjUTK_SQLnY,5320
14
14
  langfun/core/logging_test.py,sha256=qvm3RObYP3knO2PnXR9evBRl4gH621GnjnwywbGbRfg,1833
15
15
  langfun/core/memory.py,sha256=f-asN1F7Vehgdn_fK84v73GrEUOxRtaW934keutTKjk,2416
16
- langfun/core/message.py,sha256=Rw3yC9HyGRjMhfDgyNjGlSCALEyDDbJ0_o6qTXeeDiQ,15738
17
- langfun/core/message_test.py,sha256=b6DDRoQ5j3uK-dc0QPSLelNTKaXX10MxJrRiI61iGX4,9574
16
+ langfun/core/message.py,sha256=3tm9HW_mnh0GmlyuJxMK8_KpQvx9GtXgVXYQTzoegJo,15882
17
+ langfun/core/message_test.py,sha256=74W5odVTvhY2U4KBBnHfTbCqD0z4cexO-9GWJQzRLO8,9516
18
18
  langfun/core/modality.py,sha256=Tla4t86DUYHpbZ2G7dy1r19fTj_Ga5XOvlYp6lbWa-Q,3512
19
19
  langfun/core/modality_test.py,sha256=HyZ5xONKQ0Fw18SzoWAq-Ob9njOXIIjBo1hNtw-rudw,2400
20
20
  langfun/core/natural_language.py,sha256=3ynSnaYQnjE60LIPK5fyMgdIjubnPYZwzGq4rWPeloE,1177
@@ -39,7 +39,7 @@ langfun/core/coding/python/execution.py,sha256=raZix62g2fwt6Lgykll2DFzkLlEjVqN9E
39
39
  langfun/core/coding/python/execution_test.py,sha256=lExY6GMLeuCsCKXgM2KbAPJ6kqSlfHmz3RG0-dqfVcI,7197
40
40
  langfun/core/coding/python/generation.py,sha256=xivSeOKGN00HnG1TLuFhPfP-JyRuRrSELxVJW2ngqIQ,7750
41
41
  langfun/core/coding/python/generation_test.py,sha256=54bgKr1DgzYFLoqR8bTn7Yjol0gPCuR6XvRltR4l6YM,2777
42
- langfun/core/coding/python/parsing.py,sha256=uyvI1c5OLZhMVK2Oltkl3oJxSLlG0wadlpQcYPEE0-U,7097
42
+ langfun/core/coding/python/parsing.py,sha256=LMg8REP4VDY0YQjtPAGNAW4rKlMNdSXF8m19wMT9yrY,7128
43
43
  langfun/core/coding/python/parsing_test.py,sha256=9vAWF484kWIm6JZq8NFiMgKUDhXV-deRl1QMmNERfAA,7386
44
44
  langfun/core/coding/python/permissions.py,sha256=1QWGHvzL8MM0Ok_auQ9tURqZHtdOfJaDpBzZ29GUE-c,2544
45
45
  langfun/core/coding/python/permissions_test.py,sha256=w5EDb8QxpxgJyZkojyzVWQvDfg366zn99-g__6TbPQ0,2699
@@ -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.0.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
121
- langfun-0.1.0.dist-info/METADATA,sha256=MUO2hj8fPm1zMlG9yIN8x0Ct1zisC39u769k5TlPJG0,5293
122
- langfun-0.1.0.dist-info/WHEEL,sha256=-oYQCr74JF3a37z2nRlQays_SX2MqOANoqVjBBAP2yE,91
123
- langfun-0.1.0.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
124
- langfun-0.1.0.dist-info/RECORD,,
120
+ langfun-0.1.1.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
121
+ langfun-0.1.1.dist-info/METADATA,sha256=wQ1jpdRAOtWbpPuoXL9m_0v0yUiFxraPcmJ8X6k6qms,5235
122
+ langfun-0.1.1.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
123
+ langfun-0.1.1.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
124
+ langfun-0.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (71.0.3)
2
+ Generator: setuptools (71.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5