theAbdoSabbagh / UnlimitedGPT

An unofficial Python wrapper for OpenAI's ChatGPT API
https://pypi.org/project/UnlimitedGPT/
GNU General Public License v3.0
346 stars 43 forks source link

[BUG] send_message() returns last item from clipboard instead of reply #36

Closed xdSora closed 1 year ago

xdSora commented 1 year ago

When running the following simple example, the output will be what the user last copy pasted instead of what chatgpt's reply was.

Steps to Reproduce

  1. copy some text to clipboard (for example "Hello from the future")
  2. run simple example
from UnlimitedGPT import ChatGPT

chatgpt_api = ChatGPT(session_token, headless=True)
reply = chatgpt_api.send_message(message="Please introduce yourself", input_mode="INSTANT")
print(reply) # prints "Hello from the future"

Additional

Installed xclip for pyperclip. The conversation is created and a reply is given, just not copied properly.

remiliacn commented 1 year ago

hi, any work around for this issue?

xdSora commented 1 year ago

I haven't done it myself, but I think if you get a simple example to work using pyperclip as standalone code, it should be an easy fix. I modified the code to use the built in shortcut for copying the last reply (Ctrl+shift+c), which also shows a popup message that the text was copied, so running it it with headless=False, I was able to see and confirm this function working. The issue lies somewhere in the process of pasting the response, can't comment further.

remiliacn commented 1 year ago

Yeah it seems like the issue generally happens when headless parameter is set as true. Switching from headless=True to headless=False and add a small timeout seems to fix the issue for me.

xdSora commented 1 year ago

For me implementing a delay was not helping, but I did find another workaround for the issue.

I added this code at the very beginning of the send_message function:

self.driver.find_element(By.TAG_NAME, "body").send_keys(Keys.LEFT_CONTROL, "r")

Essentially right before sending a message, I reload the website, which fixes the issue where the chatbot would not write an answer even though the text is sent to it (it does answer, but it only shows up some time afterwards when you refresh the page)

I'm not sure what causes this originally, but will close the issue.