Skip to content

Commit

Permalink
Upgrade Azure OpenAI API version to 2023-05-15 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
blrchen committed Jul 3, 2023
1 parent b29cc73 commit a7bfa39
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 38 deletions.
68 changes: 41 additions & 27 deletions README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@

[English](./README.en-US.md) | Simplified Chinese

An Azure OpenAI API proxy tool that can convert OpenAI API requests into Azure OpenAI API requests, allowing applications that only support OpenAI to seamlessly use Azure Open AI.
Azure OpenAI Proxy is a tool that transforms OpenAI API requests into Azure OpenAI API requests. This allows applications that are compatible only with OpenAI to use Azure Open AI seamlessly.

## Usage Requirements
## Prerequisites

You must have an Azure OpenAI account to use the Azure OpenAI Proxy.
To use Azure OpenAI Proxy, you need an Azure OpenAI account.

## Deploy to Azure
## Azure Deployment

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fscalaone%2Fazure-openai-proxy%2Fmain%2Fdeploy%2Fazure-deploy.json)

## Docker Deployment

Run the following command to deploy using Docker:

`docker run -d -p 3000:3000 scalaone/azure-openai-proxy`

## Local Running and Testing, Command Line Method
## Local Execution and Testing (Command Line)

Follow the steps below:

1. Install NodeJS 18.
2. Clone the code in the command line window.
3. Run `npm install` to install dependencies.
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. 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`.
5. Use the script below for testing. Replace `AZURE_RESOURCE_ID`, `AZURE_MODEL_DEPLOYMENT`, and `AZURE_API_KEY` before executing. `AZURE_API_VERSION` is optional, its default value is `2023-05-15`.

<details>
<summary>Test script</summary>

```bash
curl -X "POST" "http://localhost:3000/v1/chat/completions" \
-H 'Authorization: AZURE_RESOURCE_ID:AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY:AZURE_API_VERSION' \
Expand All @@ -44,45 +52,51 @@ curl -X "POST" "http://localhost:3000/v1/chat/completions" \
}'
```

## App has been tested
</details>

## Tested Applications

The following apps have been tested and confirmed to work with the azure-openai-proxy:
The azure-openai-proxy has been tested and confirmed to work with the following applications:

| App Name | E2E Docker-compose file |
|------------------|-------------------------|
| Application Name | Docker-compose File |
|------------------|---------------------|
| [chatbot-ui](https://github.com/mckaywrigley/chatbot-ui) | [docker-compose.yml](./e2e/chatbot-ui/docker-compose.yml) |
| [chatgpt-next-web](https://github.com/Yidadaa/ChatGPT-Next-Web) | [docker-compose.yml](./e2e/chatgpt-next-web/docker-compose.yml) |
| [chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web) | [docker-compose.yml](./e2e/chatgpt-web/docker-compose.yml) |
| [chatgpt-lite](https://github.com/blrchen/chatgpt-lite) | [docker-compose.yml](./e2e/chatgpt-lite/docker-compose.yml) |
| [chatgpt-mininal](https://github.com/blrchen/chatgpt-mininal) | [docker-compose.yml](./e2e/chatgpt-mininal/docker-compose.yml) |

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

1. Clone the code in a command-line window.
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.
3. Navigate to the directory containing the `docker-compose.yml` file for the app you want to test.
4. Execute the build command: `docker-compose build`.
1. Clone the repository in a command-line window.
2. Update the `OPENAPI_API_KEY` environment variable with `AZURE_RESOURCE_ID:AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY`. Alternatively, update the OPENAPI_API_KEY value directly in the docker-compose.yml file.
3. Navigate to the directory containing the `docker-compose.yml` file for the application you want to test.
4. Run the build command: `docker-compose build`.
5. Start the service: `docker-compose up -d`.
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.
6. Launch the application locally using the exposed port defined in the docker-compose.yml file. For example, visit http://localhost:3000.

## Frequently Asked Questions
## FAQs

Q: What is `AZURE_RESOURCE_ID`,`AZURE_MODEL_DEPLOYMENT`,`AZURE_API_KEY`?
<details>
<summary>Q: What are `AZURE_RESOURCE_ID`,`AZURE_MODEL_DEPLOYMENT`, and `AZURE_API_KEY`?

A: It can be found in azure management portal, see image below for details:
A: You can find these in the Azure management portal. Refer to the image below for details:

![resource-and-model](./resource-and-model.jpg)
</details>

Q: How do I support GPT-4?
<details>
<summary>Q: How can I use GPT-4?

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

`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`
</details>

# How To Contribute Code?
## Contributing

Welcome to submit various PRs.
We welcome various PR submissions.

# Disclaimer
## Disclaimer

This code is for demonstration and testing purposes only.
This code is intended for demonstration and testing purposes only.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[English](./README.en-US.md) | 简体中文

一个 Azure OpenAI API 代理工具,能将 OpenAI API 请求转换为 Azure OpenAI API 请求,使仅支持 OpenAI 的应用程序可以无缝地使用 Azure Open AI
Azure OpenAI Proxy是一个 OpenAI API 代理工具,它可以将OpenAI API请求转换为Azure OpenAI API请求,使仅支持OpenAI的应用程序可以无缝地使用Azure OpenAI。

## 使用要求

Expand All @@ -14,15 +14,21 @@

## Docker Deployment

`docker run -d -p 3000:3000 scalaone/azure-openai-proxy`
```bash
docker run -d -p 3000:3000 scalaone/azure-openai-proxy
```

## 本地运行和测试,命令行方式

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

<details>
<summary>测试脚本</summary>

```bash
curl -X "POST" "http://localhost:3000/v1/chat/completions" \
-H 'Authorization: AZURE_RESOURCE_ID:AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY:AZURE_API_VERSION' \
Expand All @@ -44,6 +50,8 @@ curl -X "POST" "http://localhost:3000/v1/chat/completions" \
}'
```

</details>

## 已测试应用

以下应用已经过测试,确认可以与 azure-openai-proxy 一起工作:
Expand All @@ -61,23 +69,25 @@ curl -X "POST" "http://localhost:3000/v1/chat/completions" \
1. 在命令行窗口中克隆代码。
2. 更新环境变量`OPENAPI_API_KEY`的值为`AZURE_RESOURCE_ID:AZURE_MODEL_DEPLOYMENT:AZURE_API_KEY`。或者,直接在`docker-compose.yml`文件中更新`OPENAPI_API_KEY`值。
3. 导航到包含要测试的应用程序的`docker-compose.yml`文件所在的目录。
3. 执行构建命令:`docker-compose build`
4. 启动服务:`docker-compose up -d`
5. 根据`docker-compose.yml`文件中定义的公开端口,启动应用以在本地进行测试。例如,访问 http://localhost:3000。
4. 执行构建命令:`docker-compose build`
5. 启动服务:`docker-compose up -d`
6. 根据`docker-compose.yml`文件中定义的公开端口,启动应用以在本地进行测试。例如,访问 http://localhost:3000。

## 常见问题

Q:什么是`AZURE_RESOURCE_ID``AZURE_MODEL_DEPLOYMENT``AZURE_API_KEY`

<details>
<summary>Q:什么是`AZURE_RESOURCE_ID`,`AZURE_MODEL_DEPLOYMENT`,`AZURE_API_KEY`</summary>
A: 可以在Azure的管理门户里查找,具体见下图标注

![resource-and-model](./resource-and-model.jpg)
</details>

Q: 如何支持GPT-4

<details>
<summary>Q: 如何支持GPT-4</summary>
A: 要使用GPT-4,请使用下列格式的key:

`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`
</details>

# 贡献代码方式

Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ logger.add(new logger.transports.Console({
format: logger.format.simple()
}));

const DEFAULT_API_VERSION = '2023-03-15-preview'
const DEFAULT_API_VERSION = '2023-05-15'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method !== 'POST') {
Expand Down

0 comments on commit a7bfa39

Please sign in to comment.