MCPcopy Index your code
hub / github.com/Jordan-Gilliam/ai-template

github.com/Jordan-Gilliam/ai-template @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
163 symbols 500 edges 74 files 0 documented · 0% updated 2y ago★ 4517 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Mercury

## Chat with any Document or Website > Train your own custom GPT - Train on specific websites that you define - Train on documents you upload - Builds on dialog with Chat History - Cites sources - [Perplexity](https://www.perplexity.ai/) style UI

#### Supported Files - [x] .pdf - [x] .docx - [x] .md - [x] .txt - [x] .png - [x] .jpg - [x] .html - [x] .json #### Coming Soon - [ ] .csv - [ ] .pptx - [ ] notion - [ ] next 13 app dir - [ ] vercel ai sdk ## Train #### 1. Upload: `/api/embed-file` - file is uploaded -> cleaned to plain text, and split into 1000-character documents. - OpenAI's embedding API is used to generate embeddings for each document using the "text-embedding-ada-002" model. - The embeddings are stored in a Pinecone namespace. #### 2. Scrape: `/api/embed-webpage` - Web pages are scraped using [cheerio](https://github.com/cheeriojs/cheerio), cleaned to plain text, and split into 1000-character documents. - OpenAI's embedding API is used to generate embeddings for each document using the "text-embedding-ada-002" model. - The embeddings are stored in a Pinecone namespace.

## Query #### Responding to queries: `/api/query` - A single embedding is generated from the user prompt. - The embedding is used to perform a similarity search against the vector database. - The results of the similarity search are used to construct a prompt for GPT-3. - The GTP-3 response is then streamed back to the user.

## Getting Started ### 1. Clone Repo and Install Deps To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
npx degit https://github.com/Jordan-Gilliam/ai-template ai-template
cd ai-template
code .
- install dependencies
npm i
### 2. Set-up Pinecone - Visit [pinecone](https://pinecone.io/) to create a free tier account and from the dashboard. - Create a new Pinecone Index with Dimensions `1536` eg:

- Copy your API key - Record your Environment name ex: `us-central1-gcp` - Record your index name ex: `mercury` ### 3. Set-up OpenAi API - Visit [openai](https://platform.openai.com/account/api-keys) to create and copy your API key > You can find this in the OpenAI web portal under `API Keys` ### 4. Open the `.env.local` file and configure your environment
cp .env.example .env.local
# OpenAI
OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Pinecone
PINECONE_API_KEY="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
PINECONE_ENVIRONMENT="us-central1-gcp"
PINECONE_INDEX_NAME="mercury"
### 5. Start the app
npm run dev
Open http://localhost:3000 in your browser to view the app. ## Template Features - OpenAI API (for generating embeddings and GPT-3 responses) - Pinecone - Nextjs API Routes (Edge runtime) - streaming - Tailwind CSS - Fonts with `@next/font` - Icons from [Lucide](https://lucide.dev) - Dark mode with `next-themes` - Radix UI Primitives - Automatic import sorting with `@ianvs/prettier-plugin-sort-imports`

## Inspiration: > 🍴 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. - https://www.perplexity.ai/ - https://builtbyjesse.com/ - https://ui.shadcn.com/docs - https://meodai.github.io/poline/ - https://github.com/gannonh/gpt3.5-turbo-pgvector - https://github.com/vercel/examples/tree/main/solutions/ai-chatgpt ## How embeddings work: ChatGPT 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. Embeddings 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. This 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.

Extension points exported contracts — how you extend this code

NavItem (Interface)
(no doc)
types/index.ts
LayoutProps (Interface)
(no doc)
components/Layouts.tsx
NavItemsProps (Interface)
(no doc)
components/NavHeader.tsx
CommandDialogProps (Interface)
(no doc)
components/ui/command.tsx
MotionProps (Interface)
(no doc)
components/animations/FadeIn.tsx
IndexDescription (Interface)
(no doc)
hooks/use-pinecone-stats.tsx
State (Interface)
(no doc)
hooks/use-toast.ts
useCopyToClipboardProps (Interface)
(no doc)
hooks/use-copy-to-clipboard.tsx

Core symbols most depended-on inside this repo

cn
called by 154
lib/utils.ts
toast
called by 9
hooks/use-toast.ts
sendData
called by 5
pages/api/query.ts
dispatch
called by 5
hooks/use-toast.ts
initPinecone
called by 4
config/pinecone.ts
t
called by 2
components/icons.tsx
extractTextFromImage
called by 2
lib/file.ts
truncateLongUrl
called by 2
lib/utils.ts

Shape

Function 143
Interface 20

Languages

TypeScript100%

Modules by API surface

components/ui/icons.tsx27 symbols
lib/utils.ts10 symbols
hooks/use-toast.ts10 symbols
components/perplexity/Sources.tsx8 symbols
lib/file.ts7 symbols
components/Layouts.tsx7 symbols
components/perplexity/Answer.tsx6 symbols
components/ui/sheet.tsx5 symbols
components/ui/codeblock.tsx5 symbols
types/index.ts4 symbols
pages/api/query.ts4 symbols
hooks/use-pinecone-stats.tsx4 symbols

For agents

$ claude mcp add ai-template \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact