Significant-Gravitas / AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
https://agpt.co
MIT License
166.65k stars 44.1k forks source link

AutoGPT cant find OpenAI API Key #2574

Closed jfranecki closed 1 year ago

jfranecki commented 1 year ago

⚠️ Search for existing issues first ⚠️

Which Operating System are you using?

Windows

GPT-3 or GPT-4?

GPT-3.5

Steps to reproduce 🕹

Using Stable branch. Tried master, did not work there either. I have installed requirements.txt and edited the .env file using the template.

Python version: Python 3.10.11 git rev-parse HEAD: 97d62cc16bf45fcd406efeb33d042ebd58c24670

I have have modified a few values in .env

### AUTO-GPT - GENERAL SETTINGS
################################################################################
# EXECUTE_LOCAL_COMMANDS - Allow local command execution (Example: False)
EXECUTE_LOCAL_COMMANDS=True
# BROWSE_CHUNK_MAX_LENGTH - When browsing website, define the length of chunk stored in memory
BROWSE_CHUNK_MAX_LENGTH=8192
# BROWSE_SUMMARY_MAX_TOKEN - Define the maximum length of the summary generated by GPT agent when browsing website
BROWSE_SUMMARY_MAX_TOKEN=300
# USER_AGENT - Define the user-agent used by the requests library to browse website (string)
# USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
# AI_SETTINGS_FILE - Specifies which AI Settings file to use (defaults to ai_settings.yaml)
AI_SETTINGS_FILE=ai_settings.yaml
# USE_WEB_BROWSER - Sets the web-browser drivers to use with selenium (defaults to chrome).
# Note: set this to either 'chrome', 'firefox', or 'safari' depending on your current browser
# USE_WEB_BROWSER=chrome

################################################################################
### LLM PROVIDER
################################################################################

### OPENAI
# OPENAI_API_KEY - OpenAI API Key (Example: my-openai-api-key)
# TEMPERATURE - Sets temperature in OpenAI (Default: 0)
# USE_AZURE - Use Azure OpenAI or not (Default: False)
OPENAI_API_KEY=myOpenaiApiKey
TEMPERATURE=0
USE_AZURE=False

### AZURE
# cleanup azure env as already moved to `azure.yaml.template`

################################################################################
### LLM MODELS
################################################################################

# SMART_LLM_MODEL - Smart language model (Default: gpt-4)
# FAST_LLM_MODEL - Fast language model (Default: gpt-3.5-turbo)
SMART_LLM_MODEL=gpt-4
FAST_LLM_MODEL=gpt-3.5-turbo

### LLM MODEL SETTINGS
# FAST_TOKEN_LIMIT - Fast token limit for OpenAI (Default: 4000)
# SMART_TOKEN_LIMIT - Smart token limit for OpenAI (Default: 8000)
# When using --gpt3only this needs to be set to 4000.
FAST_TOKEN_LIMIT=4000
SMART_TOKEN_LIMIT=8000

################################################################################
### MEMORY
################################################################################

### MEMORY_BACKEND - Memory backend type
# local - Default
# pinecone - Pinecone (if configured)
# redis - Redis (if configured)
MEMORY_BACKEND=local

### PINECONE
# PINECONE_API_KEY - Pinecone API Key (Example: my-pinecone-api-key)
# PINECONE_ENV - Pinecone environment (region) (Example: us-west-2)
PINECONE_API_KEY=your-pinecone-api-key
PINECONE_ENV=your-pinecone-region

### REDIS
# REDIS_HOST - Redis host (Default: localhost)
# REDIS_PORT - Redis port (Default: 6379)
# REDIS_PASSWORD - Redis password (Default: "")
# WIPE_REDIS_ON_START - Wipes data / index on start (Default: False)
# MEMORY_INDEX - Name of index created in Redis database (Default: auto-gpt)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
WIPE_REDIS_ON_START=False
MEMORY_INDEX=auto-gpt

### WEAVIATE
# MEMORY_BACKEND - Use 'weaviate' to use Weaviate vector storage
# WEAVIATE_HOST - Weaviate host IP
# WEAVIATE_PORT - Weaviate host port
# WEAVIATE_PROTOCOL - Weaviate host protocol (e.g. 'http')
# USE_WEAVIATE_EMBEDDED - Whether to use Embedded Weaviate
# WEAVIATE_EMBEDDED_PATH - File system path were to persist data when running Embedded Weaviate
# WEAVIATE_USERNAME - Weaviate username
# WEAVIATE_PASSWORD - Weaviate password
# WEAVIATE_API_KEY - Weaviate API key if using API-key-based authentication
# MEMORY_INDEX - Name of index to create in Weaviate
WEAVIATE_HOST="127.0.0.1"
WEAVIATE_PORT=8080
WEAVIATE_PROTOCOL="http"
USE_WEAVIATE_EMBEDDED=False
WEAVIATE_EMBEDDED_PATH="/home/me/.local/share/weaviate"
WEAVIATE_USERNAME=
WEAVIATE_PASSWORD=
WEAVIATE_API_KEY=
MEMORY_INDEX=AutoGpt

### MILVUS
# MILVUS_ADDR - Milvus remote address (e.g. localhost:19530)
# MILVUS_COLLECTION - Milvus collection, 
# change it if you want to start a new memory and retain the old memory.
MILVUS_ADDR=your-milvus-cluster-host-port
MILVUS_COLLECTION=autogpt

################################################################################
### IMAGE GENERATION PROVIDER
################################################################################

### OPEN AI
# IMAGE_PROVIDER - Image provider (Example: dalle)
IMAGE_PROVIDER=dalle

