diff --git a/app/.dockerignore b/.dockerignore similarity index 100% rename from app/.dockerignore rename to .dockerignore diff --git a/app/.eslintrc.json b/.eslintrc.json similarity index 100% rename from app/.eslintrc.json rename to .eslintrc.json diff --git a/app/.gitignore b/.gitignore similarity index 100% rename from app/.gitignore rename to .gitignore diff --git a/app/.prettierrc b/.prettierrc similarity index 100% rename from app/.prettierrc rename to .prettierrc diff --git a/app/Dockerfile b/Dockerfile similarity index 88% rename from app/Dockerfile rename to Dockerfile index eb83dc4..f9ccac2 100644 --- a/app/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +# This Dockerfile is generated based on sample in the following document +# https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile FROM node:18-alpine AS base # Install dependencies only when needed diff --git a/README.md b/README.md index f2e3562..289844a 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,64 @@ # GPT Lite -A lightweight version of ChatGPT UI. Support both Open AI and Azure Open AI accounts +English | [简体中文](./README.zh-CN.md) -![demo](demo.jpg) +GPT Lite is a web application that provides a fast ChatGPT user interface. It is built on top of Next.js and AntD. The app supports both Open AI and Azure Open AI accounts. -# How to run locally +Some example use cases for GPT Lite include: -1. Clone the repo -2. Install dependencies with `npm install` -3. Run the app with `npm run dev` -4. Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. +- The free version ChatGPT site The web version is prone to disconnecting and requires refreshing. The Plus subscription at 20 USD/month may not be cost-effective for some users, deploy a customized webchat UI with API integration is a more economical option. +- Deploy a customized chatgpt web app to exploring OpenAI's ChatGPT completion API. +- Create a private web chatbot using ChatGPT for exclusive use among friends without sharing api key. +- Learn developing web applications using OpenAI's API -# How to deploy +![demo](./docs/images/demo.jpg) -To be updated +## Prerequisites + +To use GPT Lite, you must have either an OpenAI account or an Azure Account + +## Running locally + +1. Ensure that NodeJS 18 is installed on your system. +2. Clone the repository in your terminal. +3. Install dependencies by running `npm install`. +4. Verify that you have set the `OPENAI_API_KEY` environment variable correctly. +5. Start the application with `npm run dev`. +6. Open [http://localhost:3000](http://localhost:3000) in your web browser. + +## Deploy with Docker + +1. Clone the repository and go to the `app` subdirectory in your terminal. +2. Update the `OPENAI_API_KEY` environment variables to the `docker-compose.yml` file. +3. Build the application using `docker-compose build .` +4. Start the application by running `docker-compose up -d`. + +## One click deploy on Vercel + +To easily connect GPT Lite to Vercel, simply click the button below. +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fblrchen%2Fgptlite&env=OPENAI_API_KEY&project-name=gptlite&framework=nextjs&repository-name=gptlite) + +## Environment Variables + +The following environments are specific to OpenAI. + +| Name | Description | Default Value | +| ------------------- | -------------------------------------------------------------------------------------------------------------------------------- | --------------------- | +| OPENAI_API_BASE_URL | Use this only if you intend to use a reserved proxy for `api.openai.com` | `https://api.openai.com` | +| OPENAI_API_KEY | To obtain the secret key string for OpenAI, please visit the [OpenAI API](https://platform.openai.com/account/api-keys) website. | | + +The following environments are specific to Azure OpenAI. + +| Name | Description | +| --------------------------- | -------------------------------------------------------- | +| AZURE_OPENAI_API_BASE_URL | Endpoint, example format:`https://xxx.openai.azure.com` | +| AZURE_OPENAI_API_KEY | Key | +| AZURE_OPENAI_API_DEPLOYMENT | Model deployment name | + +## Contribution + +Welcome PRs of any size. + +# Disclaimers + +This code is intended solely for demonstration and testing purposes. diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 0000000..934617d --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,64 @@ +# ChatGPT-API Demo + +[English](./README.md) | 简体中文 + +GPT Lite是一个ChatGPT UI的第三方页面,使用Next.js和AntD实现,支持Open AI和Azure Open AI账户。 + +下面是一些GPT Lite的用途: +- 虽然ChatGPT有官方网站,但是免费版非常容易断开连接并需要连续刷新,20美元/月的Plus订阅又很不划算,部署集成API的第三方UI程序是更经济的选择。 +- 部署一个定制化ChatGPT程序以探索OpenAI's ChatGPT来研究ChatGPT的completion API,prompt提示词等。 +- 部署一个方便家人朋友一起使用的ChatGPT程序,无须共享API密钥。 +- 学习使用OpenAI API开发Web应用程序 + +![demo](./docs/images/demo.jpg) + +## 使用要求 + +要使用GPT Lite,必须拥有OpenAI帐户或Azure帐户。 + +## 在本地运行 + +1. 确保安装了NodeJS 18。 +2. 打开命令行窗口里克隆代码。 +3. 运行`npm install`来安装依赖项。 +4. 确保设置了`OPENAI_API_KEY`环境变量。 +5. 运行`npm run dev`启动应用程序。 +6. 在Web浏览器中打开`http://localhost:3000`。 + +## 使用Docker部署 + +1. 打开命令行窗口里克隆代码。 +2. 更新`docker-compose.yml`文件中里的`OPENAI_API_KEY`环境变量。 +3. 运行`docker-compose build`构建。 +4. 运行`docker-compose up -d`启动。 + +## Vercel一键部署 + +点击下列Deploy按钮即可一键部署至Vercel +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fblrchen%2Fgptlite&env=OPENAI_API_KEY&project-name=gptlite&framework=nextjs&repository-name=gptlite) + +## 环境变量说明 + +以下是OpenAI相关的环境变量 + +| 名称 | 描述 | 默认值 | +|---------------------|-------------------------------------------------------------------------------|----------------------| +| OPENAI_API_BASE_URL | 反向代理 `api.openai.com` | `https://api.openai.com` | +| OPENAI_API_KEY | OpenAI key,可以从[OpenAI API](https://platform.openai.com/account/api-keys)网站获取. | | + +以下是Azure OpenAI相关的环境变量 + +| Name | Description | +| --------------------------- |------------------------------------------------| +| AZURE_OPENAI_API_BASE_URL | 格式类似`https://xxx.openai.azure.com` | +| AZURE_OPENAI_API_KEY | 密钥 | +| AZURE_OPENAI_API_DEPLOYMENT | Model部署的名称 | + + +## 贡献代码 + +欢迎各种PR,大小不限。Issue列表里所有带`Good First Issue`的issue都可以认领。 + +# 免责说明 + +此代码仅用于演示和测试目的。 \ No newline at end of file diff --git a/app/.idea/.gitignore b/app/.idea/.gitignore deleted file mode 100644 index b58b603..0000000 --- a/app/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/app/.idea/app.iml b/app/.idea/app.iml deleted file mode 100644 index 0c8867d..0000000 --- a/app/.idea/app.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/app/.idea/codeStyles/Project.xml b/app/.idea/codeStyles/Project.xml deleted file mode 100644 index f986f2f..0000000 --- a/app/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/.idea/codeStyles/codeStyleConfig.xml b/app/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 79ee123..0000000 --- a/app/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/.idea/inspectionProfiles/Project_Default.xml b/app/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 03d9549..0000000 --- a/app/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/.idea/modules.xml b/app/.idea/modules.xml deleted file mode 100644 index 8c4259d..0000000 --- a/app/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/.idea/vcs.xml b/app/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/app/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/README.md b/app/README.md deleted file mode 100644 index 965a122..0000000 --- a/app/README.md +++ /dev/null @@ -1,38 +0,0 @@ -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 -# or -pnpm 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.tsx`. 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.ts`. - -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. - -This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. - -## 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. diff --git a/app/public/favicon.ico b/app/public/favicon.ico deleted file mode 100644 index 718d6fe..0000000 Binary files a/app/public/favicon.ico and /dev/null differ diff --git a/app/public/next.svg b/app/public/next.svg deleted file mode 100644 index 5174b28..0000000 --- a/app/public/next.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/app/public/thirteen.svg b/app/public/thirteen.svg deleted file mode 100644 index 8977c1b..0000000 --- a/app/public/thirteen.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/app/public/vercel.svg b/app/public/vercel.svg deleted file mode 100644 index d2f8422..0000000 --- a/app/public/vercel.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/app/docker-compose.yml b/docker-compose.yml similarity index 55% rename from app/docker-compose.yml rename to docker-compose.yml index 042a0a6..44e9fb6 100644 --- a/app/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,12 @@ version: '3.8' services: gptlite: - build: . + build: app ports: - "3000:3000" environment: - - OPENAI_BASE_URL= + - OPENAI_API_BASE_URL= - OPENAI_API_KEY= - - AZURE_OPENAI_BASE_URL= - - AZURE_OPENAI_DEPLOYMENT= + - AZURE_OPENAI_API_BASE_URL= - AZURE_OPENAI_API_KEY= + - AZURE_OPENAI_DEPLOYMENT= \ No newline at end of file diff --git a/demo.jpg b/docs/images/demo.jpg similarity index 100% rename from demo.jpg rename to docs/images/demo.jpg diff --git a/app/next.config.js b/next.config.js similarity index 100% rename from app/next.config.js rename to next.config.js diff --git a/app/package-lock.json b/package-lock.json similarity index 100% rename from app/package-lock.json rename to package-lock.json diff --git a/app/package.json b/package.json similarity index 91% rename from app/package.json rename to package.json index d80d372..20bb87e 100644 --- a/app/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "next build", "start": "next start", "lint": "next lint", - "lint:prettier": "prettier --write \"src/**/*.{ts,tsx,js,html,css,less,md}\"" + "lint:prettier": "prettier --write \\\"src/**/*.{ts,tsx,js,html,css,less,md}\\\"" }, "dependencies": { "@ant-design/icons": "^4.7.0", diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/logo192.png b/public/logo192.png new file mode 100644 index 0000000..fc44b0a Binary files /dev/null and b/public/logo192.png differ diff --git a/app/src/components/ChatGPT/MessageItem.tsx b/src/components/ChatGPT/MessageItem.tsx similarity index 100% rename from app/src/components/ChatGPT/MessageItem.tsx rename to src/components/ChatGPT/MessageItem.tsx diff --git a/app/src/components/ChatGPT/SendBar.tsx b/src/components/ChatGPT/SendBar.tsx similarity index 100% rename from app/src/components/ChatGPT/SendBar.tsx rename to src/components/ChatGPT/SendBar.tsx diff --git a/app/src/components/ChatGPT/Show.tsx b/src/components/ChatGPT/Show.tsx similarity index 100% rename from app/src/components/ChatGPT/Show.tsx rename to src/components/ChatGPT/Show.tsx diff --git a/app/src/components/ChatGPT/index.less b/src/components/ChatGPT/index.less similarity index 100% rename from app/src/components/ChatGPT/index.less rename to src/components/ChatGPT/index.less diff --git a/app/src/components/ChatGPT/index.tsx b/src/components/ChatGPT/index.tsx similarity index 100% rename from app/src/components/ChatGPT/index.tsx rename to src/components/ChatGPT/index.tsx diff --git a/app/src/components/ChatGPT/interface.ts b/src/components/ChatGPT/interface.ts similarity index 100% rename from app/src/components/ChatGPT/interface.ts rename to src/components/ChatGPT/interface.ts diff --git a/app/src/components/ChatGPT/useChatGPT.ts b/src/components/ChatGPT/useChatGPT.ts similarity index 100% rename from app/src/components/ChatGPT/useChatGPT.ts rename to src/components/ChatGPT/useChatGPT.ts diff --git a/app/src/components/FooterBar/VersionBar.tsx b/src/components/FooterBar/VersionBar.tsx similarity index 100% rename from app/src/components/FooterBar/VersionBar.tsx rename to src/components/FooterBar/VersionBar.tsx diff --git a/app/src/components/FooterBar/index.module.less b/src/components/FooterBar/index.module.less similarity index 100% rename from app/src/components/FooterBar/index.module.less rename to src/components/FooterBar/index.module.less diff --git a/app/src/components/FooterBar/index.tsx b/src/components/FooterBar/index.tsx similarity index 100% rename from app/src/components/FooterBar/index.tsx rename to src/components/FooterBar/index.tsx diff --git a/app/src/components/HeaderBar/index.module.less b/src/components/HeaderBar/index.module.less similarity index 100% rename from app/src/components/HeaderBar/index.module.less rename to src/components/HeaderBar/index.module.less diff --git a/app/src/components/HeaderBar/index.tsx b/src/components/HeaderBar/index.tsx similarity index 94% rename from app/src/components/HeaderBar/index.tsx rename to src/components/HeaderBar/index.tsx index e521cf7..f2ecad5 100644 --- a/app/src/components/HeaderBar/index.tsx +++ b/src/components/HeaderBar/index.tsx @@ -15,6 +15,7 @@ const HeaderBar = () => {
+ logo

