Currently, we are using Python to request a stream from ChatGPT and returning the streamed text to the frontend webpage. However, there are instances where the returned text is interrupted. I’m unsure whether adding logs would help identify whether the issue lies with ChatGPT not providing a complete sentence or if the frontend is refusing to receive, causing us to stop further reception. Below is my code for obtaining the stream:
responses = openai.ChatCompletion.create(
model=model, messages=messages, temperature=0, stream=True
)
for response in responses:
try:
last_response = response["choices"][0]["delta"]["content"]
except:
logging.error("incomplete reception")
I can only determine if the stream has ended by checking the length of the list obtained from response["choices"][0]["delta"]["content"]
. If the length exceeds a certain threshold, it indicates that ChatGPT has stopped providing content, and the stream ends. However, if the stream termination is due to an incorrect response or a failure in proper content delivery, how can I distinguish between these scenarios?