llama-index-llms-openai 0.3.13__tar.gz → 0.3.15__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.13
3
+ Version: 0.3.15
4
4
  Summary: llama-index llms openai integration
5
5
  License: MIT
6
6
  Author: llama-index
@@ -2,7 +2,13 @@ import logging
2
2
  import os
3
3
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
4
4
 
5
+ import openai
5
6
  from deprecated import deprecated
7
+ from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall
8
+ from openai.types.chat.chat_completion_chunk import ChoiceDeltaToolCall
9
+ from openai.types.chat.chat_completion_message import ChatCompletionMessage
10
+ from openai.types.chat.chat_completion_token_logprob import ChatCompletionTokenLogprob
11
+ from openai.types.completion_choice import Logprobs
6
12
  from tenacity import (
7
13
  before_sleep_log,
8
14
  retry,
@@ -14,20 +20,15 @@ from tenacity import (
14
20
  )
15
21
  from tenacity.stop import stop_base
16
22
 
17
- import openai
18
23
  from llama_index.core.base.llms.generic_utils import get_from_param_or_env
19
24
  from llama_index.core.base.llms.types import (
20
25
  ChatMessage,
21
26
  ImageBlock,
22
27
  LogProb,
28
+ MessageRole,
23
29
  TextBlock,
24
30
  )
25
31
  from llama_index.core.bridge.pydantic import BaseModel
26
- from openai.types.chat import ChatCompletionMessageParam, ChatCompletionMessageToolCall
27
- from openai.types.chat.chat_completion_chunk import ChoiceDeltaToolCall
28
- from openai.types.chat.chat_completion_message import ChatCompletionMessage
29
- from openai.types.chat.chat_completion_token_logprob import ChatCompletionTokenLogprob
30
- from openai.types.completion_choice import Logprobs
31
32
 
32
33
  DEFAULT_OPENAI_API_TYPE = "open_ai"
33
34
  DEFAULT_OPENAI_API_BASE = "https://api.openai.com/v1"
@@ -40,6 +41,8 @@ O1_MODELS: Dict[str, int] = {
40
41
  "o1-preview-2024-09-12": 128000,
41
42
  "o1-mini": 128000,
42
43
  "o1-mini-2024-09-12": 128000,
44
+ "o3-mini": 200000,
45
+ "o3-mini-2025-01-31": 200000,
43
46
  }
44
47
 
45
48
  O1_MODELS_WITHOUT_FUNCTION_CALLING = {
@@ -292,9 +295,14 @@ def to_openai_message_dict(
292
295
  msg = f"Unsupported content block type: {type(block).__name__}"
293
296
  raise ValueError(msg)
294
297
 
295
- # NOTE: Sending a blank string to openai will cause an error.
296
- # This will commonly happen with tool calls.
297
- content_txt = None if content_txt == "" else content_txt
298
+ # NOTE: Sending a null value (None) for Tool Message to OpenAI will cause error
299
+ # It's only Allowed to send None if it's an Assistant Message
300
+ # Reference: https://platform.openai.com/docs/api-reference/chat/create
301
+ content_txt = (
302
+ None
303
+ if content_txt == "" and message.role == MessageRole.ASSISTANT
304
+ else content_txt
305
+ )
298
306
 
299
307
  # NOTE: Despite what the openai docs say, if the role is ASSISTANT, SYSTEM
300
308
  # or TOOL, 'content' cannot be a list and must be string instead.
@@ -302,10 +310,12 @@ def to_openai_message_dict(
302
310
  # as the content. This will avoid breaking openai-like APIs.
303
311
  message_dict = {
304
312
  "role": message.role.value,
305
- "content": content_txt
306
- if message.role.value in ("assistant", "tool", "system")
307
- or all(isinstance(block, TextBlock) for block in message.blocks)
308
- else content,
313
+ "content": (
314
+ content_txt
315
+ if message.role.value in ("assistant", "tool", "system")
316
+ or all(isinstance(block, TextBlock) for block in message.blocks)
317
+ else content
318
+ ),
309
319
  }
310
320
 
311
321
  # TODO: O1 models do not support system prompts
@@ -29,7 +29,7 @@ exclude = ["**/BUILD"]
29
29
  license = "MIT"
30
30
  name = "llama-index-llms-openai"
31
31
  readme = "README.md"
32
- version = "0.3.13"
32
+ version = "0.3.15"
33
33
 
34
34
  [tool.poetry.dependencies]
35
35
  python = ">=3.9,<4.0"