ian-kent / gptchat

A GPT-4 client which gives your favourite AI a memory and tools for self-improvement

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ERROR: ChatCompletion Failed

Rolocker opened this issue · comments

Hello,

Apologies if there's a simple solution, I'm not to familiar with how to do this. I've copied the repository onto my computer, installed go, and then attempted to run from gptchat-main and received the following error:

ERROR: ChatCompletion failed: error, status code: 401, message: You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.

I attempted to input "Y Authorization: my api key" and it asked me for "USER:", but nothing I could think of worked including email, username, blank, or my api key. I've also modified main.go to already use my api key. Edit: Forgot to mention I also tried typing the "I'd like to tell you a story." prompt like in the videos but only got the same error.

Do you know how I can get past this error?

I am having the same issue!

got the same error, still figuring out how to input api key

Have you exported the enviroment variable OPENAI_API_KEY with your gpt4 key?

@ian-kent I think it's best to update the README to be more clear

Have you exported the enviroment variable OPENAI_API_KEY with your gpt4 key?

@ian-kent I think it's best to update the README to be more clear

Could you clarify this please?

If you're on a UNIX-based system is as simple as hoping into a terminal and running:

export OPENAI_API_KEY="YOUR_API_KEY_GOES_HERE"

Remember to add to your ~/.bashrc (or equivalent) in order to persist into other terminal sessions.

If you're on a UNIX-based system is as simple as hoping into a terminal and running:

export OPENAI_API_KEY="YOUR_API_KEY_GOES_HERE"

Remember to add to your ~/.bashrc (or equivalent) in order to persist into other terminal sessions.

Cheers mate this worked, I'm on windows is there a way to make it persist into other terminal sessions?

If you're on a UNIX-based system is as simple as hoping into a terminal and running:

export OPENAI_API_KEY="YOUR_API_KEY_GOES_HERE"

Remember to add to your ~/.bashrc (or equivalent) in order to persist into other terminal sessions.

Cheers mate this worked, I'm on windows is there a way to make it persist into other terminal sessions?

From cmd.exe

setx OPENAI_API_KEY YOUR_API_KEY /m

Or powershell

[System.Environment]::SetEnvironmentVariable('OPENAI_API_KEY','YOUR_API_KEY',[System.EnvironmentVariableTarget]::User)

On my personal win 11 pro machine I right click the start menu and go to settings. Type "enviro" in the search box and select "Edit the system environment variables" option , then click "Environment Variables...", next click the "New..." button under the "System variables" box under the lower window... Enter OPENAI_API_KEY for the "Variable name" and your API key for the value. and click ok. Now you'll be using that API key for anything you run that uses "(os.Getenv("OPENAI_API_KEY")" or "OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")"

I've updated the readme to mention setting the API key, and I've updated the app to prompt for the API key on startup if it isn't set. Hopefully this should simplify things a bit!