Simatwa / WebChatGPT

Python SDK/API for ChatGPT Web-Version
GNU General Public License v3.0
90 stars 22 forks source link

Streaming response overlapping even after using flush #10

Closed RasyiidWho closed 8 months ago

RasyiidWho commented 8 months ago

Streaming response overlapping even after using flush, seems like chuck creating new buffer every loop. Expected result are streamed string that overwrite previous string from buffer.

Step to reproduce:

for chunk in bot.chat('Okay I get you', stream=True): print(chunk, end="", flush=True) sys.stdout.flush()

Streamed print response: GreatGreat toGreat to hearGreat to hear!

Expected print response: Great to hear!

Simatwa commented 8 months ago

The current chunk will entail the previous one and the newly created as illustrated here.

So something like this will definitely work out pretty fine.


import pytgpt.leo as leo

bot = leo.LEO(False)

previous_chunk = ''

for chunk in bot.chat('Okay I get you', stream=True):

    print(chunk.replace(previous_chunk,''), end='')

    previous_chunk=chunk