GPT Lite

diff --git a/app/src/models/index.ts b/src/models/index.ts similarity index 100% rename from app/src/models/index.ts rename to src/models/index.ts diff --git a/app/src/pages/_app.tsx b/src/pages/_app.tsx similarity index 100% rename from app/src/pages/_app.tsx rename to src/pages/_app.tsx diff --git a/app/src/pages/_document.tsx b/src/pages/_document.tsx similarity index 100% rename from app/src/pages/_document.tsx rename to src/pages/_document.tsx diff --git a/app/src/pages/api/chat-completion.ts b/src/pages/api/chat-completion.ts similarity index 92% rename from app/src/pages/api/chat-completion.ts rename to src/pages/api/chat-completion.ts index f511ff6..f34e6ff 100644 --- a/app/src/pages/api/chat-completion.ts +++ b/src/pages/api/chat-completion.ts @@ -6,7 +6,6 @@ export const config = { } const handler = async (req: Request): Promise => { - let deployment try { const { messages } = (await req.json()) as { messages: Message[] @@ -26,20 +25,20 @@ const handler = async (req: Request): Promise => { } const useAzureOpenAI = - process.env.AZURE_OPENAI_BASE_URL && process.env.AZURE_OPENAI_BASE_URL.length > 0 + process.env.AZURE_OPENAI_API_BASE_URL && process.env.AZURE_OPENAI_API_BASE_URL.length > 0 let apiUrl: string let apiKey: string let model: string if (useAzureOpenAI) { - const apiBaseUrl = process.env.AZURE_OPENAI_BASE_URL + const apiBaseUrl = process.env.AZURE_OPENAI_API_BASE_URL const version = '2023-03-15-preview' const deployment = process.env.AZURE_OPENAI_DEPLOYMENT || '' apiUrl = `${apiBaseUrl}/openai/deployments/${deployment}/chat/completions?api-version=${version}` apiKey = process.env.AZURE_OPENAI_API_KEY || '' model = 'gpt-35-turbo' } else { - const apiBaseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com' + const apiBaseUrl = process.env.OPENAI_API_BASE_URL || 'https://api.openai.com' apiUrl = `${apiBaseUrl}/v1/chat/completions` apiKey = process.env.OPENAI_API_KEY || '' model = 'gpt-3.5-turbo' diff --git a/app/src/pages/api/healthz.ts b/src/pages/api/healthz.ts similarity index 100% rename from app/src/pages/api/healthz.ts rename to src/pages/api/healthz.ts diff --git a/app/src/pages/index.module.less b/src/pages/index.module.less similarity index 100% rename from app/src/pages/index.module.less rename to src/pages/index.module.less diff --git a/app/src/pages/index.tsx b/src/pages/index.tsx similarity index 73% rename from app/src/pages/index.tsx rename to src/pages/index.tsx index 72d85e2..5b9955d 100644 --- a/app/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -13,8 +13,8 @@ export default function Home() { - {/**/} - + {/* */} + diff --git a/app/src/styles/globals.css b/src/styles/globals.css similarity index 100% rename from app/src/styles/globals.css rename to src/styles/globals.css diff --git a/app/src/typings/global.d.ts b/src/typings/global.d.ts similarity index 100% rename from app/src/typings/global.d.ts rename to src/typings/global.d.ts diff --git a/app/tsconfig.json b/tsconfig.json similarity index 89% rename from app/tsconfig.json rename to tsconfig.json index 61c19ab..736822b 100644 --- a/app/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,7 @@ "@/*": ["./src/*"] } }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "include": [ + "next-env.d.ts", "**/*.ts", "**/*.tsx"], "exclude": ["node_modules"] }