alexfacehead / AutoGPTCommands

AutoGPT with commands, read/write/del access. Edit .env file for working changes
MIT License
75 stars 19 forks source link

OpenAPIKey #1

Open gacott opened 1 year ago

gacott commented 1 year ago

OpenAPI key in in the doc, and I am getting this

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\util.py", line 186, in default_api_key raise openai.error.AuthenticationError( openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = ', or you can set the environment variable OPENAI_API_KEY=). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = '. You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email support@openai.com if you have any questions.

alexfacehead commented 1 year ago

The error message is saying you have not provided an API key for the OpenAI library.

Since you said you have the OpenAI API key in your file, I suggest the following steps:

  1. Please pull from this repository if you haven't recently.

  2. I am assuming you mean your .env file when you say in the doc. If so, skip to step 7. If NOT, or if you don't know what I mean by .env file, or if you're simply unsure whether you did it right, then follow all these steps.

  3. Please use .env.template below (it also exists as .env.template in your repo if you've pulled recently):

OPENAI_API_KEY= ELEVENLABS_API_KEY= FAST_LLM_MODEL="gpt-3.5-turbo" SMART_LLM_MODEL="gpt-3.5-turbo" GOOGLE_API_KEY= CUSTOM_SEARCH_ENGINE_ID= SEARX_URL= SEARX_USERNAME= SEARX_PASSWORD= BASE_AUTO_GPT="/working/directory/goes/here"

  1. If you have not already, generate an API key from the OpenAI web interface. You can find this in your OpenAI account settings or API settings on the platform (https://platform.openai.com/account/api-keys)

  2. Fill out the .env template. DO NOT FORGET TO RENAME your .env.template file to .env and save it in /AutoGPT/. I cannot stress this enough.**

  3. ALTERNATIVE SOLUTIONS:

    • Run set OPENAI_API_KEY=<your_api_key> from a Windows command prompt, THEN run the script
    • If that doesn't work, run setx OPENAI_API_KEY "<your_api_key>", THEN run the script
    • If that still doesn't work, [Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "<your_api_key>", "User") will permanently add the OpenAI API key to your environment only for your current username. Don't change User.
  4. If all else fails, then I need you to hardcode your API key on line 39 of AutoGPT/scripts/config.py and change it to equal: self.openai_api_key = "YOUR_KEY_HERE" and replace OPENAI_API_KEY with your key.

Please let me know when you've tried the above steps.

gacott commented 1 year ago

Perfect, yes I was speaking of the .env.template. The set command worked great, thanks.

The next issue is this Searx URL is not configured. Even though I used the URL of one of the servers listed. Do I need to fire one of these up myself, go a "have" to have a user account for Searx? Or is the URL supposed to be good enough?

Thanks so much, I am glad somebody is actually making this work. :-)

alexfacehead commented 1 year ago

Just curious, did you rename .env.template to .env? It will not be recognized, otherwise. The file I provided is only a template :p I highly recommend using the .env file as otherwise you will have to manually set each variable in the terminal each session (unless you permanently change your environment variables). Thus, I think we should focus on getting that working, if we can. To do that, I'd need a little more information, but please try these steps:

  1. Go to config.py

  2. At the very top of the file, you should see line 5, load_dotenv()

  3. Please pass your .env file - named correctly and located in /AutoGPT/ - as a parameter like so: "path/to/.env/" So the line should look like: load_dotenv("/home/dev/Auto-GPT/scripts/.env) if you're me on Linux. On Windows, it may look a little more like: load_dotenv("C:\Users\Administrator\.env") where the actual path there is your precise path (I'm unsure of your file structure. NOTE: you may have to escape the backslashes with an extra backslash. I apologize, it's been some time since I've used Windows.)

  4. Please verify whether the .env file information is being loaded properly. Since you've already run the set command, it may be hard to verify whether that properly loaded the .env file, but it likely did.

  5. Now, please remove the SearX line from the .env file, as well as the SearX username and password line.

  6. Now go to lines 104 and 105 of commands.py and remove (or comment out) the following lines completely: elif command_name == "searx": return searx_search(arguments["input"]) # SearX search, added by Alex

This will, essentially, remove the option from the list of available commands for GPT to choose from. For the record, this is how you can add any command :) (or remove!)

In regards to the SearX issue in terms of replacing search functionality -

Since I recommend removing the functionality if you don't have a SearX server setup, I instead recommend going and setting up a Google search API. It can be a hassle to set it up a SearX server on your own machine. Because of this, I recommend avoiding it. I added this functionality as an alternative to Google's search API which actually costs money after a certain amount of use, though, so if you're willing to put in the effort, I recommend, but if not, then please follow the below steps to use Google (which also needs to have its information deposited into the .env file or you will have to set it manually using setx:

  1. Create an API key on https://console.cloud.google.com/welcome?project=vocal-collector-382718 after making an account image

  2. As seen in the image, click on the top left hamburger/dropdown menu and then go to APIs & Services > Credentials

  3. At the top, press + Create Credentials > API key

  4. Use your API key and put it either into the .env file or copy the .env variable format and use setx again like you did with the OPENAI_API_KEY

  5. Finally, create a new custom search engine at cse.google.com and then do the same thing as step 4 but with the custom search engine ID. (located at https://programmablesearchengine.google.com/controlpanel/all)

Report back with any issues.

alexfacehead commented 1 year ago

Apologies for formatting errors, my markdown isn't up to par. Should be good now.

alexfacehead commented 1 year ago

Update - thank you for bringing a new issue to my attention. I'll have the full fix pushed in ~20 mins. Discovered a lack of Google functionality, lol, oops. Disabled it during testing and never re-added it! I am going to also add an option to disable search entirely using the --no-search flag. I will edit this again when I've pushed.

Update #2 Alright, changes are up. The README has been updated with new instructions.

Features released:

gacott commented 1 year ago

Thanks so much; I'll dig in ASAP. :-)