mirror of
https://github.com/sqlchat/sqlchat.git
synced 2026-03-13 07:59:44 +08:00
feat: initial skeleton
This commit is contained in:
1
.env.example
Normal file
1
.env.example
Normal file
@@ -0,0 +1 @@
|
||||
OPENAI_API_KEY=<YOUR_API_KEY>
|
||||
6
.eslintrc.json
Normal file
6
.eslintrc.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "next/core-web-vitals",
|
||||
"rules": {
|
||||
"@next/next/no-img-element": "off"
|
||||
}
|
||||
}
|
||||
37
.gitignore
vendored
Normal file
37
.gitignore
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
.env
|
||||
|
||||
# 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
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
5
next-env.d.ts
vendored
Normal file
5
next-env.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
27
package.json
Normal file
27
package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "chatdba",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/analytics": "^0.1.11",
|
||||
"highlight.js": "^11.7.0",
|
||||
"next": "^13.2.4",
|
||||
"openai": "^3.0.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.18",
|
||||
"@types/react": "^18.0.26",
|
||||
"autoprefixer": "^10.4.13",
|
||||
"eslint": "8.20.0",
|
||||
"eslint-config-next": "12.2.3",
|
||||
"postcss": "^8.4.20",
|
||||
"tailwindcss": "^3.2.4",
|
||||
"typescript": "^4.9.4"
|
||||
}
|
||||
}
|
||||
15
pages/_app.tsx
Normal file
15
pages/_app.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { AppProps } from "next/app";
|
||||
import React from "react";
|
||||
import { Analytics } from "@vercel/analytics/react";
|
||||
import "./styles/globals.css";
|
||||
|
||||
function MyApp({ Component, pageProps }: AppProps) {
|
||||
return (
|
||||
<>
|
||||
<Component {...pageProps} />
|
||||
<Analytics />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
26
pages/api/chat.ts
Normal file
26
pages/api/chat.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import openai, { ChatCompletionResponse } from "./openai-api";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse<ChatCompletionResponse>) => {
|
||||
const completionResponse = await openai.createChatCompletion({
|
||||
model: "gpt-3.5-turbo",
|
||||
messages: req.body.messages,
|
||||
max_tokens: 2000,
|
||||
temperature: 0,
|
||||
top_p: 1.0,
|
||||
frequency_penalty: 0.0,
|
||||
presence_penalty: 0.0,
|
||||
});
|
||||
|
||||
res.status(200).json({ message: completionResponse.data.choices[0].message! });
|
||||
};
|
||||
|
||||
// TODO(steven): Implement a generic getChatPrompt function that takes in a
|
||||
// message and a robot identifier, then returns a string with specific prompts.
|
||||
const getChatPrompt = async (message: string) => {
|
||||
return `
|
||||
Question: ${message}
|
||||
Answer:`;
|
||||
};
|
||||
|
||||
export default handler;
|
||||
12
pages/api/openai-api.ts
Normal file
12
pages/api/openai-api.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ChatCompletionResponseMessage, Configuration, OpenAIApi } from "openai";
|
||||
|
||||
export interface ChatCompletionResponse {
|
||||
message: ChatCompletionResponseMessage;
|
||||
}
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
const openai = new OpenAIApi(configuration);
|
||||
|
||||
export default openai;
|
||||
7
pages/api/ping.ts
Normal file
7
pages/api/ping.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
const handler = async (_: NextApiRequest, res: NextApiResponse) => {
|
||||
res.status(200).json("Hello world!");
|
||||
};
|
||||
|
||||
export default handler;
|
||||
23
pages/chat.tsx
Normal file
23
pages/chat.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NextPage } from "next";
|
||||
import Head from "next/head";
|
||||
import React, { useEffect } from "react";
|
||||
|
||||
const ChatPage: NextPage = () => {
|
||||
useEffect(() => {
|
||||
// todo
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>ChatDBA</title>
|
||||
<meta name="description" content="" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
||||
<main className="flex flex-col items-center justify-center m-20">WIP</main>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChatPage;
|
||||
29
pages/index.tsx
Normal file
29
pages/index.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextPage } from "next";
|
||||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
import React from "react";
|
||||
|
||||
const HomePage: NextPage = () => {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>ChatDBA</title>
|
||||
<meta name="description" content="" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
||||
<main className="flex min-h-screen flex-col items-center justify-center bg-black">
|
||||
<div className="flex flex-col items-center justify-center gap-12 px-4 py-16">
|
||||
<h1 className="text-5xl font-extrabold tracking-tight text-white sm:text-6xl">ChatDBA</h1>
|
||||
<div className="grid grid-cols-1 gap-4">
|
||||
<Link className="flex max-w-xs flex-col rounded-xl bg-gray-800 p-4 px-6 text-white hover:opacity-80" href="/chat">
|
||||
<h3 className="text-2xl font-medium">Chat →</h3>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default HomePage;
|
||||
3
pages/styles/globals.css
Normal file
3
pages/styles/globals.css
Normal file
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
2414
pnpm-lock.yaml
generated
Normal file
2414
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
postcss.config.js
Normal file
6
postcss.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
8
tailwind.config.js
Normal file
8
tailwind.config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
20
tsconfig.json
Normal file
20
tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user