Skip to content

Commit 7bef4e2

Browse files
committed
Skip None chunks from DONE markers in streaming
1 parent c236f92 commit 7bef4e2

3 files changed

Lines changed: 1104 additions & 3 deletions

File tree

src/cohere/base_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,9 @@ async def main() -> None:
19671967
request_options=request_options,
19681968
) as r:
19691969
async for _chunk in r.data:
1970-
yield _chunk
1970+
# Skip None chunks (e.g., from [DONE] markers in SSE streams)
1971+
if _chunk is not None:
1972+
yield _chunk
19711973

19721974
async def chat(
19731975
self,
@@ -2430,7 +2432,9 @@ async def main() -> None:
24302432
request_options=request_options,
24312433
) as r:
24322434
async for _chunk in r.data:
2433-
yield _chunk
2435+
# Skip None chunks (e.g., from [DONE] markers in SSE streams)
2436+
if _chunk is not None:
2437+
yield _chunk
24342438

24352439
async def generate(
24362440
self,

src/cohere/v2/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,9 @@ async def main() -> None:
761761
request_options=request_options,
762762
) as r:
763763
async for _chunk in r.data:
764-
yield _chunk
764+
# Skip None chunks (e.g., from [DONE] markers in SSE streams)
765+
if _chunk is not None:
766+
yield _chunk
765767

766768
async def chat(
767769
self,

0 commit comments

Comments
 (0)