Giter Site home page Giter Site logo

jordan-gilliam / ai-template Goto Github PK

View Code? Open in Web Editor NEW
424.0 11.0 66.0 2.01 MB

Mercury - Train your own custom GPT. Chat with any file, or website.

License: The Unlicense

TypeScript 96.14% JavaScript 1.52% CSS 2.34%
embeddings gpt-3 openai radix-ui tailwindcss typescript openai-template chatgpt nextjs gpt-4 pinecone ai cheeriojs vector-database pdf

ai-template's Introduction

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 style UI


Supported Files

  • .pdf
  • .docx
  • .md
  • .txt
  • .png
  • .jpg
  • .html
  • .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, 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:

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 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 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
  • Dark mode with next-themes
  • Radix UI Primitives
  • Automatic import sorting with @ianvs/prettier-plugin-sort-imports


Inspiration:

๐Ÿด Huge thanks to @gannonh and @mayooear for their fantastic work that helped inspire this template.

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.

ai-template's People

Contributors

jordan-gilliam avatar kagemanjoroge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ai-template's Issues

change pinecone for other open source

Is your feature request related to a problem? Please describe.
Pinecone is has no free tier ready when you choose free tier, they put you on waiting list
Describe the solution you'd like
use other and free open source
Describe alternatives you've considered
redis, https://milvus.io , https://github.com/weaviate/weaviate , postgres
Additional context
Add any other context or screenshots about the feature request here.

Seperate links for Train and Query

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Is it possible to restrict access to the "train section" if I want to share this with someone?
Describe the solution you'd like
A clear and concise description of what you want to happen.

Would like to share the trained "bot" without providing access to the "train" section

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Error: [Class extends value undefined is not a constructor or null

When I run it on my local, it shows this error:
error - [Class extends value undefined is not a constructor or null

This might be caused by a React Class Component being rendered in a Server Component, React Class Components only works in Client Components. Read more: https://nextjs.org/docs/messages/class-component-in-server-component
] {
name: 'TypeError'
}
error - [Class extends value undefined is not a constructor or null

This might be caused by a React Class Component being rendered in a Server Component, React Class Components only works in Client Components. Read more: https://nextjs.org/docs/messages/class-component-in-server-component
] {
name: 'TypeError'
}

TypeError: Cannot convert argument to a ByteString because the character at index 11 has a value of 8230 which is greater than 255

Describe the bug
Whenever I try to embed a pdf or simply query from the search box, I get the following error:
TypeError: Cannot convert argument to a ByteString because the character at index 11 has a value of 8230 which is greater than 255

To Reproduce
Steps to reproduce the behavior:

  1. Try to upload the pdf and click the upload button.
    OR
  2. Ask a question in the search box.

Expected behavior
It should not give the error, it should perform it's respective functionality

Desktop (please complete the following information):

  • OS: MacBook Air (M1 Chip)
  • Browser: Chrome

Failed to ingest your data

Describe the bug
Using the template does not work even when the .env file is set up properly.

The Pinecone Docs for namespaces say that "gcp-starter" enviroments don't support namespaces.
I have to assume the bug it coming from trying to send a namespace to Pinecone when it does not support namespaces.
https://docs.pinecone.io/docs/namespaces

To Reproduce
Steps to reproduce the behavior:

  1. Start the server
  2. Upload a .txt file to the "Train" section
  3. wait for error "Error: Failed to ingest your data"

Expected behavior
It should upload the file contents to Pinecone

Fail to upload the pdf from the frontend , it said fail log backend error

Hi ,
When I upload the file in pdf format which is the size in 3.5Mb , it spend like a hour then it will apprear following error.

Sometime like this
Error [Error: PineconeClient: Error calling upsert: Error: PineconeClient: Error calling upsertRaw: FetchError: The request failed and the interceptors did not return an alternative response]
error - [Error: Failed to ingest your data] { page: '/api/embed-file' }
wait - compiling /_error (client and server)...
event - compiled client and server successfully in 176 ms (2430 modules)

Sometime like this
error [TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle]
error - [Error: Failed to ingest your data] { page: '/api/embed-file' }

I already using another of ur branch /feature/animate

meanwhile when I ask the questions from the query page , it resposne a error message
error [TypeError: stream.getReader is not a function]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.