xtekky / chatgpt-clone

ChatGPT interface with better UI
https://g4f.ai
GNU General Public License v3.0
3.46k stars 1.03k forks source link

when executing the command python run.py #59

Open Toshik-One opened 1 year ago

Toshik-One commented 1 year ago

when executing the command python run.py gives an error message : Traceback (most recent call last): File "C:\chatgpt-clone\run.py", line 19, in backend_api = Backend_Api(app, config) ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\chatgpt-clone\server\backend.py", line 17, in init self.openai_key = os.environ["OPENAI_API_KEY"] or config['openai_key']


  File "<frozen os>", line 679, in __getitem__
KeyError: 'OPENAI_API_KEY'

What should I do ?
openai_key I entered in the file config.json
KaarisMoiLeCrane commented 1 year ago

Hello, I encountered the same problem while using Docker. To fix it, you can remove both instances of os.environ in server/backend.py line 17 and 18 (as well as the or keyword). This should resolve the issue.

If you're still experiencing issues, try replacing os.environ["OPENAI_API_KEY"] or config['openai_key'] with your own OpenAI API key enclosed in quotation marks, like this: "sk-...". Similarly, replace os.environ["OPENAI_API_BASE"] or config['openai_api_base'] with the base API URL enclosed in quotation marks, like this: "https://api.openai.com".

I'm posting this right now, but after two hours, I believe that you have successfully found a fix for the issue. I hope this will be helpful for you and anyone else who encounters this issue in the future.

dvelm commented 1 year ago

the UI is loaded but typing a message gives {"_action":"_ask","error":"an error occurred string indices must be integers","success":false}

and {"_action":"_ask","error":"an error occurred 'Backend_Api' object has no attribute 'openai_api_base'","success":false}

Shivak11 commented 1 year ago

Same here: I am also getting the same error {"_action":"_ask","error":"an error occurred 'Backend_Api' object has no attribute 'openai_api_base'","success":false}

jackmingo commented 1 year ago

This looks related to a change I put in yesterday, and I think I lazily didn't null-safe the os.environ check. WIll put out a pull request shortly. In the meantime you can set env vars OPENAI_API_KEY to your key and OPENAI_API_BASE to https://api.openai.com

jackmingo commented 1 year ago

Pull request: https://github.com/xtekky/chatgpt-clone/pull/63 should fix this.

jackmingo commented 1 year ago

Closed my pull request, This one will resolve it: https://github.com/xtekky/chatgpt-clone/pull/57

dvelm commented 1 year ago

which key? How to resolve this?

jackmingo commented 1 year ago

See my comment 3 notes up. Set the env vars for OPENAI_API_KEY and OPENAI_API_BASE. Once pull #57 is brought in, you won't need to do that and can set via the config file.

Toshik-One commented 1 year ago

Hello, I encountered the same problem while using Docker. To fix it, you can remove both instances of os.environ in server/backend.py line 17 and 18 (as well as the or keyword). This should resolve the issue.

If you're still experiencing issues, try replacing os.environ["OPENAI_API_KEY"] or config['openai_key'] with your own OpenAI API key enclosed in quotation marks, like this: "sk-...". Similarly, replace os.environ["OPENAI_API_BASE"] or config['openai_api_base'] with the base API URL enclosed in quotation marks, like this: "https://api.openai.com".

I'm posting this right now, but after two hours, I believe that you have successfully found a fix for the issue. I hope this will be helpful for you and anyone else who encounters this issue in the future.

did as you suggested to me, everything started up, but when you enter a word, nothing happens, but in the console it displays this list index out of range None list index out of range None list index out of range None list index out of range None list index out of range None list index out of range None list index out of range None list index out of range None 192.168.229.70 - - [28/Apr/2023 21:48:59] "POST /backend-api/v2/conversation HTTP/1.1" 200 -

dvelm commented 1 year ago

I have no key for OPENAI_API_KEY . There should a clearer guide

