|
| 1 | +# Generative AI YouTube Video Search |
| 2 | + |
| 3 | +The purpose of this app is to let users search an existing bank of YouTube videos and get their questions answered. |
| 4 | + |
| 5 | +## Installation & Setup |
| 6 | + |
| 7 | +### Prerequisits |
| 8 | + |
| 9 | +1. Node.js |
| 10 | +2. Docker |
| 11 | + |
| 12 | +### Setup |
| 13 | + |
| 14 | +Install dependencies: |
| 15 | + |
| 16 | +``` |
| 17 | +npm install |
| 18 | +``` |
| 19 | + |
| 20 | +Run setup script (copies the .env.example files) |
| 21 | + |
| 22 | +``` |
| 23 | +npm run setup |
| 24 | +``` |
| 25 | + |
| 26 | +Edit the `services/video-search/.env` file to your liking, including the relevant API keys. |
| 27 | + |
| 28 | +### Run |
| 29 | + |
| 30 | +Start the docker containers |
| 31 | + |
| 32 | +``` |
| 33 | +npm run dev |
| 34 | +``` |
| 35 | + |
| 36 | +The containers are mounted to your local project director, so changes to the project will hot-reload. |
| 37 | + |
| 38 | +### Functionality breakdown |
| 39 | + |
| 40 | +The process for how this app functions is as follows: |
| 41 | + |
| 42 | +1. Videos are uploaded to the video-search service by making a `POST http://localhost:8000/api/videos` request with the following body: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "videos": ["youtube-video-ids-or-urls"] |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +1. Both `Google` and `OpenAI` will be used to generate summaries and embeddings for the videos. You can edit `services/video-search/src/router.ts` if you don't want to use one or the other. You can also edit the `USE` environment variable for searches. `GOOGLE` uses Google and `OPENAI` uses OpenAI. |
| 51 | +1. A user goes to `http://localhost` and asks a question |
| 52 | +1. The question is simplified by asking Google/OpenAI for a semantically similar, shorter version. |
| 53 | +1. The semantic question is then used to search for videos that answer the question |
| 54 | +1. The list of resulting videos is passed to Google/OpenAI to retrieve an actual answer to the question. |
| 55 | +1. A vector embedding is generated for the question and stored in Redis with the videos and answer as the metadata. For future questions, the first step is to search this semantic cache to bypass calling Google/OpenAI. |
| 56 | +1. The answer + resulting videos are passed back to the client |
| 57 | + |
| 58 | +### Project layout |
| 59 | + |
| 60 | +There are two workspaces in this project: `app` and `services/video-search`. `video-search` is the API, and `app` is a thin client built on top of the API using Next.js. |
| 61 | + |
| 62 | +#### video-search service |
| 63 | + |
| 64 | +Within the `video-search` service you will find a typical Express.js app. The bulk of the AI logic happens in the following directories: |
| 65 | + |
| 66 | +1. `src/google` - Contains all of the LLM setup, vector store setup, searching, and embedding logic and uses Google as the LLM |
| 67 | +1. `src/openai` - Contains all of the LLM setup, vector store setup, searching, and embedding logic and uses OpenAI as the LLM **NOTE**: **NOTE:** The above directories export the exact same interface to make it easy to swap them in and out. |
| 68 | +1. `src/templates` - Stores the LLM prompts for getting semantic questions, video summaries, and answers |
| 69 | +1. `src/transcripts` - Contains the logic to retrieve YouTube video information (title, description, thmubnail, and transcript) |
| 70 | + |
| 71 | +Almost all of the remaining important logic is found in `src/router.ts` where you will find the three API routes: |
| 72 | + |
| 73 | +1. `POST /api/videos` - Accepts a list of `{ "videos": [] }` which can be either full YouTube URLs or the video IDs. |
| 74 | +1. `GET /api/videos/search` - Accepts a `?question=<question>` and returns a list of videos and the answer to the question |
| 75 | +1. `GET /api/healthcheck` - Ensures the service is up and running and connected to Redis |
0 commit comments