Skip to content

Commit

Permalink
fix: avoid JSONDecodeError for empty line stream response
Browse files Browse the repository at this point in the history
  • Loading branch information
johnny0120 committed Dec 25, 2024
1 parent 7d1e002 commit 22d6d2a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ollama/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def inner():
raise ResponseError(e.response.text, e.response.status_code) from None

for line in r.iter_lines():
if not line: continue
part = json.loads(line)
if err := part.get('error'):
raise ResponseError(err)
Expand Down Expand Up @@ -669,6 +670,7 @@ async def inner():
raise ResponseError(e.response.text, e.response.status_code) from None

async for line in r.aiter_lines():
if not line: continue
part = json.loads(line)
if err := part.get('error'):
raise ResponseError(err)
Expand Down

0 comments on commit 22d6d2a

Please sign in to comment.