{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f35a36ce-7231-4815-88b9-d8bf52c125ad",
   "metadata": {},
   "source": [
    "## Deploy a RAG LlamaIndex App to Vercel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06b061c1-97d9-49a5-8ee8-fd47e92bb09a",
   "metadata": {},
   "source": [
    "## Phase 1: Local\n",
    "* Create a github codespace\n",
    "* Create github repo\n",
    "* Create RAG app with create-llama"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3cdd1e27-e4a8-4bcb-875f-a3b03cf29701",
   "metadata": {},
   "source": [
    "## Phase 2: To Vercel\n",
    "* Create account in Vercel\n",
    "* Authorize github\n",
    "* Select github repo\n",
    "* Deploy to Vercel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0037fcba-6c22-44b7-90eb-66bf49889b95",
   "metadata": {},
   "source": [
    "## Create a github repo and open it in a github codespace"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0bd98884-595f-47aa-9a4f-d7a1b7195412",
   "metadata": {},
   "source": [
    "Working in a github codespace is like working from your computer but with the advantage of having many packages already pre-installed there for you."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e4ff9fb-66bc-4709-87e0-8b76a236fca0",
   "metadata": {},
   "source": [
    "## Install create-llama from the codespace terminal"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c20d9a1-d826-4df8-93ec-81ec13ab0b53",
   "metadata": {},
   "source": [
    "* npx create-llama@latest\n",
    "* confirm installation of create-llama\n",
    "* name the app: my-app or whatever you want\n",
    "* template: select option chat with streaming\n",
    "* framework: select nextJS\n",
    "* UI: just HTML\n",
    "* chat engine: ContextChatEngine (RAG application)\n",
    "* enter OpenAI key\n",
    "* use ESLint"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0694dd33-11f3-4873-8be5-2df6a5c28db0",
   "metadata": {},
   "source": [
    "## Upload your private documents in my-app/data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2bd50e6d-d1c8-4a30-b87c-78a6b38a724f",
   "metadata": {},
   "source": [
    "* after uploading new private documents:\n",
    "    * cd my-app \n",
    "    * npm run generate"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8967dbc-ef80-4227-b0ed-59aafe8ad331",
   "metadata": {},
   "source": [
    "## Run the app"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2c0fed6-8911-4688-b901-bc4b4ccd02cf",
   "metadata": {},
   "source": [
    "* npm run dev"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "45315aba-753c-4acb-a783-ee1c6958f351",
   "metadata": {},
   "source": [
    "## To stop de app"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da8510ca-8af8-4af3-af56-39a64672b556",
   "metadata": {},
   "source": [
    "* CTRL-C"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e31ad6b-58fd-4967-9e70-4e1c7bd0baa6",
   "metadata": {},
   "source": [
    "## Load changes in github repo"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a18c7e2-0ecb-451e-af88-e57fefb388fb",
   "metadata": {},
   "source": [
    "* cd ..\n",
    "* git status\n",
    "* git add my-app\n",
    "* git status\n",
    "* git commit -m \"llamaindex app created using create-llama\"\n",
    "* git status\n",
    "* git push"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3495a4fa-0466-4234-afaa-2d850474d256",
   "metadata": {},
   "source": [
    "## Deploy to Vercel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1170c885-3d5e-4845-8987-f71ae5131a71",
   "metadata": {},
   "source": [
    "* Go to vercel.com\n",
    "* Sign up with Github\n",
    "* Give access to import the app's github repo\n",
    "* Import the repo into Vercel\n",
    "* Root directory: click edit and select the my-app folder\n",
    "* Environment variables: enter the OpenAI API Key\n",
    "* Click on the deploy button\n",
    "* It will take some time to complete the deployment\n",
    "* If you click on the app screen, it will open the app on Vercel\n",
    "* Confirm the app works OK\n",
    "* Check the Vercel dashboard\n",
    "* Now in the page of the github repo there is a link to the app on Vercel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "986a8455-81ab-40e0-abf5-691ffef7c818",
   "metadata": {},
   "source": [
    "## If you want to delete the project from Vercel\n",
    "* In the Vercel dashboard, go to settings > delete project"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5d55a71-70d3-4820-bcc7-e6496786fdb0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