### HUGGINGFACE
# STABLE DIFFUSION
# (Default URL: https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4)
# Set in image_gen.py)
# HUGGINGFACE_API_TOKEN - HuggingFace API token (Example: my-huggingface-api-token)
HUGGINGFACE_API_TOKEN=your-huggingface-api-token

################################################################################
### AUDIO TO TEXT PROVIDER
################################################################################

### HUGGINGFACE
HUGGINGFACE_AUDIO_TO_TEXT_MODEL=facebook/wav2vec2-base-960h

################################################################################
### GIT Provider for repository actions
################################################################################

### GITHUB
# GITHUB_API_KEY - Github API key / PAT (Example: github_pat_123)
# GITHUB_USERNAME - Github username
GITHUB_API_KEY=github_pat_123
GITHUB_USERNAME=your-github-username

################################################################################
### SEARCH PROVIDER
################################################################################

### GOOGLE
# GOOGLE_API_KEY - Google API key (Example: my-google-api-key)
# CUSTOM_SEARCH_ENGINE_ID - Custom search engine ID (Example: my-custom-search-engine-id)
GOOGLE_API_KEY=your-google-api-key
CUSTOM_SEARCH_ENGINE_ID=your-custom-search-engine-id

################################################################################
### TTS PROVIDER
################################################################################

### MAC OS
# USE_MAC_OS_TTS - Use Mac OS TTS or not (Default: False)
USE_MAC_OS_TTS=False

### STREAMELEMENTS
# USE_BRIAN_TTS - Use Brian TTS or not (Default: False)
USE_BRIAN_TTS=False

### ELEVENLABS
# ELEVENLABS_API_KEY - Eleven Labs API key (Example: my-elevenlabs-api-key)
# ELEVENLABS_VOICE_1_ID - Eleven Labs voice 1 ID (Example: my-voice-id-1)
# ELEVENLABS_VOICE_2_ID - Eleven Labs voice 2 ID (Example: my-voice-id-2)
ELEVENLABS_API_KEY=myelevenlabskey
ELEVENLABS_VOICE_1_ID=myclonedvoice1 #Cloned voice name 1
ELEVENLABS_VOICE_2_ID=myclonedvoice1 #Cloned voice name 2

################################################################################
### TWITTER API 
################################################################################

TW_CONSUMER_KEY=
TW_CONSUMER_SECRET=
TW_ACCESS_TOKEN=
TW_ACCESS_TOKEN_SECRET=

AutoGPT Directory Picture:

Auto-GPT\
.devcontainer
.github
auto_gpt_workspace
autogpt
docs
logs
outputs
scripts
tests
.env
.env.template
.flake8
.gitignore
.isort.cfg
.pre-commit-config.yaml
.sourcery.yaml
ai_settings.yaml
auto-gpt.json
azure.yaml.template
CODE_OF_CONDUCT.md
CONTRIBUTING.md
docker-compose.yml
Dockerfile
LICENSE
main.py
pyproject.toml
README.md
requirements-docker.txt
requirements.txt
run_continuous.bat
run.bat
tests.py

Current behavior 😯

Command Ran in Windows Terminal Auto-GPT>python -m autogpt --gpt3only

Response:

Please set your OpenAI API key in .env or as an environment variable.
You can get your key from https://beta.openai.com/account/api-keys

The command python -m autogpt returns the same response.

Expected behavior 🤔

No response

Your prompt 📝

No response

Your Logs 📒

No response

k-boikov commented 1 year ago

Please verify you are editing the correct .env file. If you have "Hide extensions for known file types" the file might be .env.txt but you wont be able to see the .txt at the end.

jfranecki commented 1 year ago

Yes, the file I provided was from the .env file and it has a file type of 'ENV File'.

robellegate commented 1 year ago

I found on the stable branch that autogpt will try reading .env from path/to/local/Auto-GPT/autogpt/.env. I symlinked this file to ../.env as a work around.

k-boikov commented 1 year ago

Strange, the only thing I can suggest is to start from scratch, or try to debug load_dotenv() in autogpt/config/config.py in particular the find_dotenv function result.

GREEENUP commented 1 year ago

Just ran into this. I removed the double quotes from my key and it worked just fine.

Aaronminer1 commented 1 year ago

ran into this issue just hard coded the api key in to config.py fixed the issue

enter your openai api key and comment out the original code as below

self.openai_api_key = "your open ai api key here " # os.getenv("OPENAI_API_KEY")

jfranecki commented 1 year ago

ran into this issue just hard coded the api key in to config.py fixed the issue

enter your openai api key and comment out the original code as below

self.openai_api_key = "your open ai api key here " # os.getenv("OPENAI_API_KEY")

That worked, thank you.

cgrizzy-123 commented 1 year ago

I just resolved this issue as well, the problem was while the file was named ".env" the file type was still "Template", vs "env file". Renaming the file updated the file type.

Vianney64 commented 1 year ago

I just resolved this issue as well, the problem was while the file was named ".env" the file type was still "Template", vs "env file". Renaming the file updated the file type.

It works. Thanks

SvenBrunk commented 1 year ago

For me there was an empty file .env in the autogpt subfolder. Maybe from prior experiments with docker or devcontainer which was completely empty. After deleting that, it worked

akamrava commented 1 year ago

I had the same issue -- challenge is computer saves the .env file as a .txt. Easy fix -- make your changes in env.template -- duplicate the file in the folder and then rename as .env This should fix it (worked for me)

EfikZara commented 1 year ago

Hi,

ran into this issue just hard coded the api key in to config.py fixed the issue

enter your openai api key and comment out the original code as below

self.openai_api_key = "your open ai api key here " # os.getenv("OPENAI_API_KEY")

I'd love some help with this if anyone is willing to walk me through. I'm having the same issue.