llama-index-llms-openai 0.3.8__tar.gz → 0.3.9__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.
- {llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/PKG-INFO +1 -1
- {llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/llama_index/llms/openai/base.py +0 -14
- {llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/llama_index/llms/openai/utils.py +7 -13
- {llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/pyproject.toml +1 -1
- {llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/README.md +0 -0
- {llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/llama_index/llms/openai/__init__.py +0 -0
{llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/llama_index/llms/openai/base.py
RENAMED
|
@@ -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:
|
{llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/llama_index/llms/openai/utils.py
RENAMED
|
@@ -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
|
-
|
|
267
|
-
|
|
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,15 @@ 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: Despite what the openai docs say, if the role is ASSISTANT, SYSTEM
|
|
289
|
+
# or TOOL, 'content' cannot be a list and must be string instead.
|
|
290
|
+
# Furthermore, if all blocks are text blocks, we can use the content_txt
|
|
291
|
+
# as the content. This will avoid breaking openai-like APIs.
|
|
296
292
|
message_dict = {
|
|
297
293
|
"role": message.role.value,
|
|
298
294
|
"content": content_txt
|
|
299
295
|
if message.role.value in ("assistant", "tool", "system")
|
|
300
|
-
or
|
|
296
|
+
or all(isinstance(block, TextBlock) for block in message.blocks)
|
|
301
297
|
else content,
|
|
302
298
|
}
|
|
303
299
|
|
|
@@ -324,7 +320,6 @@ def to_openai_message_dicts(
|
|
|
324
320
|
messages: Sequence[ChatMessage],
|
|
325
321
|
drop_none: bool = False,
|
|
326
322
|
model: Optional[str] = None,
|
|
327
|
-
supports_content_blocks: bool = False,
|
|
328
323
|
) -> List[ChatCompletionMessageParam]:
|
|
329
324
|
"""Convert generic messages to OpenAI message dicts."""
|
|
330
325
|
return [
|
|
@@ -332,7 +327,6 @@ def to_openai_message_dicts(
|
|
|
332
327
|
message,
|
|
333
328
|
drop_none=drop_none,
|
|
334
329
|
model=model,
|
|
335
|
-
supports_content_blocks=supports_content_blocks,
|
|
336
330
|
)
|
|
337
331
|
for message in messages
|
|
338
332
|
]
|
|
File without changes
|
{llama_index_llms_openai-0.3.8 → llama_index_llms_openai-0.3.9}/llama_index/llms/openai/__init__.py
RENAMED
|
File without changes
|