{"id":13469768,"url":"https://github.com/Jordan-Gilliam/ai-template","last_synced_at":"2025-03-26T09:31:13.510Z","repository":{"id":161815947,"uuid":"615536358","full_name":"Jordan-Gilliam/ai-template","owner":"Jordan-Gilliam","description":"Mercury - Train your own custom GPT. Chat with any file, or website.","archived":false,"fork":false,"pushed_at":"2023-09-07T16:23:27.000Z","size":2054,"stargazers_count":408,"open_issues_count":7,"forks_count":61,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-06-09T17:44:17.702Z","etag":null,"topics":["ai","chatgpt","cheeriojs","embeddings","gpt-3","gpt-4","nextjs","openai","openai-template","pdf","pinecone","radix-ui","tailwindcss","typescript","vector-database"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jordan-Gilliam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-03-17T23:41:59.000Z","updated_at":"2024-06-05T16:14:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"8f8aa590-5554-402e-ab62-fe6e6c17fd6c","html_url":"https://github.com/Jordan-Gilliam/ai-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jordan-Gilliam%2Fai-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jordan-Gilliam%2Fai-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jordan-Gilliam%2Fai-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jordan-Gilliam%2Fai-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jordan-Gilliam","download_url":"https://codeload.github.com/Jordan-Gilliam/ai-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213380531,"owners_count":15578384,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","chatgpt","cheeriojs","embeddings","gpt-3","gpt-4","nextjs","openai","openai-template","pdf","pinecone","radix-ui","tailwindcss","typescript","vector-database"],"created_at":"2024-07-31T16:00:14.993Z","updated_at":"2024-07-31T16:01:09.598Z","avatar_url":"https://github.com/Jordan-Gilliam.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Other Open Source Work","chatgpt"],"sub_categories":["AI Template"],"readme":"\u003ch1 align=\"center\"\u003eMercury\u003c/h4\u003e\n\n\n\u003ch4 align=\"center\"\u003e\n\n\u003cimg width=\"800\" src=\"https://github.com/Jordan-Gilliam/readme-assets/blob/master/merc-search.png\" alt=\"\"\u003e\n\u003c/h4\u003e\n\n\u003ch4 align=\"center\"\u003e\n\u003cimg width=\"200\" src=\"https://github.com/Jordan-Gilliam/readme-assets/blob/master/logo-down-indigo.webp\" alt=\"\"\u003e\n\n\u003c/h4\u003e\n\n\n\n\n\n\n\n\n## Chat with any Document or Website\n\u003e Train your own custom GPT\n\n- Train on specific websites that you define\n- Train on documents you upload\n- Builds on dialog with Chat History \n- Cites sources\n- [Perplexity](https://www.perplexity.ai/) style UI\n\n\u003ch2 align=\"center\"\u003e\n  \u003cbr\u003e\n\u003cimg width=\"1000\" src=\"https://github.com/Jordan-Gilliam/readme-assets/blob/master/merc-read-1.png\" alt=\"\"\u003e\n\u003c/h2\u003e\n\n\n\n\n#### Supported Files\n- [x] .pdf\n- [x] .docx\n- [x] .md\n- [x] .txt\n- [x] .png\n- [x] .jpg\n- [x] .html\n- [x] .json\n\n#### Coming Soon\n- [ ] .csv\n- [ ] .pptx\n- [ ] notion\n- [ ] next 13 app dir\n- [ ] vercel ai sdk\n\n\n\n\n## Train\n\n\n\n#### 1. Upload: `/api/embed-file`\n\n- file is uploaded -\u003e cleaned to plain text, and split into 1000-character documents.\n- OpenAI's embedding API is used to generate embeddings for each document using the \"text-embedding-ada-002\" model.\n- The embeddings are stored in a Pinecone namespace.\n\n#### 2. Scrape: `/api/embed-webpage`\n\n- Web pages are scraped using [cheerio](https://github.com/cheeriojs/cheerio), cleaned to plain text, and split into 1000-character documents.\n- OpenAI's embedding API is used to generate embeddings for each document using the \"text-embedding-ada-002\" model.\n- The embeddings are stored in a Pinecone namespace.\n\n\u003ch4 align=\"center\"\u003e\n  \u003cbr\u003e\n\u003cimg width=\"1000\" src=\"https://github.com/Jordan-Gilliam/readme-assets/blob/master/merc-dark-train.png\" alt=\"\"\u003e\n\u003c/h4\u003e\n\n\n\n## Query\n\n#### Responding to queries: `/api/query`\n\n- A single embedding is generated from the user prompt.\n- The embedding is used to perform a similarity search against the vector database.\n- The results of the similarity search are used to construct a prompt for GPT-3.\n- The GTP-3 response is then streamed back to the user.\n\n\n\u003ch4 align=\"center\"\u003e\n  \u003cbr\u003e\n\u003cimg width=\"1000\" src=\"https://github.com/Jordan-Gilliam/readme-assets/blob/master/merc-2.gif\" alt=\"\"\u003e\n\u003c/h4\u003e\n\n\n## Getting Started\n\n\n\n\n\n### 1. Clone Repo and Install Deps\n\nTo create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):\n\n```bash\nnpx degit https://github.com/Jordan-Gilliam/ai-template ai-template\n```\n\n```bash\ncd ai-template\ncode .\n```\n\n- install dependencies\n\n```bash\nnpm i\n```\n\n\n### 2. Set-up Pinecone\n\n- Visit [pinecone](https://pinecone.io/) to create a free tier account and from the dashboard.\n- Create a new Pinecone Index with Dimensions `1536`\neg: \n\u003ch4 align=\"\"\u003e\n  \u003cbr\u003e\n\u003cimg width=\"700\" src=\"https://github.com/Jordan-Gilliam/readme-assets/blob/master/merc-pinecone.png\" alt=\"\"\u003e\n\u003c/h4\u003e\n\n- Copy your API key\n- Record your Environment name ex: `us-central1-gcp`\n- Record your index name ex: `mercury`\n\n### 3. Set-up OpenAi API\n\n- Visit [openai](https://platform.openai.com/account/api-keys) to create and copy your API key\n\u003e You can find this in the OpenAI web portal under `API Keys`\n\n### 4. Open the `.env.local` file and configure your environment\n\n```bash\ncp .env.example .env.local\n```\n\n```bash\n# OpenAI\nOPENAI_API_KEY=\"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n# Pinecone\nPINECONE_API_KEY=\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx\"\nPINECONE_ENVIRONMENT=\"us-central1-gcp\"\nPINECONE_INDEX_NAME=\"mercury\"\n```\n\n\n### 5. Start the app\n\n```bash\nnpm run dev\n```\n\nOpen http://localhost:3000 in your browser to view the app.\n\n## Template Features\n\n- OpenAI API (for generating embeddings and GPT-3 responses)\n- Pinecone\n- Nextjs API Routes (Edge runtime) - streaming\n- Tailwind CSS\n- Fonts with `@next/font`\n- Icons from [Lucide](https://lucide.dev)\n- Dark mode with `next-themes`\n- Radix UI Primitives\n- Automatic import sorting with `@ianvs/prettier-plugin-sort-imports`\n\n\u003ch2 align=\"center\"\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://github.com/Jordan-Gilliam/ai-template\"\u003e\u003cimg width=\"700\" src=\"https://github.com/Jordan-Gilliam/readme-assets/blob/master/merc-light.png\" alt=\"\"\u003e\u003c/a\u003e\n\u003c/h2\u003e\n\n\n## Inspiration:\n\n\u003e 🍴 Huge thanks to [@gannonh](https://github.com/gannonh) and [@mayooear](https://github.com/mayooear/gpt4-pdf-chatbot-langchain) for their fantastic work that helped inspire this template. \n\n\n- https://www.perplexity.ai/\n- https://builtbyjesse.com/\n- https://ui.shadcn.com/docs\n- https://meodai.github.io/poline/\n- https://github.com/gannonh/gpt3.5-turbo-pgvector\n- https://github.com/vercel/examples/tree/main/solutions/ai-chatgpt\n\n## How embeddings work:\n\nChatGPT is a great tool for answering general questions, but it falls short when it comes to answering domain-specific questions as it often makes up answers to fill its knowledge gaps and doesn't cite sources. To solve this issue, this starter app uses embeddings coupled with vector search. This app shows how OpenAI's GPT-3 API can be used to create conversational interfaces for domain-specific knowledge.\n\n\u003cb\u003eEmbeddings\u003c/b\u003e are vectors of floating-point numbers that represent the \"relatedness\" of text strings. They are very useful for tasks like ranking search results, clustering, and classification. In text embeddings, a high cosine similarity between two embedding vectors indicates that the corresponding text strings are highly related.\n\nThis app uses embeddings to generate a vector representation of a document and then uses vector search to find the most similar documents to the query. The results of the vector search are then used to construct a prompt for GPT-3, which generates a response. The response is then streamed back to the user.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJordan-Gilliam%2Fai-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJordan-Gilliam%2Fai-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJordan-Gilliam%2Fai-template/lists"}