A template for Vercel APIs to utilize with GPTs
This repository contains a template for setting up a Vercel API using Python to interact with OpenAI's GPT models. The template provides a basic structure to build, deploy, and run a scalable API for integrating GPT-powered features into your applications.
- Python-based API setup.
- Integration with OpenAI GPT models.
- Scalable architecture suitable for Vercel deployment.
Before you can utilize this Vercel API template with OpenAI's GPT models, you need to set up accounts on GitHub, Vercel, and have a ChatGPT Plus account with OpenAI.
- Go to GitHub.
- Click on 'Sign up'.
- Fill in the registration form with your details.
- Verify your email address to complete the account setup.
- Visit Vercel's website.
- Click 'Sign Up'.
- You can sign up using your GitHub account or with an email address.
- Follow the on-screen instructions to complete the setup.
- Go to OpenAI's website.
- Sign up for an account if you don't already have one.
- Upgrade to ChatGPT Plus for access to the GPT API.
- Once you have the Plus account, navigate to the API section and generate an API key.
After setting up your accounts, follow these steps to install Visual Studio Code, download the repository, and prepare your API.
- Go to the Visual Studio Code website.
- Download the version appropriate for your operating system (Windows, MacOS, Linux).
- Follow the installation instructions for your operating system.
- Navigate to the GitHub repository in your web browser.
- Click on the 'Code' button and then choose 'Download ZIP'.
- Once downloaded, extract the ZIP file to your desired location on your local drive.
- Right-click on the project directory (the folder where you extracted the repository).
- Select 'Open with VS Code'.
- In VS Code, open the
api
directory in the project. - Locate and open the
main.py
file.
- Copy the contents of
main.py
. - Consult ChatGPT, providing the copied code, and describe the specific API functionality you wish to develop.
- For example, "Here's a Python template for a Vercel API. I want to create an API that does X, Y, and Z. Can you help modify this template?"
After developing and testing your API, the next step is to update your GitHub repository with your latest code. GitHub Desktop provides a user-friendly interface to manage your repositories. Here are the steps to initialize your project as a Git repository, commit your changes, and push them to GitHub using GitHub Desktop.
- Go to the GitHub Desktop website.
- Download the version appropriate for your operating system (Windows or MacOS).
- Follow the installation instructions for your operating system.
- Open GitHub Desktop.
- Click on 'File', then select 'New Repository'.
- Fill in the details for your new repository, such as 'Name', 'Local Path', and 'Description'.
- Make sure to select 'Initialize this repository with a README'.
- Click 'Create Repository' to create your new repository.
- Open the folder where you extracted the Vercel API template.
- Copy all the files and folders from this template directory.
- Navigate to the local directory of the new repository you created in GitHub Desktop.
- Paste all the copied files from the template into this directory.
- Open GitHub Desktop; it should automatically detect the changes in your repository.
- In the left-hand sidebar, you'll see a list of changed files. Review these to ensure they are the correct changes you want to commit.
- At the bottom, provide a summary of the changes in the 'Summary' field and optionally a more detailed description in the 'Description' field.
- Click 'Commit to main' to stage your changes.
- Once committed, click 'Publish repository' or 'Push origin' to push your changes to the remote GitHub repository.
- Go to Vercel's website and log in to your account.
- On the Vercel dashboard, click on 'New Project'.
- Vercel will prompt you to import a project from GitHub. Click 'Import' next to the repository you want to deploy.
- If you're linking to Vercel for the first time, you may need to install the Vercel for GitHub integration and authorize Vercel to access your GitHub account.
- After selecting your repository, you'll be taken to the 'Import Project' page.
- Here, you can configure your project settings. For most Python-based APIs, the default settings should work fine.
- Set the 'Framework Preset' to 'Other' or the specific framework if it's listed.
- You can also configure environment variables if your project requires them under the 'Environment Variables' section.
- Once you've configured your project settings, click on the 'Deploy' button at the bottom of the page.
- Vercel will then begin the deployment process. You can monitor the progress in the 'Deployments' tab of your Vercel dashboard.
- When the deployment is complete, Vercel will provide a URL where your deployed project is accessible.
After deploying your API on Vercel, the next step is to create an OpenAPI schema. This schema will help in defining the endpoints, parameters, and responses of your API in a standardized format. Here's how you can create an OpenAPI schema for the Stock Data API.
-
Start by defining the basic structure of your OpenAPI schema as follows:
{ "openapi": "3.1.0", "info": { "title": "Stock Data API", "description": "Retrieves open, high, low, and close prices of a specified stock symbol.", "version": "v1.0.0" }, "servers": [ { "url": "https://vercel-api-stock-ticker.vercel.app/" } ], "paths": { "/{symbol}": { "get": { "description": "Get stock data for a specific symbol", "operationId": "GetStockData", "parameters": [ { "name": "symbol", "in": "path", "description": "The stock symbol to retrieve data for (e.g., 'AAPL' for Apple Inc.)", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Successful response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/StockData" } } } }, "404": { "description": "Data not found for the given symbol" } }, "deprecated": false } } }, "components": { "schemas": { "StockData": { "type": "object", "properties": { "symbol": { "type": "string", "description": "Stock symbol" }, "open": { "type": "number", "format": "float", "description": "Opening price" }, "high": { "type": "number", "format": "float", "description": "Highest price during the day" }, "low": { "type": "number", "format": "float", "description": "Lowest price during the day" }, "close": { "type": "number", "format": "float", "description": "Closing price" } } } } } } Replace the content of the schema.txt file in your project with the above JSON schema.
####Step 2: Using ChatGPT to Create a New GPT with the Schema Go back to the ChatGPT interface. Click on 'Explore' in ChatGPT. Choose 'Create new GPT'. Click on 'Add Action'. Paste the entire OpenAPI schema into the input box.
Now your API is ready!