diff --git a/next.config.js b/next.config.js index 10b5577..edb615b 100644 --- a/next.config.js +++ b/next.config.js @@ -8,4 +8,4 @@ const nextConfig = { }, }; -export default nextConfig; \ No newline at end of file +export default nextConfig; diff --git a/package.json b/package.json index 72144e4..0b13499 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "prettier --check '{*,pages/*,public/*,utils/*}.{ts,tsx,js,jsx,json}' && next lint", + "prettier": "prettier --write '{*,pages/*,public/*,utils/*}.{ts,tsx,js,jsx,json}'" }, "dependencies": { "@emotion/react": "^11.10.8", diff --git a/pages/_app.tsx b/pages/_app.tsx index 021681f..a7a790f 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,6 +1,6 @@ -import '@/styles/globals.css' -import type { AppProps } from 'next/app' +import "@/styles/globals.css"; +import type { AppProps } from "next/app"; export default function App({ Component, pageProps }: AppProps) { - return + return ; } diff --git a/pages/_document.tsx b/pages/_document.tsx index 54e8bf3..b2fff8b 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -1,4 +1,4 @@ -import { Html, Head, Main, NextScript } from 'next/document' +import { Html, Head, Main, NextScript } from "next/document"; export default function Document() { return ( @@ -9,5 +9,5 @@ export default function Document() { - ) + ); } diff --git a/pages/api/chat.ts b/pages/api/chat.ts index 12ee482..d5fad27 100644 --- a/pages/api/chat.ts +++ b/pages/api/chat.ts @@ -3,20 +3,17 @@ import { Configuration, OpenAIApi, - ChatCompletionRequestMessageRoleEnum,} from "openai"; + ChatCompletionRequestMessageRoleEnum, +} from "openai"; import type { NextApiRequest, NextApiResponse } from "next"; - const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); -async function chatHandler( - req: NextApiRequest, - res: NextApiResponse -) { +async function chatHandler(req: NextApiRequest, res: NextApiResponse) { const completion = await openai.createChatCompletion({ // Downgraded to GPT-3.5 due to high traffic. Sorry for the inconvenience. // If you have access to GPT-4, simply change the model to "gpt-4" @@ -26,7 +23,6 @@ async function chatHandler( role: ChatCompletionRequestMessageRoleEnum.System, content: "You are a helpful assistant.", }, - ].concat(req.body.messages), temperature: 0, }); diff --git a/pages/index.tsx b/pages/index.tsx index 383a6a3..d70efa5 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,4 +1,4 @@ -import { useState, useRef, useEffect, FormEvent, KeyboardEvent} from "react"; +import { useState, useRef, useEffect, FormEvent, KeyboardEvent } from "react"; import Head from "next/head"; import styles from "../styles/Home.module.css"; import Image from "next/image"; @@ -16,7 +16,6 @@ export default function Home() { const messageListRef = useRef(null); const textAreaRef = useRef(null); - // Auto scroll chat to bottom useEffect(() => { if (messageListRef.current) { @@ -25,12 +24,12 @@ export default function Home() { } }, [messages]); -// Focus on input field -useEffect(() => { - if (textAreaRef.current) { - textAreaRef.current.focus(); - } -}, []); + // Focus on input field + useEffect(() => { + if (textAreaRef.current) { + textAreaRef.current.focus(); + } + }, []); // Handle errors const handleError = () => { @@ -113,7 +112,6 @@ useEffect(() => { > Docs -
@@ -175,7 +173,6 @@ useEffect(() => { autoFocus={false} rows={1} maxLength={512} - id="userInput" name="userInput" placeholder={ @@ -213,7 +210,7 @@ useEffect(() => { OpenAI - . + .