llama-index-llms-openai 0.3.8__py3-none-any.whl → 0.3.10__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.
@@ -59,7 +59,6 @@ from llama_index.core.llms.llm import ToolSelection
59
59
  from llama_index.core.llms.utils import parse_partial_json
60
60
  from llama_index.core.types import BaseOutputParser, Model, PydanticProgramMode
61
61
  from llama_index.llms.openai.utils import (
62
- ALL_AVAILABLE_MODELS,
63
62
  O1_MODELS,
64
63
  OpenAIToolCall,
65
64
  create_retry_decorator,
@@ -218,10 +217,6 @@ class OpenAI(FunctionCallingLLM):
218
217
  default=False,
219
218
  description="Whether to use strict mode for invoking tools/using schemas.",
220
219
  )
221
- supports_content_blocks: bool = Field(
222
- default=False,
223
- description="Whether the model supports content blocks in chat messages.",
224
- )
225
220
 
226
221
  _client: Optional[SyncOpenAI] = PrivateAttr()
227
222
  _aclient: Optional[AsyncOpenAI] = PrivateAttr()
@@ -267,10 +262,6 @@ class OpenAI(FunctionCallingLLM):
267
262
  if model in O1_MODELS:
268
263
  temperature = 1.0
269
264
 
270
- supports_content_blocks = kwargs.pop(
271
- "supports_content_blocks", model in ALL_AVAILABLE_MODELS
272
- )
273
-
274
265
  super().__init__(
275
266
  model=model,
276
267
  temperature=temperature,
@@ -290,7 +281,6 @@ class OpenAI(FunctionCallingLLM):
290
281
  pydantic_program_mode=pydantic_program_mode,
291
282
  output_parser=output_parser,
292
283
  strict=strict,
293
- supports_content_blocks=supports_content_blocks,
294
284
  **kwargs,
295
285
  )
296
286
 
@@ -436,7 +426,6 @@ class OpenAI(FunctionCallingLLM):
436
426
  message_dicts = to_openai_message_dicts(
437
427
  messages,
438
428
  model=self.model,
439
- supports_content_blocks=self.supports_content_blocks,
440
429
  )
441
430
 
442
431
  if self.reuse_client:
@@ -475,7 +464,6 @@ class OpenAI(FunctionCallingLLM):
475
464
  message_dicts = to_openai_message_dicts(
476
465
  messages,
477
466
  model=self.model,
478
- supports_content_blocks=self.supports_content_blocks,
479
467
  )
480
468
 
481
469
  def gen() -> ChatResponseGen:
@@ -689,7 +677,6 @@ class OpenAI(FunctionCallingLLM):
689
677
  message_dicts = to_openai_message_dicts(
690
678
  messages,
691
679
  model=self.model,
692
- supports_content_blocks=self.supports_content_blocks,
693
680
  )
694
681
 
695
682
  if self.reuse_client:
@@ -726,7 +713,6 @@ class OpenAI(FunctionCallingLLM):
726
713
  message_dicts = to_openai_message_dicts(
727
714
  messages,
728
715
  model=self.model,
729
- supports_content_blocks=self.supports_content_blocks,
730
716
  )
731
717
 
732
718
  async def gen() -> ChatResponseAsyncGen:
@@ -256,22 +256,14 @@ def to_openai_message_dict(
256
256
  message: ChatMessage,
257
257
  drop_none: bool = False,
258
258
  model: Optional[str] = None,
259
- supports_content_blocks: bool = False,
260
259
  ) -> ChatCompletionMessageParam:
261
260
  """Convert a ChatMessage to an OpenAI message dict."""
262
261
  content = []
263
262
  content_txt = ""
264
263
  for block in message.blocks:
265
264
  if isinstance(block, TextBlock):
