Closed Bainky closed 1 year ago
Can you explain this code snippet? Or create a pull request?
This piece of code allows you not to wait for the completion of the answer to the question from chatgpt, but to display it every conditional 3 seconds.
You can test this yourself by replacing the send_message
function in the main module with my code. Here is a video how it works
Maybe something like this works better?
def __stream_message(self):
prev_content = ''
while True:
result_streaming = self.driver.find_elements(*chatgpt_streaming)
responses = self.driver.find_elements(*chatgpt_big_response)
if responses:
response = responses[-1]
if 'text-red' in response.get_attribute('class'):
self.logger.debug('Response is an error')
raise ValueError(response.text)
response = self.driver.find_elements(*chatgpt_small_response)[-1]
content = response.text
if content != prev_content:
yield content[len(prev_content) :]
prev_content = content
if not result_streaming:
break
And then I can add this to send_message()
:
if stream:
for i in self.__stream_message():
print(i, end='')
time.sleep(0.1)
return print()
And call the function by this:
chat.send_message(prompt, stream=True)
I would like to see such a feature not only in the form of my own fork, but also in your project. I did it like this.