Skip to content

Commit e99e53a

Browse files
committed
File Q and A app
1 parent dad1c6a commit e99e53a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+21383
-0
lines changed

apps/file-q-and-a/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# File Q&A
2+
3+
File Q&A is a [Next.js](https://nextjs.org/) app that lets you find answers in your files using OpenAI APIs. You can upload files and ask questions related to their content, and the app will use embeddings and GPT to generate answers from the most relevant files.
4+
5+
This repo contains two versions of the app:
6+
7+
- `/nextjs`: A standalone Next.js app that stores embeddings locally in the browser. You will need an OpenAI API key to use this app. Read more in its [README](./nextjs/README.md).
8+
- `/nextjs-with-flask-server`: A Next.js app that uses a Flask server as a proxy to access the OpenAI APIs, and Pinecone as a vector database to store embeddings. You will need an OpenAI API key and a Pinecone API key to use this app. Read more in its [README](./nextjs-with-flask-server/README.md).
9+
10+
To run either version of the app, please follow the instructions in the respective README.md files in the subdirectories.
11+
12+
## How it works
13+
14+
When a file is uploaded, text is extracted from the file. This text is then split into shorter text chunks, and an embedding is created for each text chunk. When the user asks a question, an embedding is created for the question, and a similarity search is performed to find the file chunk embeddings that are most similar to the question (i.e. have highest cosine similarities with the question embedding). An API call is then made the the completions endpoint, with the question and the most relevant file chunks are included in the prompt. The generative model then gives the answer to the question found in the file chunks, if the answer can be found in the extracts.
15+
16+
## Limitations
17+
18+
The app may sometimes generate answers that are not in the files, or hallucinate about the existence of files that are not uploaded.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# File Q&A with Next.js and Flask
2+
3+
File Q&A is a web app that lets you find answers in your files. You can upload files and ask questions related to their content, and the app will use embeddings and GPT to generate answers from the most relevant files. \
4+
5+
## Requirements
6+
7+
To run the app, you need:
8+
9+
- An OpenAI API key. You can create a new API key [here](https://beta.openai.com/account/api-keys).
10+
- A Pinecone API key and index name. You can create a new account and index [here](https://www.pinecone.io/).
11+
- Python 3.7 or higher and pipenv for the Flask server.
12+
- Node.js and npm for the Next.js client.
13+
14+
## Set-Up and Development
15+
16+
### Server
17+
18+
Fill out the config.yaml file with your Pinecone API key, index name and environment.
19+
20+
Run the Flask server:
21+
22+
```
23+
cd server
24+
bash script/start "<your OPENAI_API_KEY>"
25+
```
26+
27+
### Client
28+
29+
Navigate to the client directory and install Node dependencies:
30+
31+
```
32+
cd client
33+
npm install
34+
```
35+
36+
Run the Next.js client:
37+
38+
```
39+
cd client
40+
npm run dev
41+
```
42+
43+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the app.
44+
45+
## Limitations
46+
47+
The app may sometimes generate answers that are not in the files, or hallucinate about the existence of files that are not uploaded.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
}
5+
6+
module.exports = nextConfig

0 commit comments

Comments
 (0)