mirror of
https://github.com/stulzq/azure-openai-proxy.git
synced 2025-12-24 01:34:27 +01:00
116 lines
3.6 KiB
Markdown
116 lines
3.6 KiB
Markdown
# azure-openai-proxy
|
|
Azure OpenAI Service Proxy. Convert Azure OpenAI API(aoai) to the official OpenAI API(oai) standard.
|
|
|
|
## Get Start
|
|
|
|
### Retrieve key and endpoint
|
|
|
|
To successfully make a call against Azure OpenAI, you'll need the following:
|
|
|
|
| Name | Desc | Example |
|
|
| --------------------- | ------------------------------------------------------------ | ----------------------------- |
|
|
| AZURE_OPENAI_ENDPOINT | This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. Alternatively, you can find the value in **Azure OpenAI Studio** > **Playground** > **Code View**. An example endpoint is: `https://docs-test-001.openai.azure.com/`. | https://test.openai.azure.com |
|
|
| AZURE_OPENAI_API_VER | [See here](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quickstart?tabs=command-line&pivots=rest-api) or Azure OpenAI Studio | 2023-03-15-preview |
|
|
| AZURE_OPENAI_DEPLOY | This value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under **Resource Management** > **Deployments** in the Azure portal or alternatively under **Management** > **Deployments** in Azure OpenAI Studio. | gpt-35-turbo |
|
|
|
|

|
|
|
|
API Key: This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.
|
|
|
|
> Use api key when call http api like Offical OpenAI.
|
|
|
|
### Use Docker
|
|
|
|
````shell
|
|
docker run -d -p 8080:8080 --name=azure-openai-proxy \
|
|
--env AZURE_OPENAI_ENDPOINT=your_azure_endpoint \
|
|
--env AZURE_OPENAI_API_VER=your_azure_api_ver \
|
|
--env AZURE_OPENAI_DEPLOY=your_azure_deploy \
|
|
stulzq/azure-openai-proxy:latest
|
|
````
|
|
|
|
Call API:
|
|
|
|
````shell
|
|
curl --location --request POST 'localhost:8080/v1/chat/completions' \
|
|
-H 'Authorization: Bearer <Azure OpenAI Key>' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"max_tokens": 1000,
|
|
"model": "gpt-3.5-turbo",
|
|
"temperature": 0.8,
|
|
"top_p": 1,
|
|
"presence_penalty": 1,
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content": "Hello"
|
|
}
|
|
],
|
|
"stream": true
|
|
}'
|
|
````
|
|
|
|
### Use ChatGPT-Web
|
|
|
|
ChatGPT Web: https://github.com/Chanzhaoyu/chatgpt-web
|
|
|
|

|
|
|
|
Envs:
|
|
|
|
- `OPENAI_API_KEY` Auzre OpenAI API Key
|
|
- `AZURE_OPENAI_ENDPOINT` Auzre OpenAI API Endpoint
|
|
- `AZURE_OPENAI_DEPLOY` Auzre OpenAI API Deployment
|
|
|
|
docker-compose.yml:
|
|
|
|
````yaml
|
|
version: '3'
|
|
|
|
services:
|
|
chatgpt-web:
|
|
image: chenzhaoyu94/chatgpt-web
|
|
ports:
|
|
- 3002:3002
|
|
environment:
|
|
OPENAI_API_KEY: <Auzre OpenAI API Key>
|
|
OPENAI_API_BASE_URL: http://azure-openai:8080
|
|
AUTH_SECRET_KEY: ""
|
|
MAX_REQUEST_PER_HOUR: 1000
|
|
TIMEOUT_MS: 60000
|
|
depends_on:
|
|
- azure-openai
|
|
links:
|
|
- azure-openai
|
|
networks:
|
|
- chatgpt-ns
|
|
|
|
azure-openai:
|
|
image: stulzq/azure-openai-proxy
|
|
ports:
|
|
- 8080:8080
|
|
environment:
|
|
AZURE_OPENAI_ENDPOINT: <Auzre OpenAI API Endpoint>
|
|
AZURE_OPENAI_DEPLOY: <Auzre OpenAI API Deployment>
|
|
AZURE_OPENAI_API_VER: 2023-03-15-preview
|
|
networks:
|
|
- chatgpt-ns
|
|
|
|
networks:
|
|
chatgpt-ns:
|
|
driver: bridge
|
|
````
|
|
|
|
Run:
|
|
|
|
````shell
|
|
docker compose up -d
|
|
````
|
|
|
|
## Proxy Api
|
|
|
|
| Api | Status |
|
|
| -------------------- | ------ |
|
|
| /v1/chat/completions | Ok |
|