langfun 0.1.2.dev202505170804__py3-none-any.whl → 0.1.2.dev202505180804__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.

Potentially problematic release.


This version of langfun might be problematic. Click here for more details.

@@ -31,10 +31,12 @@ class GeminiMessageConverter(lf.MessageConverter):
31
31
  'Chunk preprocessor for Langfun chunk to Gemini chunk conversion. '
32
32
  'It will be applied before each Langfun chunk is converted. '
33
33
  'If returns None, the chunk will be skipped.'
34
- )
34
+ ),
35
35
  ] = None
36
36
 
37
- def to_value(self, message: lf.Message) -> dict[str, Any]:
37
+ def to_value(
38
+ self, message: lf.Message, always_send_content: bool = True
39
+ ) -> dict[str, Any]:
38
40
  """Converts a Langfun message to Gemini API."""
39
41
  parts = []
40
42
  for chunk in message.chunk():
@@ -44,7 +46,7 @@ class GeminiMessageConverter(lf.MessageConverter):
44
46
  continue
45
47
 
46
48
  if isinstance(chunk, str):
47
- parts.append(self._convert_chunk(chunk))
49
+ parts.append(self._convert_chunk(chunk, always_send_content))
48
50
  else:
49
51
  if isinstance(chunk, lf_modalities.Mime):
50
52
  modalities = [chunk]
@@ -54,10 +56,14 @@ class GeminiMessageConverter(lf.MessageConverter):
54
56
  modalities = chunk
55
57
  else:
56
58
  raise ValueError(f'Unsupported content type: {chunk!r}.')
57
- parts.extend(self._convert_chunk(c) for c in modalities)
59
+ parts.extend(
60
+ self._convert_chunk(c, always_send_content) for c in modalities
61
+ )
58
62
  return dict(role=self.get_role(message), parts=parts)
59
63
 
60
- def _convert_chunk(self, chunk: str | lf.Modality) -> Any:
64
+ def _convert_chunk(
65
+ self, chunk: str | lf.Modality, always_send_content: bool = True
66
+ ) -> Any:
61
67
  """Converts a Langfun chunk to Gemini chunk."""
62
68
  if isinstance(chunk, str):
63
69
  return {'text': chunk}
@@ -73,8 +79,10 @@ class GeminiMessageConverter(lf.MessageConverter):
73
79
  }
74
80
  if chunk.is_text:
75
81
  return {'text': chunk.to_text()}
76
- if chunk.uri and chunk.uri.lower().startswith(
77
- ('http:', 'https:', 'ftp:')
82
+ if (
83
+ not always_send_content
84
+ and chunk.uri
85
+ and chunk.uri.lower().startswith(('http:', 'https:', 'ftp:'))
78
86
  ):
79
87
  return {
80
88
  'fileData': {
@@ -58,11 +58,8 @@ class GeminiConversionTest(unittest.TestCase):
58
58
  def test_as_format_with_image(self):
59
59
  self.assertEqual(
60
60
  lf.Template(
61
- 'What are the common words from {{image}}, {{pdf}} and {{video}}?',
61
+ 'What are the common words from {{image}} and {{video}}?',
62
62
  image=lf_modalities.Image.from_bytes(image_content),
63
- pdf=lf_modalities.Custom.from_uri(
64
- 'https://my.pdf', mime='application/pdf'
65
- ),
66
63
  video=lf_modalities.Custom.from_uri(
67
64
  'https://www.youtube.com/watch?v=abcd', mime='text/html'
68
65
  ),
@@ -79,15 +76,6 @@ class GeminiConversionTest(unittest.TestCase):
79
76
  'mimeType': 'image/png',
80
77
  }
81
78
  },
82
- {
83
- 'text': ','
84
- },
85
- {
86
- 'fileData': {
87
- 'fileUri': 'https://my.pdf',
88
- 'mimeType': 'application/pdf',
89
- }
90
- },
91
79
  {
92
80
  'text': 'and'
93
81
  },
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langfun
3
- Version: 0.1.2.dev202505170804
3
+ Version: 0.1.2.dev202505180804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -46,8 +46,8 @@ langfun/core/data/__init__.py,sha256=qllw9ST1vveZv-1E0VM5hezn1YH-OcqGI-yFqQYnWgI
46
46
  langfun/core/data/conversion/__init__.py,sha256=ZcGntBruvvZSfESO-Tha1nzHfgWEK7I1u78Jw8gsoVU,883
47
47
  langfun/core/data/conversion/anthropic.py,sha256=0xf1sWt6WhmG8EsaeLY4Ee7S3FcDWKPOtn6caCBhtrQ,4431
48
48
  langfun/core/data/conversion/anthropic_test.py,sha256=R43PyveNUCHNCvfu6RFsTk0EIKK8M1Gzng0Kay8TlE8,8534
49
- langfun/core/data/conversion/gemini.py,sha256=k-BJFQ_xuYRTNH_k0cJlZlhN1VrQHiFjckSxRCyUGNY,5523
50
- langfun/core/data/conversion/gemini_test.py,sha256=KIaWdY8CIn0YMaSomxTizvwCrljvt7lbDi3WSEbb1FE,7637
49
+ langfun/core/data/conversion/gemini.py,sha256=fQ5yjwmQLTb-YJN1p6n3cxM9TQoniOkaLvT-p-jMoP8,5722
50
+ langfun/core/data/conversion/gemini_test.py,sha256=G-av2BUngBkxOkJz94CMpZRGq6DGDBvgLltoezuohm0,7239
51
51
  langfun/core/data/conversion/openai.py,sha256=sSpkDSxMJWJ3I1dNICBCzvLsJv4iiLg8FPYLtubBJUM,4181
52
52
  langfun/core/data/conversion/openai_test.py,sha256=38WV_3ofFZiUF10bTKnZp4VyuDP5-81aR3h3Q0HlBm0,5283
53
53
  langfun/core/eval/__init__.py,sha256=OEXr1ZRuvLuhJJfuQ1ZWQ-SvYzjyrtiAAEogYaB7E6o,1933
@@ -156,8 +156,8 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
156
156
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
157
157
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
158
158
  langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
159
- langfun-0.1.2.dev202505170804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
160
- langfun-0.1.2.dev202505170804.dist-info/METADATA,sha256=U2rauYCb-_LY_r_xxtlTa61nIxkMWL4icBLDu5SrW8Y,8178
161
- langfun-0.1.2.dev202505170804.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
162
- langfun-0.1.2.dev202505170804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
163
- langfun-0.1.2.dev202505170804.dist-info/RECORD,,
159
+ langfun-0.1.2.dev202505180804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
160
+ langfun-0.1.2.dev202505180804.dist-info/METADATA,sha256=DI4w_LawSCzpgClMnLKFSx8lKZrs98KY1EPtsjb0Ooo,8178
161
+ langfun-0.1.2.dev202505180804.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
162
+ langfun-0.1.2.dev202505180804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
163
+ langfun-0.1.2.dev202505180804.dist-info/RECORD,,