KaarisMoiLeCrane commented 1 year ago

I have no key for OPENAI_API_KEY . There should a clearer guide

Hello, to obtain an OpenAI API key, it's a very easy process. First, navigate to https://platform.openai.com/ and log in if needed. Then, click on your profile located at the top right corner of the page, and select View API keys. From there, click on the + Create new secret key button in the center of the page, give it a name that will help you remember its purpose, and copy the key. The copied API key should begin with "sk-". Remember to keep this key private and never share it with others.

If you're unable to locate the + Create new secret key button, try clicking on the API keys section in the left-hand navigation bar (under the "USER" text). From there, you should be able to create a new key by following the steps outlined earlier.

I hope this will be helpful for you.

KaarisMoiLeCrane commented 1 year ago

Hello, I encountered the same problem while using Docker. To fix it, you can remove both instances of os.environ in server/backend.py line 17 and 18 (as well as the or keyword). This should resolve the issue. If you're still experiencing issues, try replacing os.environ["OPENAI_API_KEY"] or config['openai_key'] with your own OpenAI API key enclosed in quotation marks, like this: "sk-...". Similarly, replace os.environ["OPENAI_API_BASE"] or config['openai_api_base'] with the base API URL enclosed in quotation marks, like this: "https://api.openai.com". I'm posting this right now, but after two hours, I believe that you have successfully found a fix for the issue. I hope this will be helpful for you and anyone else who encounters this issue in the future.

did as you suggested to me, everything started up, but when you enter a word, nothing happens, but in the console it displays this list index out of range None list index out of range None list index out of range None list index out of range None list index out of range None list index out of range None list index out of range None list index out of range None 192.168.229.70 - - [28/Apr/2023 21:48:59] "POST /backend-api/v2/conversation HTTP/1.1" 200 -

Hello, I'm sorry to hear that you're experiencing this error, but I have not encountered it before so I don't have any idea about how to fix this. Have you tried using Docker to see if the issue still persists ?

Edit : After running the bot, it doesn't seem to respond even though there are no real error messages.

From the Docker Logs section (debug mode set to true in the config.json) :

2023-04-29 11:34:29 x - - [29/Apr/2023 09:34:29] "GET / HTTP/1.1" 302 -
2023-04-29 11:34:29 x - - [29/Apr/2023 09:34:29] "GET /chat/ HTTP/1.1" 200 -
2023-04-29 11:34:29 x - - [29/Apr/2023 09:34:29] "GET /assets/css/style.css HTTP/1.1" 304 -
2023-04-29 11:34:29 x - - [29/Apr/2023 09:34:29] "GET /assets/js/icons.js HTTP/1.1" 304 -
2023-04-29 11:34:29 x - - [29/Apr/2023 09:34:29] "GET /assets/js/highlight.min.js HTTP/1.1" 304 -
2023-04-29 11:34:29 x - - [29/Apr/2023 09:34:29] "GET /assets/js/highlightjs-copy.min.js HTTP/1.1" 304 -
2023-04-29 11:34:29 x - - [29/Apr/2023 09:34:29] "GET /assets/js/chat.js HTTP/1.1" 304 -
2023-04-29 11:34:30 x - - [29/Apr/2023 09:34:30] "GET /assets/img/site.webmanifest HTTP/1.1" 304 -
2023-04-29 11:34:44 x - - [29/Apr/2023 09:34:44] "GET /assets/img/user.png HTTP/1.1" 304 -
2023-04-29 11:34:44 x - - [29/Apr/2023 09:34:44] "GET /assets/img/gpt.png HTTP/1.1" 304 -
2023-04-29 11:34:45 x - - [29/Apr/2023 09:34:45] "POST /backend-api/v2/conversation HTTP/1.1" 200 -

"x" corresponds to an IP address, but I'm not sure who it belongs to so I hide it.

It's possible that the HTTP POST request is not completing, which could be the reason why the bot is not responding.