Overview:
The Next.js OpenAI Doc Search Starter is a starter template that allows users to process .mdx files and use them as custom context within OpenAI Text Completion prompts. It can be deployed on Vercel and integrates with Supabase for database management. This starter template enables users to build custom ChatGPTs by performing vector similarity search and injecting content into OpenAI GPT-3 text completion prompts.
Features:
- Process .mdx files in the pages directory to use as custom context within OpenAI Text Completion prompts.
- Integration with Supabase for automatic environment variable setup and database schema configuration.
- Perform vector similarity search to find relevant content for user questions.
- Inject content into OpenAI GPT-3 text completion prompts and stream response to the client.
Installation:
- Deploy the starter to Vercel. The Supabase integration will automatically set the required environment variables and configure your Database Schema. Set your OPENAI_KEY and you’re ready to go.
- Building your own custom ChatGPT involves four steps:
- Pre-process the knowledge base by storing the embeddings of .mdx files in Postgres with pgvector.
- Perform vector similarity search to find the relevant content for the user’s question.
- Inject the content into OpenAI GPT-3 text completion prompts and stream the response to the client.
- During build time, execute the generate-embeddings script which generates embeddings for .mdx files and stores them in the database. It also generates a checksum for each file to ensure that the embeddings are only regenerated when the file has changed.
- During runtime, when the user submits a question, perform the sequence of tasks using the SearchDialog (Client) component and the vector-search (Edge Function).
- For local development:
- Copy the contents of .env.example to .env file and set the OPENAI_KEY in the .env file.
- Set NEXT_PUBLIC_SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY by running supabase start command.
- Start the Next.js app by running the command.
- Ensure supabase is running by running supabase status command.
- Regenerate embeddings for .mdx docs by running the command.
- Refresh the Next.js localhost:3000 rendered page by running the command.
Summary:
The Next.js OpenAI Doc Search Starter is a powerful tool for building custom ChatGPTs. It provides an easy way to process .mdx files, perform vector similarity search, and inject content into OpenAI GPT-3 text completion prompts. The integration with Supabase simplifies the setup and configuration of the database. With this starter template, users can create advanced search functionality and enhance the user experience.