Skip to content

Commit

Permalink
Add docker compose file and update README (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
blrchen committed Apr 14, 2023
1 parent 3977711 commit d9fc957
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 62 deletions.
70 changes: 70 additions & 0 deletions README.en-US.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Azure OpenAI Proxy

[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.

## Usage Requirements

You must have an Azure OpenAI account to use the Azure OpenAI Proxy.

## Docker Deployment
`docker run -d -p 3080:3080 scalaone/azure-openai-proxy`

## Local Running and Testing, Command Line Method

1. Install NodeJS 18.
2. Clone the code in the command line window.
3. Run `npm install` to install dependencies.
4. Run `npm start` to start the application.
5. Run the script below for testing, replacing `YOUR_RESOURCE_ID`, `YOUR_MODEL_DEPLOYMENT`, and `YOUR_API_KEY` before running it.
```bash
curl -X "POST" "http://localhost:3000/v1/chat/completions" \
-H 'Authorization: YOUR_RESOURCE_ID:YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"messages": [
{
"role": "system",
"content": "You are an AI assistant that helps people find information."
},
{
"role": "user",
"content": "hi."
}
],
"temperature": 1,
"model": "gpt-3.5-turbo",
"stream": false
}'
```

## Local Running and Testing, Using WebChat for Streaming Test

1. Clone code in command line window
2. Update environment variable of OPENAPI_API_KEY on line nine of docker-compose.yml file with `YOUR_RESOURCE_ID:YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY`
3. Execute build:run docker-compose build
4. Start service:run docker-compose up -d
5. Launch `http://localhost:3000`

Frequently Asked Questions

Q:What is `YOUR_RESOURCE_ID`,`YOUR_MODEL_DEPLOYMENT`,`YOUR_API_KEY`?

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

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

Q:How do I support GPT-4?

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

`YOUR_RESOURCE_ID:gpt-3.5-turbo|YOUR_MODEL_DEPLOYMENT,gpt-4|YOUR_MODEL_DEPLOYMENT,gpt-4-32k|YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY`

# How To Contribute Code?

Welcome to submit various PRs.

# Disclaimer

This code is for demonstration and testing purposes only.
103 changes: 41 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,36 @@
# Azure-OpenAI-Proxy
# Azure OpenAI Proxy

Azure-OpenAI-Proxy is an application that serves as a proxy for OpenAI's API. It enables users to request AI-generated text completions for specific prompts, using different models and parameters. The proxy supports GPT-4 models in addition to other available models. It simplifies the interaction with the OpenAI API and helps manage multiple deployments with ease for your AI-based text generation applications.
[English](./README.en-US.md) | 简体中文

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

Follow these steps to set up Azure-OpenAI-Proxy:
## 使用要求

1. Clone the repository:
必须拥有Azure OpenAI帐户才能使用 Azure OpenAI Proxy。

```
git clone https://github.com/scalaone/azure-openai-proxy.git
```

2. Navigate to the project directory:

```
cd azure-openai-proxy
```

3. Install the required dependencies:

```
npm install
```
## Docker部署
`docker run -d -p 3080:3080 scalaone/azure-openai-proxy`

4. Replace the placeholder values in the example request as mentioned in the [Usage section](#usage) with your actual resource ID, deployment IDs, model names, and API key.
## 本地运行和测试,命令行方式

5. Run the application:

```
npm run start
```

The Azure-OpenAI-Proxy will be running on your server and listening for incoming requests.

## Usage

To send a request, use a `curl` command to POST the input data to the application's URL. Replace the placeholder values with your actual resource ID, deployment IDs, model names, and API key.

Example request:

```
curl -X "POST" "https://openaiproxy2.azurewebsites.net/v1/chat/completions" \
-H 'Authorization: Bearer YOUR_RESOURCE_ID:YOUR_MODEL_NAME_IDENTIFIERS:YOUR_API_KEY' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
1. 安装 NodeJS 18。
2. 克隆代码到命令行窗口。
3. 运行 `npm install` 安装依赖项。
4. 运行 `npm start` 启动应用程序。
5. 运行下面脚本测试,运行前需要把`YOUR_RESOURCE_ID``YOUR_MODEL_DEPLOYMENT``YOUR_API_KEY`替换。
```bash
curl -X "POST" "http://localhost:3000/v1/chat/completions" \
-H 'Authorization: YOUR_RESOURCE_ID:YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"messages": [
{
"content": "hi",
"role": "user"
"role": "system",
"content": "You are an AI assistant that helps people find information."
},
{
"role": "user",
"content": "hi."
}
],
"temperature": 1,
Expand All @@ -57,35 +39,32 @@ curl -X "POST" "https://openaiproxy2.azurewebsites.net/v1/chat/completions" \
}'
```

Replace the following placeholder values:
## 本地运行和测试,使用WebChat测试streaming

- `YOUR_RESOURCE_ID` with the actual resource ID (e.g., `hai`).
- `YOUR_MODEL_NAME_IDENTIFIERS` with the actual model and deployment ID mappings (e.g., `gpt-3.5-turbo|gpt-35-turbo,gpt-4|gpt-4,gpt-4-32k|gpt-4-32k`).
- `YOUR_API_KEY` with your actual API key (e.g., `xxxxxx`).
1. 克隆代码到命令行窗口
2. 更新 `docker-compose.yml` 文件中第九行的 `OPENAI_API_KEY` 环境变量为`YOUR_RESOURCE_ID:YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY`
3. 执行构建:运行 `docker-compose build`
4. 启动服务:运行 `docker-compose up -d`
5. 运行`http://localhost:3000`

## Parameters
常见问题

The request body contains the following parameters:
Q:什么是`YOUR_RESOURCE_ID`,`YOUR_MODEL_DEPLOYMENT`,`YOUR_API_KEY`

- `messages`: An array of message objects containing `content` and `role` properties. The `content` represents the text input, and the `role` can be one of the following options: `'system'`, `'user'`, or `'assistant'`.
- `temperature`: Controls the randomness of generated completions. Higher values (e.g., 1) result in more random responses, while lower values (e.g., 0.1) produce more focused and deterministic responses.
- `model`: Specifies the AI model to be used for generating completions. In the example, it is set to `'gpt-3.5-turbo'`.
- `stream`: A boolean value indicating whether the response should be streamed.
A: 可以在Azure的管理门户里查找,具体见下图标注

## License
![resource-and-model](./resource-and-model.jpg)

This project is licensed under the MIT License. See the [LICENSE](https://choosealicense.com/licenses/mit/) file for details.
Q: 如何支持GPT-4

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

Contributions to Azure-OpenAI-Proxy are greatly appreciated. To contribute, follow these steps:
`YOUR_RESOURCE_ID:gpt-3.5-turbo|YOUR_MODEL_DEPLOYMENT,gpt-4|YOUR_MODEL_DEPLOYMENT,gpt-4-32k|YOUR_MODEL_DEPLOYMENT:YOUR_API_KEY`

1. Fork the repository and create your branch.
2. Make changes or additions to the code.
3. Commit your changes and raise a Pull Request.
# 贡献代码方式

Please make sure to follow the project's coding standards and update documentation accordingly.
欢迎提交各种PR。

For further information, check the [OpenAI API documentation](https://platform.openai.com/docs/api-reference/completions/create).
# 免责声明

Thank you for your interest in contributing to Azure-OpenAI-Proxy. Your efforts will help improve the project and benefit the community.
此代码仅供演示和测试目的。
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.8'

services:
gptlite:
image: blrchen/gptlite:main
ports:
- 3000:3000
environment:
OPENAI_API_KEY: ${OPENAI_API_KEY}
OPENAI_API_BASE_URL: http://azure-openai:3000
depends_on:
- azure-openai
networks:
- network

azure-openai:
build:
context: .
networks:
- network
restart: unless-stopped

networks:
network:
driver: bridge
Binary file added resource-and-model.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d9fc957

Please sign in to comment.