terry3041 / pyChatGPT

An unofficial Python wrapper for OpenAI's ChatGPT API
GNU General Public License v3.0
1.35k stars 255 forks source link

Returning an issue as No Such Element, t: Unable to locate element: {"method":"tag name","selector":"pre"} #96

Open nithinreddyy opened 1 year ago

nithinreddyy commented 1 year ago

Below is the code i tried on Google Colab,

api = ChatGPT(secret_token)

It's returning error as below

[/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py](https://localhost:8080/#) in check_response(self, response)
    247                 alert_text = value["alert"].get("text")
    248             raise exception_class(message, screen, stacktrace, alert_text)  # type: ignore[call-arg]  # mypy is not smart enough here
--> 249         raise exception_class(message, screen, stacktrace)

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"tag name","selector":"pre"}
  (Session info: chrome=108.0.5359.71)
Stacktrace:
#0 0x558db8b72253 <unknown>
#1 0x558db88e82e1 <unknown>
#2 0x558db8924b45 <unknown>
#3 0x558db8924d71 <unknown>
#4 0x558db89619f7 <unknown>
#5 0x558db894615d <unknown>
#6 0x558db895f52c <unknown>
#7 0x558db8946493 <unknown>
#8 0x558db8917f73 <unknown>
#9 0x558db89195f5 <unknown>
#10 0x558db8bf0080 <unknown>
#11 0x558db8baa9c9 <unknown>
#12 0x558db8baa420 <unknown>
#13 0x558db8bab1a5 <unknown>
#14 0x558db8bebc2b <unknown>
#15 0x558db8bab50e <unknown>
#16 0x558db8b8ce17 <unknown>
#17 0x558db8bb6248 <unknown>
#18 0x558db8bb63e9 <unknown>
#19 0x558db8bce770 <unknown>
#20 0x7f456dd906db start_thread

Can anyone please help me with this?

masanori0209 commented 1 year ago

I had the same error on AWS EC2. The problem is that CloudFlare is denying access (error code: 1020) and module can't get the pre tag. As a solution, we used a proxy server that retrieves tags from outside the IP range outside of google colab(Google Cloud) or AWS and it worked.

# For example
PROXY = "your proxy"
api = ChatGPT(session_token, chrome_args=[
    '--proxy-server=%s' % PROXY,
])

You can either set up your own proxy server or use one that randomly converts IPs, such as Tor. However, the latter is not recommended.

nithinreddyy commented 1 year ago

I had the same error on AWS EC2. The problem is that CloudFlare is denying access (error code: 1020) and module can't get the pre tag. As a solution, we used a proxy server that retrieves tags from outside the IP range outside of google colab(Google Cloud) or AWS and it worked.

# For example
PROXY = "your proxy"
api = ChatGPT(session_token, chrome_args=[
    '--proxy-server=%s' % PROXY,
])

You can either set up your own proxy server or use one that randomly converts IPs, such as Tor. However, the latter is not recommended.

But i don't have any server here. How to use it on local pc, any idea??

masanori0209 commented 1 year ago

Although it may not be a good practice, the following solution is available if you do not set up a proxy server. (but you will need to check to see if there are any legal issues)

  1. install Tor (Debian system is used as an example) apt-get -y update && apt-get install -y tor

  2. run as follows (Example)

    
    from pyChatGPT import ChatGPT
    import subprocess
    from subprocess import PIPE

session_token = "your token" tor = subprocess.Popen(["tor"], shell=True, stdout=PIPE, stderr=PIPE)

default IP

PROXY = "socks5://localhost:9050"

api = ChatGPT(session_token, chrome_args=[ "--proxy-server=%s'"% PROXY, ]) resp = api.send_message("Hello World")

tor.kill()


---

※ This may not be something that is explained in this repository, but that the API has been officially released(GPT-3), you may want to consider using it.

### API Key Page
https://beta.openai.com/account/api-keys

### Program Example
`pip install openai`

```python3
import openai
CHAT_GPT_SECRET = "your secret api key"
openai.api_key = CHAT_GPT_SECRET

response = openai.Completion.create(
    model="text-davinci-003",
    prompt="Hello World",
    temperature=0,
    max_tokens=3000
)
print(response.choices[0].text)
nithinreddyy commented 1 year ago

Although it may not be a good practice, the following solution is available if you do not set up a proxy server. (but you will need to check to see if there are any legal issues)

  1. install Tor (Debian system is used as an example) apt-get -y update && apt-get install -y tor
  2. run as follows (Example)
from pyChatGPT import ChatGPT
import subprocess
from subprocess import PIPE

session_token = "your token"
tor = subprocess.Popen(["tor"], shell=True, stdout=PIPE, stderr=PIPE)
# default IP
PROXY = "socks5://localhost:9050"

api = ChatGPT(session_token, chrome_args=[
    "--proxy-server=%s'"% PROXY,
])
resp = api.send_message("Hello World")

tor.kill()

※ This may not be something that is explained in this repository, but now that the API has been officially released, you may want to consider using it.

API Key Page

https://beta.openai.com/account/api-keys

Program Example

pip install openai

import openai
CHAT_GPT_SECRET = "your secret api key"
openai.api_key = CHAT_GPT_SECRET

response = openai.Completion.create(
    model="text-davinci-003",
    prompt="Hello World",
    temperature=0,
    max_tokens=3000
)
print(response.choices[0].text)

ChatGPT API is not release yet right? I think the 2nd code which you wrote is for GPT-3

masanori0209 commented 1 year ago

Sorry, I misunderstood. It is true that there may be a difference in accuracy due to the GPT-3 model, but the results are equivalent, so I think it is better to use the API. If you still want to use ChatGPT, you can use a proxy server as described above or anonymize your IP address using like Tor.

nulone commented 1 year ago

Sorry, I misunderstood. It is true that there may be a difference in accuracy due to the GPT-3 model, but the results are equivalent, so I think it is better to use the API. If you still want to use ChatGPT, you can use a proxy server as described above or anonymize your IP address using like Tor.

Tor option doesnt work - giving me same error as without it.

terry3041 commented 1 year ago

IPs of Google Colab and AWS are blocked. Consider using a proxy.

image

DimaGolobokov commented 1 year ago

I have http proxy in format - ip:port:username:password How can I use it?

jromal commented 1 year ago

※ This may not be something that is explained in this repository, but now that the API has been officially released, you may want to consider using it.

API Key Page

https://beta.openai.com/account/api-keys

Program Example

pip install openai

import openai
CHAT_GPT_SECRET = "your secret api key"
openai.api_key = CHAT_GPT_SECRET

response = openai.Completion.create(
    model="text-davinci-003",
    prompt="Hello World",
    temperature=0,
    max_tokens=3000
)
print(response.choices[0].text)

ChatGPT API is not release yet right? I think the 2nd code which you wrote is for GPT-3

The API is for davinci-3, which is similar but not the same as GPT-3. You need to keep sending the questions and answers if you have several questions. And the prices are terrible. The 18 USD you get are consumed very quickly.

They need to:

And then we can all abandon those tricky (but nice) solutions.

abdurryy commented 1 year ago

I'm having this issue too!