Skip to content

Commit

Permalink
[bugfix]Fix chunk.choices[0].delta.content is None in query response (m…
Browse files Browse the repository at this point in the history
…icrosoft#520)

fix llm response content is None in query
  • Loading branch information
KylinMountain authored Jul 12, 2024
1 parent ff7ac05 commit ec37389
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .semversioner/next-release/patch-20240712035356859335.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "patch",
"description": "fix llm response content is None in query"
}
4 changes: 2 additions & 2 deletions graphrag/query/llm/oai/chat_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _generate(
continue

delta = (
chunk.choices[0].delta.content if chunk.choices[0].delta else ""
chunk.choices[0].delta.content if chunk.choices[0].delta and chunk.choices[0].delta.content else ""
) # type: ignore

full_response += delta
Expand Down Expand Up @@ -186,7 +186,7 @@ async def _agenerate(
continue

delta = (
chunk.choices[0].delta.content if chunk.choices[0].delta else ""
chunk.choices[0].delta.content if chunk.choices[0].delta and chunk.choices[0].delta.content else ""
) # type: ignore

full_response += delta
Expand Down
16 changes: 14 additions & 2 deletions graphrag/query/llm/oai/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ def _generate(
while True:
try:
chunk = response.__next__() # type: ignore
delta = chunk.choices[0].delta.content or "" # type: ignore
if not chunk or not chunk.choices:
continue

delta = (
chunk.choices[0].delta.content if chunk.choices[0].delta and chunk.choices[0].delta.content else ""
) # type: ignore

full_response += delta
if callbacks:
for callback in callbacks:
Expand Down Expand Up @@ -158,7 +164,13 @@ async def _agenerate(
while True:
try:
chunk = await response.__anext__() # type: ignore
delta = chunk.choices[0].delta.content or "" # type: ignore
if not chunk or not chunk.choices:
continue

delta = (
chunk.choices[0].delta.content if chunk.choices[0].delta and chunk.choices[0].delta.content else ""
) # type: ignore

full_response += delta
if callbacks:
for callback in callbacks:
Expand Down

0 comments on commit ec37389

Please sign in to comment.