Skip to content

Commit

Permalink
Change default api version from 2023-05-15 to 2024-02-01
Browse files Browse the repository at this point in the history
  • Loading branch information
blrchen committed Apr 4, 2024
1 parent 51f9795 commit f223144
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 121 deletions.
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 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:20-alpine AS base

# Install dependencies only when needed
Expand Down Expand Up @@ -28,7 +29,9 @@ ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
Expand All @@ -41,4 +44,6 @@ EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]
# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD HOSTNAME="0.0.0.0" node server.js
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ docker run -d -p 3000:3000 scalaone/azure-openai-proxy

Follow these steps:

1. Install NodeJS 18.
1. Install NodeJS 20.
2. Clone the repository in the command line window.
3. Run `npm install` to install the dependencies.
4. Run `npm start` to start the application.
5. Use the script below for testing. Replace `AZURE_RESOURCE_ID`, `AZURE_MODEL_DEPLOYMENT`, and `AZURE_API_KEY` before running. The default value for `AZURE_API_VERSION` is `2023-05-15` and is optional.
5. Use the script below for testing. Replace `AZURE_RESOURCE_ID`, `AZURE_MODEL_DEPLOYMENT`, and `AZURE_API_KEY` before running. The default value for `AZURE_API_VERSION` is `2024-02-01` and is optional.

