cogentapps / chat-with-gpt

An open-source ChatGPT app with a voice
https://www.chatwithgpt.ai
MIT License
2.3k stars 489 forks source link

"having trouble connecting to OpenAI" using server-side placed API-key #136

Closed megavenik closed 1 year ago

megavenik commented 1 year ago

Hi!

Everything is working fine if I set my API key over the web in my profile. But when I remove it from there and place to data/config.yaml app responses to me with

I'm sorry, I'm having trouble connecting to OpenAI (no response from OpenAI in the last 30 seconds). Please make sure you've entered your OpenAI API key correctly and try again.

Can you please help me debug this issue?

Here's how it looks from inside the container:

root@ee-vpn-inferno:/opt/chat-with-gpt# docker-compose exec chatgpt bash
root@6b244cf85ca8:/app# cat data/config.yaml
services:
  openai:
    apiKey: "sk-3KtYs*********************owJ9flc"
root@6b244cf85ca8:/app#

When container starts, it says that config file was read and that it processes my requests:

chat-with-gpt |
chat-with-gpt | > chat-with-gpt@0.2.3 start
chat-with-gpt | > npx ts-node --logError src/index.ts
chat-with-gpt |
chat-with-gpt | Loaded config from: /app/data/config.yaml
chat-with-gpt | Configuring Passport.
chat-with-gpt | Listening on port 3000.
chat-with-gpt | Statistics (last 5m):
chat-with-gpt |   - 1 active users: info@******.ch
chat-with-gpt |   - 1 updates processed
SDL2000 commented 1 year ago

Quotes are not needed for the key. Take them away

megavenik commented 1 year ago

@SDL2000 yaml accepts both quoted and non-quoted strings. In this particular case neither of them work.

SDL2000 commented 1 year ago

I don't know, everything works for me. With quotes - I remember exactly, it didn't work. Removed the quotes, restarted the container - it worked

True, registration and authorization are still required (Sign in)

cogentapps commented 1 year ago

"no response from OpenAI in the last 30 seconds" is not an API key issue - if it were not able to use your API key from the config file, you would get a different error indicating that.

No response means it wasn't able to connect to OpenAI. This is usually a temporary issue that happens sometimes because OpenAI's API is not 100% reliable, and when their servers are very busy they drop connections.

Another possibility - much less likely, but worth checking if the problem continues - is that you could have some firewall configuration blocking your Docker container from accessing the internet.

megavenik commented 1 year ago

UPD: Oh, well, looks like Ireally have dns issues inside Docker. I've tested curl outside of the container, which confused me a lot. Many thanks to you and sorry for misinformation!


@cogentapps sorry that I haven't mentioned it on the original post, but it's not about the connectivity either, everything works via curl:

root@ee-vpn-inferno:/opt/chat-with-gpt# curl https://api.openai.com/v1/completions -H "Content-Type: application/json" -H "Authorization: Bearer sk-3KtYsU*************************wJ9flc" -d '{"model": "text-davinci-003", "prompt": "Say this is a test", "temperature": 0, "max_tokens": 7}'
{"id":"cmpl-79Z************************J5Re","object":"text_completion","created":1682515358,"model":"text-davinci-003","choices":[{"text":"\n\nThis is indeed a test","index":0,"logprobs":null,"finish_reason":"length"}],"usage":{"prompt_tokens":5,"completion_tokens":7,"total_tokens":12}}
root@ee-vpn-inferno:/opt/chat-with-gpt#