266
- if (
267
- message.role.value in ("assistant", "tool", "system")
268
- or not supports_content_blocks
269
- ):
270
- # Despite the docs say otherwise, when role is ASSISTANT, SYSTEM
271
- # or TOOL, 'content' cannot be a list and must be string instead.
272
- content_txt += block.text
273
- else:
274
- content.append({"type": "text", "text": block.text})
265
+ content.append({"type": "text", "text": block.text})
266
+ content_txt += block.text
275
267
  elif isinstance(block, ImageBlock):
276
268
  if block.url:
277
269
  content.append(
@@ -293,11 +285,19 @@ def to_openai_message_dict(
293
285
  msg = f"Unsupported content block type: {type(block).__name__}"
294
286
  raise ValueError(msg)
295
287
 
288
+ # NOTE: Sending a blank string to openai will cause an error.
289
+ # This will commonly happen with tool calls.
290
+ content_txt = None if content_txt == "" else content_txt
291
+
292
+ # NOTE: Despite what the openai docs say, if the role is ASSISTANT, SYSTEM
293
+ # or TOOL, 'content' cannot be a list and must be string instead.
294
+ # Furthermore, if all blocks are text blocks, we can use the content_txt
295
+ # as the content. This will avoid breaking openai-like APIs.
296
296
  message_dict = {
297
297
  "role": message.role.value,
298
298
  "content": content_txt
299
299
  if message.role.value in ("assistant", "tool", "system")
300
- or not supports_content_blocks
300
+ or all(isinstance(block, TextBlock) for block in message.blocks)
301
301
  else content,
302
302
  }
303
303
 
@@ -324,7 +324,6 @@ def to_openai_message_dicts(
324
324
  messages: Sequence[ChatMessage],
325
325
  drop_none: bool = False,
326
326
  model: Optional[str] = None,
327
- supports_content_blocks: bool = False,
328
327
  ) -> List[ChatCompletionMessageParam]:
329
328
  """Convert generic messages to OpenAI message dicts."""
330
329
  return [
@@ -332,7 +331,6 @@ def to_openai_message_dicts(
332
331
  message,
333
332
  drop_none=drop_none,
334
333
  model=model,
335
- supports_content_blocks=supports_content_blocks,
336
334
  )
337
335
  for message in messages
338
336
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llama-index-llms-openai
3
- Version: 0.3.8
3
+ Version: 0.3.10
4
4
  Summary: llama-index llms openai integration
5
5
  License: MIT
6
6
  Author: llama-index
@@ -0,0 +1,6 @@
1
+ llama_index/llms/openai/__init__.py,sha256=vm3cIBSGkBFlE77GyfyN0EhpJcnJZN95QMhPN53EkbE,148
2
+ llama_index/llms/openai/base.py,sha256=_kW22tTABTKQ-GFRN00P5OOcJS4IeVAI3vPqbjw1D8o,35777
3
+ llama_index/llms/openai/utils.py,sha256=q4qfub-sbjdfszucQCIXUyxc54_SKNM5xt84GXjKaXY,18400
4
+ llama_index_llms_openai-0.3.10.dist-info/METADATA,sha256=cDAY7NIsXdQDMDThNsifONnFKcsmWsbCaqeJw8TwXH0,3321
5
+ llama_index_llms_openai-0.3.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
+ llama_index_llms_openai-0.3.10.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- llama_index/llms/openai/__init__.py,sha256=vm3cIBSGkBFlE77GyfyN0EhpJcnJZN95QMhPN53EkbE,148
2
- llama_index/llms/openai/base.py,sha256=z176ueUBn4ZeKlDxqqTyUZ_1VrauaFAt6H4jl5bm_MI,36409
3
- llama_index/llms/openai/utils.py,sha256=a5BvfhjUO1lbKWR5kptQs9WaJ6Ykg_kSWWZQRpk-T3g,18383
4
- llama_index_llms_openai-0.3.8.dist-info/METADATA,sha256=ewX0c-U-io6xgRtyHQgXkax6m5FNtvk5Y3OCvoTORBs,3320
5
- llama_index_llms_openai-0.3.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
- llama_index_llms_openai-0.3.8.dist-info/RECORD,,