llama-index-llms-openai 0.3.3__tar.gz → 0.3.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llama-index-llms-openai
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: llama-index llms openai integration
5
5
  License: MIT
6
6
  Author: llama-index
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Requires-Dist: llama-index-core (>=0.12.4,<0.13.0)
15
- Requires-Dist: openai (>=1.40.0,<2.0.0)
15
+ Requires-Dist: openai (>=1.57.1,<2.0.0)
16
16
  Description-Content-Type: text/markdown
17
17
 
18
18
  # LlamaIndex Llms Integration: Openai
@@ -257,9 +257,15 @@ def to_openai_message_dict(
257
257
  ) -> ChatCompletionMessageParam:
258
258
  """Convert a ChatMessage to an OpenAI message dict."""
259
259
  content = []
260
+ content_txt = ""
260
261
  for block in message.blocks:
261
262
  if isinstance(block, TextBlock):
262
- content.append({"type": "text", "text": block.text})
263
+ if message.role.value in ("assistant", "tool", "system"):
264
+ # Despite the docs say otherwise, when role is ASSISTANT, SYSTEM
265
+ # or TOOL, 'content' cannot be a list and must be string instead.
266
+ content_txt += block.text
267
+ else:
268
+ content.append({"type": "text", "text": block.text})
263
269
  elif isinstance(block, ImageBlock):
264
270
  if block.url:
265
271
  content.append(
@@ -283,7 +289,9 @@ def to_openai_message_dict(
283
289
 
284
290
  message_dict = {
285
291
  "role": message.role.value,
286
- "content": content,
292
+ "content": content_txt
293
+ if message.role.value in ("assistant", "tool", "system")
294
+ else content,
287
295
  }
288
296
 
289
297
  # TODO: O1 models do not support system prompts
@@ -29,11 +29,11 @@ exclude = ["**/BUILD"]
29
29
  license = "MIT"
30
30
  name = "llama-index-llms-openai"
31
31
  readme = "README.md"
32
- version = "0.3.3"
32
+ version = "0.3.4"
33
33
 
34
34
  [tool.poetry.dependencies]
35
35
  python = ">=3.9,<4.0"
36
- openai = "^1.40.0"
36
+ openai = "^1.57.1"
37
37
  llama-index-core = "^0.12.4"
38
38
 
39
39
  [tool.poetry.group.dev.dependencies]