<details>
<summary>Test script</summary>
Expand Down Expand Up @@ -67,10 +67,11 @@ The azure-openai-proxy has been tested and confirmed to work with the following
| Application Name | Docker-compose File for E2E Test |
| --------------------------------------------------------------- | --------------------------------------------------------------- |
| [chatgpt-lite](https://github.com/blrchen/chatgpt-lite) | [docker-compose.yml](./e2e/chatgpt-lite/docker-compose.yml) |
| [chatgpt-minimal](https://github.com/blrchen/chatgpt-minimal) | [docker-compose.yml](./e2e/chatgpt-minimal/docker-compose.yml) |
| [chatgpt-next-web](https://github.com/Yidadaa/ChatGPT-Next-Web) | [docker-compose.yml](./e2e/chatgpt-next-web/docker-compose.yml) |
| [chatbot-ui](https://github.com/mckaywrigley/chatbot-ui) | [docker-compose.yml](./e2e/chatbot-ui/docker-compose.yml) |
| [chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web) | [docker-compose.yml](./e2e/chatgpt-web/docker-compose.yml) |
| [chatgpt-minimal](https://github.com/blrchen/chatgpt-minimal) | [docker-compose.yml](./e2e/chatgpt-minimal/docker-compose.yml) |


To test locally, follow these steps:

Expand Down
6 changes: 3 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ docker run -d -p 3000:3000 scalaone/azure-openai-proxy

遵循以下步骤:

1. 安装 NodeJS 18
1. 安装 NodeJS 20
2. 克隆代码到命令行窗口。
3. 运行 `npm install` 安装依赖项。
4. 运行 `npm start` 启动应用程序。
5. 运行下面脚本测试,运行前需要把`AZURE_RESOURCE_ID``AZURE_MODEL_DEPLOYMENT``AZURE_API_KEY``AZURE_API_VERSION`替换,`AZURE_API_VERSION`参数可选,默认是`2023-05-15`
5. 运行下面脚本测试,运行前需要把`AZURE_RESOURCE_ID``AZURE_MODEL_DEPLOYMENT``AZURE_API_KEY``AZURE_API_VERSION`替换,`AZURE_API_VERSION`参数可选,默认是`2024-02-01`

<details>
<summary>测试脚本</summary>
Expand Down Expand Up @@ -67,10 +67,10 @@ curl -X "POST" "http://localhost:3000/v1/chat/completions" \
| 应用名称 | E2E测试 Docker-compose 文件 |
| --------------------------------------------------------------- | --------------------------------------------------------------- |
| [chatgpt-lite](https://github.com/blrchen/chatgpt-lite) | [docker-compose.yml](./e2e/chatgpt-lite/docker-compose.yml) |
| [chatgpt-minimal](https://github.com/blrchen/chatgpt-minimal) | [docker-compose.yml](./e2e/chatgpt-minimal/docker-compose.yml) |
| [chatgpt-next-web](https://github.com/Yidadaa/ChatGPT-Next-Web) | [docker-compose.yml](./e2e/chatgpt-next-web/docker-compose.yml) |
| [chatbot-ui](https://github.com/mckaywrigley/chatbot-ui) | [docker-compose.yml](./e2e/chatbot-ui/docker-compose.yml) |
| [chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web) | [docker-compose.yml](./e2e/chatgpt-web/docker-compose.yml) |
| [chatgpt-minimal](https://github.com/blrchen/chatgpt-minimal) | [docker-compose.yml](./e2e/chatgpt-minimal/docker-compose.yml) |

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

Expand Down
Binary file removed app/favicon.ico
Binary file not shown.
11 changes: 0 additions & 11 deletions app/layout.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions app/page.tsx

This file was deleted.

18 changes: 7 additions & 11 deletions app/v1/chat/completions/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from 'next/server'

const DEFAULT_API_VERSION = '2023-05-15'
const DEFAULT_API_VERSION = '2024-02-01'
const MAX_RETRY_COUNT = 3
const RETRY_DELAY = 1000

Expand All @@ -13,26 +13,22 @@ export async function POST(request: NextRequest) {

let retryCount = 0
while (true) {
let response = await chat(apiKey, body)
const response = await chat(apiKey, body)
const status = response.status
if (status < 300 || (status >= 400 && status < 500)) {
if (status < 300 || (status >= 400 && status < 500) || retryCount >= MAX_RETRY_COUNT) {
return response
}
if (retryCount >= MAX_RETRY_COUNT) {
return response
} else {
retryCount++
console.log(`Status is ${status}, Retry ${retryCount} times`)
await delay(RETRY_DELAY)
}

retryCount++
console.log(`Status is ${status}, Retry ${retryCount} times`)
await delay(RETRY_DELAY)
}
}

async function chat(apiKey: string, body: any) {
const [resourceId, mapping, azureApiKey, apiVersion] = apiKey.split(':')
const model = body['model']

// get deployment id
let deploymentId
if (mapping.includes('|')) {
const modelMapping = Object.fromEntries(mapping.split(',').map((pair) => pair.split('|')))
Expand Down
6 changes: 2 additions & 4 deletions deploy/azure-deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"webAppName": "[concat(parameters('resourcePrefix'),'webapp' )]",
"webAppPlanName": "[concat(parameters('resourcePrefix'),'appplan' )]",
"webAppPlanSku": "B1",
"webAppAPIVersion": "2021-03-01",
"webAppAPIVersion": "2021-03-01",
"preBuiltdockerImage": "scalaone/azure-openai-proxy:latest"
},
"functions": [],
Expand All @@ -40,9 +40,7 @@
"apiVersion": "[variables('webAppAPIVersion')]",
"name": "[variables('webAppName')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('webAppPlanName'))]"
],
"dependsOn": ["[resourceId('Microsoft.Web/serverfarms', variables('webAppPlanName'))]"],
"kind": "app,linux,container",
"identity": {
"type": "SystemAssigned"
Expand Down
2 changes: 2 additions & 0 deletions e2e/chatbot-ui/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '3.8'

services:
# ChatGPT UI application
chatbot-ui:
container_name: chatbot-ui
image: ghcr.io/mckaywrigley/chatbot-ui:main
Expand All @@ -15,6 +16,7 @@ services:
- vnet
restart: unless-stopped

# Azure OpenAI Proxy service
azure-openai-proxy:
container_name: azure-openai-proxy
build:
Expand Down
2 changes: 2 additions & 0 deletions e2e/chatgpt-lite/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '3.8'

services:
# ChatGPT UI application
chatgpt-lite:
container_name: chatgpt-lite
image: blrchen/chatgpt-lite:main
Expand All @@ -15,6 +16,7 @@ services:
- vnet
restart: unless-stopped

# Azure OpenAI Proxy service
azure-openai-proxy:
container_name: azure-openai-proxy
build:
Expand Down
2 changes: 2 additions & 0 deletions e2e/chatgpt-minimal/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '3.8'

services:
# ChatGPT UI application
chatgpt-minimal:
container_name: chatgpt-minimal
image: blrchen/chatgpt-minimal:main
Expand All @@ -15,6 +16,7 @@ services:
- vnet
restart: unless-stopped

# Azure OpenAI Proxy service
azure-openai-proxy:
container_name: azure-openai-proxy
build:
Expand Down
2 changes: 1 addition & 1 deletion e2e/chatgpt-next-web/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.8'

services:
# ChatGPT Next Web service
# ChatGPT UI application
chatgpt-next-web:
container_name: chatgpt-next-web
image: yidadaa/chatgpt-next-web:latest
Expand Down
2 changes: 2 additions & 0 deletions e2e/chatgpt-web/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '3.8'

services:
# ChatGPT UI application
chatgpt-web:
container_name: chatgpt-web
image: chenzhaoyu94/chatgpt-web
Expand All @@ -19,6 +20,7 @@ services:
- vnet
restart: unless-stopped

# Azure OpenAI Proxy service
azure-openai-proxy:
container_name: azure-openai-proxy
build:
Expand Down
Loading

0 comments on commit f223144

Please sign in to comment.