From 55dc9845cb895d4cc2e3e145be1ee9f8db648e4c Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:51:41 -0300 Subject: [PATCH] Update 12 - OpenAI API.md --- docs/12 - OpenAI API.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/12 - OpenAI API.md b/docs/12 - OpenAI API.md index 17c83a3d..90e171fc 100644 --- a/docs/12 - OpenAI API.md +++ b/docs/12 - OpenAI API.md @@ -174,11 +174,15 @@ while True: stream_response = requests.post(url, headers=headers, json=data, verify=False, stream=True) client = sseclient.SSEClient(stream_response) + assistant_message = '' for event in client.events(): payload = json.loads(event.data) - print(payload['choices'][0]['message']['content'], end='') + chunk = payload['choices'][0]['message']['content'] + assistant_message += chunk + print(chunk, end='') print() + history.append({"role": "assistant", "content": assistant_message}) ``` #### Python completions example with streaming