Skip to content

Commit dfdabd6

Browse files
authored
Rewrite the entire code base using Next.js (#12)
1 parent b1795ac commit dfdabd6

35 files changed

+4631
-8458
lines changed

.deployment

Lines changed: 0 additions & 2 deletions
This file was deleted.

.dockerignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

.gitignore

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
# compiled output
2-
/dist
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
34
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
410

5-
# Logs
6-
logs
7-
*.log
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
823
npm-debug.log*
9-
pnpm-debug.log*
1024
yarn-debug.log*
1125
yarn-error.log*
12-
lerna-debug.log*
1326

14-
# OS
15-
.DS_Store
27+
# local env files
28+
.env*.local
1629

17-
# Tests
18-
/coverage
19-
/.nyc_output
20-
21-
# IDEs and editors
22-
/.idea
23-
.project
24-
.classpath
25-
.c9/
26-
*.launch
27-
.settings/
28-
*.sublime-workspace
29-
30-
# IDE - VSCode
31-
.vscode/*
32-
!.vscode/settings.json
33-
!.vscode/tasks.json
34-
!.vscode/launch.json
35-
!.vscode/extensions.json
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts
36+
37+
# JetBrains
38+
.idea/

.prettierrc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
{
2-
"printWidth": 120,
2+
"printWidth": 100,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
36
"singleQuote": true,
4-
"trailingComma": "all"
7+
"quoteProps": "as-needed",
8+
"jsxSingleQuote": false,
9+
"trailingComma": "none",
10+
"bracketSpacing": true,
11+
"bracketSameLine": false,
12+
"arrowParens": "always",
13+
"rangeStart": 0,
14+
"requirePragma": false,
15+
"insertPragma": false,
16+
"proseWrap": "preserve",
17+
"htmlWhitespaceSensitivity": "css",
18+
"endOfLine": "lf"
519
}

.vscode/settings.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

Dockerfile

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
1-
# Building layer
2-
FROM node:18-alpine as development
1+
# This Dockerfile is generated based on sample in the following document
2+
# https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
3+
FROM node:18-alpine AS base
4+
5+
# Install dependencies only when needed
6+
FROM base AS deps
7+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8+
RUN apk add --no-cache libc6-compat
39
WORKDIR /app
410

5-
# Copy configuration files
6-
COPY tsconfig*.json ./
7-
COPY package*.json ./
8-
9-
# Install dependencies from package-lock.json
11+
# Install dependencies based on the preferred package manager
12+
COPY package.json package-lock.json* ./
1013
RUN npm ci
1114

12-
# Copy application sources (.ts, .tsx, js)
13-
COPY src/ src/
14-
15-
# Build application (produces dist/ folder)
15+
# Rebuild the source code only when needed
16+
FROM base AS builder
17+
WORKDIR /app
18+
COPY --from=deps /app/node_modules ./node_modules
19+
COPY . .
1620
RUN npm run build
1721

18-
# Runtime (production) layer
19-
FROM node:18-alpine as production
22+
# Production image, copy all the files and run next
23+
FROM base AS runner
2024
WORKDIR /app
2125

22-
# Copy dependencies files
23-
COPY package*.json ./
26+
ENV NODE_ENV production
2427

25-
# Install runtime dependencies (without dev/test dependencies)
26-
RUN npm ci --only=production
28+
RUN addgroup --system --gid 1001 nodejs
29+
RUN adduser --system --uid 1001 nextjs
2730

28-
# Copy production build
29-
COPY --from=development /app/dist/ ./dist/
31+
COPY --from=builder /app/public ./public
32+
33+
# Automatically leverage output traces to reduce image size
34+
# https://nextjs.org/docs/advanced-features/output-file-tracing
35+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
36+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
37+
38+
USER nextjs
3039

31-
# Expose application port
3240
EXPOSE 3000
3341

34-
# Start application
35-
CMD [ "node", "dist/main.js" ]
42+
ENV PORT 3000
43+
44+
CMD ["node", "server.js"]

README.en-US.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ You must have an Azure OpenAI account to use the Azure OpenAI Proxy.
2222
2. Clone the code in the command line window.
2323
3. Run `npm install` to install dependencies.
2424
4. Run `npm start` to start the application.
25-
5. Run the script below for testing, replacing `YOUR_RESOURCE_ID`, `YOUR_MODEL_DEPLOYMENT`, and `YOUR_API_KEY` before running it, `AZURE_API_VERSION` is optional and the default value is `2023-03-15-preview`.
25+
5. Run the script below for testing, replacing `AZURE_RESOURCE_ID`, `AZURE_MODEL_DEPLOYMENT`, and `AZURE_API_KEY` before running it, `AZURE_API_VERSION` is optional and the default value is `2023-03-15-preview`.
2626
```bash
2727
curl -X "POST" "http://localhost:3000/v1/chat/completions" \
28-
-H 'Authorization: YOUR_RESOURCE_ID:YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY:AZURE_API_VERSION' \
28+
-H 'Authorization: AZURE_RESOURCE_ID:AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY:AZURE_API_VERSION' \
2929
-H 'Content-Type: application/json; charset=utf-8' \
3030
-d $'{
3131
"messages": [
@@ -51,21 +51,22 @@ The following apps have been tested and confirmed to work with the azure-openai-
5151
| App Name | E2E Docker-compose file |
5252
|------------------|-------------------------|
5353
| [chatbot-ui](https://github.com/mckaywrigley/chatbot-ui) | [docker-compose.yml](./e2e/chatbot-ui/docker-compose.yml) |
54+
| [chatgpt-next-web](https://github.com/Yidadaa/ChatGPT-Next-Web) | [docker-compose.yml](./e2e/chatgpt-next-web/docker-compose.yml) |
5455
| [chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web) | [docker-compose.yml](./e2e/chatgpt-web/docker-compose.yml) |
5556
| [gptlite](https://github.com/blrchen/gptlite) | [docker-compose.yml](./e2e/gptlite/docker-compose.yml) |
5657

5758
To run a test locally, please follow these steps:
5859

5960
1. Clone the code in a command-line window.
60-
2. Update the environment variable `OPENAPI_API_KEY` with `YOUR_RESOURCE_ID:YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY`. Alternatively, you can update the OPENAPI_API_KEY value directly in the docker-compose.yml file.
61+
2. Update the environment variable `OPENAPI_API_KEY` with `AZURE_RESOURCE_ID:AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY`. Alternatively, you can update the OPENAPI_API_KEY value directly in the docker-compose.yml file.
6162
3. Navigate to the directory containing the `docker-compose.yml` file for the app you want to test.
6263
4. Execute the build command: `docker-compose build`.
6364
5. Start the service: `docker-compose up -d`.
6465
6. Based on the exposed port defined in the docker-compose.yml file, launch the app to test it locally. For example, visit http://localhost:3000.
6566

6667
## Frequently Asked Questions
6768

68-
Q: What is `YOUR_RESOURCE_ID`,`YOUR_MODEL_DEPLOYMENT`,`YOUR_API_KEY`?
69+
Q: What is `AZURE_RESOURCE_ID`,`AZURE_MODEL_DEPLOYMENT`,`AZURE_API_KEY`?
6970

7071
A: It can be found in azure management portal, see image below for details:
7172

@@ -75,7 +76,7 @@ Q: How do I support GPT-4?
7576

7677
A: To use GPT-4, please use key format as follows:
7778

78-
`YOUR_RESOURCE_ID:gpt-3.5-turbo|YOUR_MODEL_DEPLOYMENT,gpt-4|YOUR_MODEL_DEPLOYMENT,gpt-4-32k|YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY:AZURE_API_VERSION`
79+
`AZURE_RESOURCE_ID:gpt-3.5-turbo|AZURE_MODEL_DEPLOYMENT,gpt-4|AZURE_MODEL_DEPLOYMENT,gpt-4-32k|AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY:AZURE_API_VERSION`
7980

8081
# How To Contribute Code?
8182

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
2. 克隆代码到命令行窗口。
2323
3. 运行 `npm install` 安装依赖项。
2424
4. 运行 `npm start` 启动应用程序。
25-
5. 运行下面脚本测试,运行前需要把`YOUR_RESOURCE_ID``YOUR_MODEL_DEPLOYMENT``YOUR_API_KEY`, `AZURE_API_VERSION`替换,`AZURE_API_VERSION`参数可选,目前默认是2023-03-15-preview。
25+
5. 运行下面脚本测试,运行前需要把`AZURE_RESOURCE_ID``AZURE_MODEL_DEPLOYMENT``AZURE_API_KEY`, `AZURE_API_VERSION`替换,`AZURE_API_VERSION`参数可选,目前默认是`2023-03-15-preview`
2626
```bash
2727
curl -X "POST" "http://localhost:3000/v1/chat/completions" \
28-
-H 'Authorization: YOUR_RESOURCE_ID:YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY:AZURE_API_VERSION' \
28+
-H 'Authorization: AZURE_RESOURCE_ID:AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY:AZURE_API_VERSION' \
2929
-H 'Content-Type: application/json; charset=utf-8' \
3030
-d $'{
3131
"messages": [
@@ -51,21 +51,22 @@ curl -X "POST" "http://localhost:3000/v1/chat/completions" \
5151
| App Name | E2E Docker-compose file |
5252
|------------------|-------------------------|
5353
| [chatbot-ui](https://github.com/mckaywrigley/chatbot-ui) | [docker-compose.yml](./e2e/chatbot-ui/docker-compose.yml) |
54+
| [chatgpt-next-web](https://github.com/Yidadaa/ChatGPT-Next-Web) | [docker-compose.yml](./e2e/chatgpt-next-web/docker-compose.yml) |
5455
| [chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web) | [docker-compose.yml](./e2e/chatgpt-web/docker-compose.yml) |
5556
| [gptlite](https://github.com/blrchen/gptlite) | [docker-compose.yml](./e2e/gptlite/docker-compose.yml) |
5657

5758
要在本地运行测试,请按照以下步骤操作:
5859

5960
1. 在命令行窗口中克隆代码。
60-
2. 更新环境变量`OPENAPI_API_KEY`的值为`YOUR_RESOURCE_ID:YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY`。或者,直接在`docker-compose.yml`文件中更新`OPENAPI_API_KEY`值。
61+
2. 更新环境变量`OPENAPI_API_KEY`的值为`AZURE_RESOURCE_ID:AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY`。或者,直接在`docker-compose.yml`文件中更新`OPENAPI_API_KEY`值。
6162
3. 导航到包含要测试的应用程序的`docker-compose.yml`文件所在的目录。
6263
3. 执行构建命令:`docker-compose build`
6364
4. 启动服务:`docker-compose up -d`
6465
5. 根据`docker-compose.yml`文件中定义的公开端口,启动应用以在本地进行测试。例如,访问 http://localhost:3000。
6566

6667
## 常见问题
6768

68-
Q:什么是`YOUR_RESOURCE_ID``YOUR_MODEL_DEPLOYMENT``YOUR_API_KEY`
69+
Q:什么是`AZURE_RESOURCE_ID``AZURE_MODEL_DEPLOYMENT``AZURE_API_KEY`
6970

7071
A: 可以在Azure的管理门户里查找,具体见下图标注
7172

@@ -75,7 +76,7 @@ Q: 如何支持GPT-4
7576

7677
A: 要使用GPT-4,请使用下列格式的key:
7778

78-
`YOUR_RESOURCE_ID:gpt-3.5-turbo|YOUR_MODEL_DEPLOYMENT,gpt-4|YOUR_MODEL_DEPLOYMENT,gpt-4-32k|YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY:AZURE_API_VERSION`
79+
`AZURE_RESOURCE_ID:gpt-3.5-turbo|AZURE_MODEL_DEPLOYMENT,gpt-4|AZURE_MODEL_DEPLOYMENT,gpt-4-32k|AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY:AZURE_API_VERSION`
7980

8081
# 贡献代码方式
8182

nest-cli.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

next.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const nextConfig = {
2+
output: 'standalone',
3+
reactStrictMode: true,
4+
async rewrites() {
5+
return [
6+
{
7+
source: '/v1/:path*',
8+
destination: '/api/:path*'
9+
}
10+
]
11+
}
12+
}
13+
14+
module.exports = nextConfig

0 commit comments

Comments
 (0)