llama-index-llms-openai 0.3.20__tar.gz → 0.3.22__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.
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Jerry Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llama-index-llms-openai
3
- Version: 0.3.20
3
+ Version: 0.3.22
4
4
  Summary: llama-index llms openai integration
5
5
  License: MIT
6
6
  Author: llama-index
@@ -323,11 +323,16 @@ def to_openai_message_dict(
323
323
  raise ValueError(msg)
324
324
 
325
325
  # NOTE: Sending a null value (None) for Tool Message to OpenAI will cause error
326
- # It's only Allowed to send None if it's an Assistant Message
326
+ # It's only Allowed to send None if it's an Assistant Message and either a function call or tool calls were performed
327
327
  # Reference: https://platform.openai.com/docs/api-reference/chat/create
328
328
  content_txt = (
329
329
  None
330
- if content_txt == "" and message.role == MessageRole.ASSISTANT
330
+ if content_txt == ""
331
+ and message.role == MessageRole.ASSISTANT
332
+ and (
333
+ "function_call" in message.additional_kwargs
334
+ or "tool_calls" in message.additional_kwargs
335
+ )
331
336
  else content_txt
332
337
  )
333
338
 
@@ -621,10 +626,19 @@ def update_tool_calls(
621
626
  # validations to get passed by mypy
622
627
  assert t.function is not None
623
628
  assert tc_delta.function is not None
624
- assert t.function.arguments is not None
625
- assert t.function.name is not None
626
- assert t.id is not None
627
629
 
630
+ # Initialize fields if they're None
631
+ # OpenAI(or Compatible)'s streaming API can return partial tool call
632
+ # information across multiple chunks where some fields may be None in
633
+ # initial chunks and populated in subsequent ones
634
+ if t.function.arguments is None:
635
+ t.function.arguments = ""
636
+ if t.function.name is None:
637
+ t.function.name = ""
638
+ if t.id is None:
639
+ t.id = ""
640
+
641
+ # Update with delta values
628
642
  t.function.arguments += tc_delta.function.arguments or ""
629
643
  t.function.name += tc_delta.function.name or ""
630
644
  t.id += tc_delta.id or ""
@@ -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.20"
32
+ version = "0.3.22"
33
33
 
34
34
  [tool.poetry.dependencies]
35
35
  python = ">=3.9,<4.0"