A ChatGPT plugin to create Spotify playlists based on user descriptions.
This repository serves as a simple example of how to develop a ChatGPT plugin and grant it access to a third-party service using OAuth (in this case, Spotify).
https://matrix.dog/gptdj-demo-2.mp4
To provide ChatGPT with access to Spotify via OAuth, you have to set up a Spotify app in the Spotify Developer Dashboard and obtain a client_id
and client_secret
:
- Go to Spotify developer's dashboard and click "Create app".
- Enter an
App name
andApp description
. - For the
Redirect URI
, puthttps://chat.openai.com/aip/plugin-id-temporary-value/oauth/callback
as a temporary value.
Because you don't know your ChatGPT plugin ID yet, leave the value plugin-id-temporary-value
for now. You will need to replace it later once you obtain your plugin ID.
Clone this repo
git clone [email protected]:kopeikins/gpt-dj.git
Install python requirements
pip install -r requirements.txt
Run FastAPI server
uvicorn app.main:app --reload
To test plugins that don't use OAuth, you can have ChatGPT communicate with your localhost directly. However, when you enable OAuth settings, OpenAI requires you to use a "real" domain. While still in the development stage, you can keep your server running on localhost but utilize tools like ngrok to create a domain that connects to your localhost via a tunnel. Setting up ngrok is simple; just follow their instructions and initiate a tunnel to port 8000.
ngrok http 8000
Once you start a tunnel, you will see a link like https://<your_id>.ngrok.app
, which points to your localhost. You can use it at the later step when setting up a plugin.
- Start the local server.
- Go to ChatGPT Plugin Store and click "Develop your own plugin".
- Enter your ngrok domain:
<your_id>.ngrok.app
- Enter
client_id
andclient_secret
you obtained when creating the Spotify app. - ChatGPT will show you a verification token. Update it in your
ai-plugin.json
and click "Verify tokens". - Click "Install for me".
- Click "Log in with GPT DJ (local version)".
- You will encounter
INVALID_CLIENT: Invalid redirect URI
error. That's ok -- just note the plugin ID in the URL, which looks something like this:plugin-9924812a-36e3-453d-8d11-f02754643cf7
(the part after "plugin-" will be different for you). - Edit your Spotify app and update
redirect_url
with the correct plugin ID. - Repeat the steps from 1 to 7, and this time, the authorization with Spotify should not fail.
After plugin is installed, just type something like "Create a spotify playlist with top 10 hits from the 80s".
Since your Spotify app is in development mode, you need to add users manually. Go to your Spotify Developer Dashboard, find your app, click "Settings," and then "User Management." Add the user's email associated with their Spotify account.
To install your plugin, a user should open the Plugin Store in ChatGPT, click "Install Unverified Plugin," and enter your ngrok domain name. Make sure they don't click "Develop Your Own Plugin," as that would prompt them to input client_id and client_secret, which they cannot do.
Contributions are welcome. It would be interesting to add more features, such as adding songs on the fly, creating playlists for YouTube, etc.