Update 12 - OpenAI API.md

This commit is contained in:
oobabooga 2023-11-07 12:51:41 -03:00 committed by GitHub
parent b0b999dd68
commit 55dc9845cb
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23

View file

@ -174,11 +174,15 @@ while True:
stream_response = requests.post(url, headers=headers, json=data, verify=False, stream=True) stream_response = requests.post(url, headers=headers, json=data, verify=False, stream=True)
client = sseclient.SSEClient(stream_response) client = sseclient.SSEClient(stream_response)
assistant_message = ''
for event in client.events(): for event in client.events():
payload = json.loads(event.data) 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() print()
history.append({"role": "assistant", "content": assistant_message})
``` ```
#### Python completions example with streaming #### Python completions example with streaming