cogentapps / chat-with-gpt

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

Fails to when providing a server-side api key #174

Open jerkstorecaller opened 1 year ago

jerkstorecaller commented 1 year ago

It says "I'm having trouble connecting to OpenAI" and Authorization Required.

Unlike the guy at #136 , I can query the API in curl from within the Docker container (beta version). I opened your container, apt installed curl, and this is the output:

root@e9dfd9cbf339:/app#  curl -XPOST -H 'Authorization: Bearer sk-xxxxxxxxx' -H "Content-type: application/json" -d '{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Who won the world series in 2020?"
    },
    {
      "role": "assistant",
      "content": "The Los Angeles Dodgers won the World Series in 2020."
    },
    {
      "role": "user",
      "content": "Where was it played?"
    }
  ]
}' 'https://api.openai.com/v1/chat/completions'

{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1690486512,
  "model": "gpt-3.5-turbo-0613",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The World Series in 2020 was played at the Globe Life Field in Arlington, Texas."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 53,
    "completion_tokens": 19,
    "total_tokens": 72
  }
}

Can you clarify what you mean by "login is required" in the README? If the API works in curl, why would a login be required for anything? To which service, and for what purpose? I tried setting my config.yaml to this (also tried without the quotes around apiKey):

services:
  openai:
    apiKey: "sk-XXXXX"
    loginRequired: false
  elevenlabs:
    apiKey: ABCD
enigmaxbt commented 1 year ago

Got the same issue here. My config.yaml contains

" services: openai: apiKey: (sk-xxxxx) elevenlabs: apiKey: (xxxxx) " Are the api keys supposed to be in (sk-xxxxx) or in "sk-xxxxx" or completely blank like: sk-xxxxx? I tried all 3 versions and none of them work. The api keys are not loaded from the config.yaml

The docs show it like that apiKey: (sk-xxxxx)

Any idea?

joshualyon commented 1 year ago

For what it's worth, the basic config file seems to work for me. To the question about formatting, I did not use any quotes or anything:

services:
  openai:
    apiKey: sk-XXXXXXXXXX
  elevenlabs:
    apiKey: XXXXXXXXXX

I originally made the mistake of putting the config file in the wrong folder, so it was prompting for the API Keys client side.

Even after fixing the issue, when you aren't logged in, it will still prompt for the API Keys client-side, but if you register an account on your local instance, it will use the server API keys as you would expect.

That being said, I never saw the particular error message mentioned in the first post. I assume the check with the direct API call to OpenAI's API is to prove that their aren't any geo-restrictions or similar network restrictions.

Are those error messages coming in client side? Are there any error messages in the server logs?