Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/supabase-promptable-chat/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Update these with your Supabase details from your project settings > API
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=

#update your openai api key
OPENAI_API_KEY=
3 changes: 3 additions & 0 deletions apps/supabase-promptable-chat/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
37 changes: 37 additions & 0 deletions apps/supabase-promptable-chat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local
.env

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
6 changes: 6 additions & 0 deletions apps/supabase-promptable-chat/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2
}
34 changes: 34 additions & 0 deletions apps/supabase-promptable-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
23 changes: 23 additions & 0 deletions apps/supabase-promptable-chat/components/LoadingDots.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import styles from '../styles/loading-dots.module.css';

const LoadingDots = ({
color = '#000',
style = 'small',
}: {
color: string;
style: string;
}) => {
return (
<span className={style == 'small' ? styles.loading2 : styles.loading}>
<span style={{ backgroundColor: color }} />
<span style={{ backgroundColor: color }} />
<span style={{ backgroundColor: color }} />
</span>
);
};

export default LoadingDots;

LoadingDots.defaultProps = {
style: 'small',
};
7 changes: 7 additions & 0 deletions apps/supabase-promptable-chat/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}

module.exports = nextConfig
44 changes: 44 additions & 0 deletions apps/supabase-promptable-chat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "supabase-promptable",
"version": "0.1.0",
"private": true,
"license": "MIT",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"type-check": "tsc --noEmit",
"lint": "eslint --ignore-path .gitignore \"**/*.+(ts|js|tsx)\"",
"format": "prettier --ignore-path .gitignore \"**/*.+(ts|js|tsx)\" --write",
"scrape": "tsx scripts/scrape-url.ts",
"embed": "tsx scripts/generate-embeddings.ts"
},
"dependencies": {
"@headlessui/react": "^1.7.13",
"@headlessui/tailwindcss": "^0.1.2",
"@heroicons/react": "^2.0.16",
"@supabase/supabase-js": "^2.10.0",
"@vercel/analytics": "^0.1.11",
"cheerio": "1.0.0-rc.12",
"next": "13.2.3",
"promptable": "^0.0.10",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hot-toast": "^2.4.0"
},
"devDependencies": {
"@types/node": "^18.14.6",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"autoprefixer": "^10.4.13",
"eslint": "8.35.0",
"eslint-config-next": "13.2.3",
"postcss": "^8.4.21",
"prettier": "^2.8.4",
"tailwindcss": "^3.2.7",
"tsx": "^3.12.3",
"typescript": "^4.9.5"
}
}
22 changes: 22 additions & 0 deletions apps/supabase-promptable-chat/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import '@/styles/base.css';
import type { AppProps } from 'next/app';
import { Analytics } from '@vercel/analytics/react';
import { Inter } from 'next/font/google';

const inter = Inter({
variable: '--font-inter',
subsets: ['latin'],
});

function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<main className={inter.variable}>
<Component {...pageProps} />
<Analytics />
</main>
</>
);
}

export default MyApp;
13 changes: 13 additions & 0 deletions apps/supabase-promptable-chat/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Html, Head, Main, NextScript } from "next/document";

export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
63 changes: 63 additions & 0 deletions apps/supabase-promptable-chat/pages/api/search-docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { openaiClient } from '@/utils/openai-client';
import type { NextApiRequest, NextApiResponse } from 'next';
import { Embeddings, prompts } from 'promptable';
import { supabaseAdmin } from '@/utils/supabase-client';

/**
* Todo add promptable prompts, LLM generation, and test via supabase
*/
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method !== 'POST') {
return res
.status(405)
.json({ success: false, message: 'Method not allowed' });
}

try {
const { question: query } = req.body;

if (!query) {
return res.status(400).json({ message: 'No question in the request' });
}

// OpenAI recommends replacing newlines with spaces for best results
const sanitizedQuery = query.trim().replaceAll('\n', ' ');

//embed user query
const embeddings = await openaiClient.embed(sanitizedQuery);

console.log('\nembeddingResponse: \n', embeddings);

//perform similarity search
const { error: matchError, data: documents } = await supabaseAdmin.rpc(
'match_page_sections',
{
embeddings,
similarity_threshold: 0.1, // Choose an appropriate threshold for your data
match_count: 10, // Choose the number of matches
},
);

if (matchError) {
console.log('Failed to match page sections', matchError);
return new Response('Error', { status: 500 });
}

console.log('documents', documents);

/**
* TODO
*
* 1. concat matched docs into context based on max tokens
* 2. craft prompt to send with context to LLM
*/

return res.status(200).json({ success: true });
} catch (error) {
console.error('error', error);
return res.status(500).json({ message: 'Error occured, please try again' });
}
}
10 changes: 10 additions & 0 deletions apps/supabase-promptable-chat/pages/api/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next';
import * as p from 'promptable';

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
res.status(200).json({ name: `John Doe` });
}
82 changes: 82 additions & 0 deletions apps/supabase-promptable-chat/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import Head from 'next/head';
import Image from 'next/image';

export default function Home() {
return (
<div className="flex min-h-screen flex-col items-center justify-center py-2">
<Head>
<title>Create Next App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main className="flex w-full flex-1 flex-col items-center justify-center px-20 text-center">
<h1 className="text-6xl font-bold">
Welcome to{' '}
<a className="text-blue-600" href="https://nextjs.org">
Next.js!
</a>
</h1>

<p className="mt-3 text-2xl">
Get started by editing{' '}
<code className="rounded-md bg-gray-100 p-3 font-mono text-lg">
pages/index.tsx
</code>
</p>

<div className="mt-6 flex max-w-4xl flex-wrap items-center justify-around sm:w-full">
<a
href="https://nextjs.org/docs"
className="mt-6 w-96 rounded-xl border p-6 text-left hover:text-blue-600 focus:text-blue-600"
>
<h3 className="text-2xl font-bold">Documentation &rarr;</h3>
<p className="mt-4 text-xl">
Find in-depth information about Next.js features and its API.
</p>
</a>

<a
href="https://nextjs.org/learn"
className="mt-6 w-96 rounded-xl border p-6 text-left hover:text-blue-600 focus:text-blue-600"
>
<h3 className="text-2xl font-bold">Learn &rarr;</h3>
<p className="mt-4 text-xl">
Learn about Next.js in an interactive course with quizzes!
</p>
</a>

<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className="mt-6 w-96 rounded-xl border p-6 text-left hover:text-blue-600 focus:text-blue-600"
>
<h3 className="text-2xl font-bold">Examples &rarr;</h3>
<p className="mt-4 text-xl">
Discover and deploy boilerplate example Next.js projects.
</p>
</a>

<a
href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className="mt-6 w-96 rounded-xl border p-6 text-left hover:text-blue-600 focus:text-blue-600"
>
<h3 className="text-2xl font-bold">Deploy &rarr;</h3>
<p className="mt-4 text-xl">
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>

<footer className="flex h-24 w-full items-center justify-center border-t">
<a
className="flex items-center justify-center gap-2"
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</a>
</footer>
</div>
);
}
Loading