Setup
Using MetaGPT involves connecting with model providers. We will walk through the setup in this page.
Setup for LLM API
We will take OpenAI API as an example. You can finish the setup in either way:
- Use environment variables. This can be used temporarily for a quick start or trying out a demo.
- Use a config or key file. This is the recommended way, best for continuous and full-feature usage and development.
1. Use environment variables
Run in command line:
shell
export OPENAI_API_KEY="sk-..." # YOUR_API_KEY
export OPENAI_API_MODEL="intended model" # gpt-4, gpt-3.5-turbo, etc.
export OPENAI_API_KEY="sk-..." # YOUR_API_KEY
export OPENAI_API_MODEL="intended model" # gpt-4, gpt-3.5-turbo, etc.
Or in python:
python
import os
os.environ["OPENAI_API_KEY"] = "sk-..." # YOUR_API_KEY
os.environ["OPENAI_API_MODEL"] = "intended model" # gpt-4, gpt-3.5-turbo, etc.
import os
os.environ["OPENAI_API_KEY"] = "sk-..." # YOUR_API_KEY
os.environ["OPENAI_API_MODEL"] = "intended model" # gpt-4, gpt-3.5-turbo, etc.
2. Use a config or key file
- In your current working directory, create a folder
config
and add a new file namedconfig.yaml
orkey.yaml
under it. - Copy the content from the example config.yaml file into your new files
- Fill in your own values to the file:
yaml
OPENAI_API_KEY: 'sk-...' # YOUR_API_KEY
OPENAI_API_MODEL: 'intended model' # gpt-4, gpt-3.5-turbo, etc.
OPENAI_API_KEY: 'sk-...' # YOUR_API_KEY
OPENAI_API_MODEL: 'intended model' # gpt-4, gpt-3.5-turbo, etc.
Remember: If you follow the git clone
approach in Installation, config/config.yaml
will already be there. Just edit it or make a copy named config/key.yaml
for editting. This way you don't accidentally commit and share your API key using git.
Note: MetaGPT will read your setup in this priority order:
config/key.yaml > config/config.yaml > environment variable
Here you are good to go! See Quickstart or our Tutorials for your first run!