From 2fbfe3c75a49b90acd3921b8f052b1ae792d5c1a Mon Sep 17 00:00:00 2001 From: Francisco Oca Date: Wed, 15 Mar 2023 12:50:43 -0400 Subject: [PATCH] Fixed streaming in chat completion This was failing before: ``` openai api chat_completions.create -m gpt-3.5-turbo --message user "tell me a joke" --stream ``` --- openai/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openai/cli.py b/openai/cli.py index e9201b18b9..5488a009eb 100644 --- a/openai/cli.py +++ b/openai/cli.py @@ -140,7 +140,8 @@ def create(cls, args): for c_idx, c in enumerate(sorted(choices, key=lambda s: s["index"])): if len(choices) > 1: sys.stdout.write("===== Chat Completion {} =====\n".format(c_idx)) - sys.stdout.write(c["message"]["content"]) + if "delta" in c and "content" in c["delta"]: + sys.stdout.write(c["delta"]["content"]) if len(choices) > 1: sys.stdout.write("\n") sys.stdout.flush()