Skip to content

Commit

Permalink
fix: skip processing of choice.delta when it is None (#16636)
Browse files Browse the repository at this point in the history
  • Loading branch information
deloz authored Oct 22, 2024
1 parent 4779843 commit 5b4c114
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ def gen() -> ChatResponseGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# check if this chunk is the start of a function call
if delta.tool_calls:
is_function = True
Expand Down Expand Up @@ -729,6 +732,9 @@ async def gen() -> ChatResponseAsyncGen:
delta = ChoiceDelta()
first_chat_chunk = False

if delta is None:
continue

# check if this chunk is the start of a function call
if delta.tool_calls:
is_function = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-llms-openai"
readme = "README.md"
version = "0.2.15"
version = "0.2.16"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ def gen() -> CompletionResponseGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# update using deltas
content_delta = delta.content or ""
text += content_delta
Expand Down Expand Up @@ -305,6 +308,9 @@ def gen() -> ChatResponseGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# check if this chunk is the start of a function call
if delta.tool_calls:
is_function = True
Expand Down Expand Up @@ -406,6 +412,9 @@ async def gen() -> CompletionResponseAsyncGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# update using deltas
content_delta = delta.content or ""
text += content_delta
Expand Down Expand Up @@ -461,6 +470,9 @@ async def gen() -> ChatResponseAsyncGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# check if this chunk is the start of a function call
if delta.tool_calls:
is_function = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-multi-modal-llms-openai"
readme = "README.md"
version = "0.2.2"
version = "0.2.3"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
7 changes: 7 additions & 0 deletions llama-index-legacy/llama_index/legacy/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ def gen() -> ChatResponseGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# check if this chunk is the start of a function call
if delta.tool_calls:
is_function = True
Expand Down Expand Up @@ -581,6 +584,10 @@ async def gen() -> ChatResponseAsyncGen:
continue
else:
delta = ChoiceDelta()

if delta is None:
continue

first_chat_chunk = False

# check if this chunk is the start of a function call
Expand Down
12 changes: 12 additions & 0 deletions llama-index-legacy/llama_index/legacy/multi_modal_llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ def gen() -> CompletionResponseGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# update using deltas
content_delta = delta.content or ""
text += content_delta
Expand Down Expand Up @@ -302,6 +305,9 @@ def gen() -> ChatResponseGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# check if this chunk is the start of a function call
if delta.tool_calls:
is_function = True
Expand Down Expand Up @@ -401,6 +407,9 @@ async def gen() -> CompletionResponseAsyncGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# update using deltas
content_delta = delta.content or ""
text += content_delta
Expand Down Expand Up @@ -454,6 +463,9 @@ async def gen() -> ChatResponseAsyncGen:
else:
delta = ChoiceDelta()

if delta is None:
continue

# check if this chunk is the start of a function call
if delta.tool_calls:
is_function = True
Expand Down

0 comments on commit 5b4c114

Please sign in to comment.