A simple RESTful API of GPT-4 / ChatGPT with Azure OpenAI Service, build with TypeScript and Node.js Express
- Base on Azure OpenAI Service REST API
- One endpoint for simple usage
- Flexible and easily extensible for future development
- Logit bias & function call are not supported yet
- RESTful API structure
- Ready for use with PM2
- Build with TypeScript, Node.js, Express
Config Name | Required? | Default Value | Description |
---|---|---|---|
HTTP_PORT | ✔️ | 80 | The HTTP port number of API |
HTTPS_PORT | ✅ | 443 | The HTTPS port number of API (if ENABLE_SSL=true) |
ENABLE_SSL | ✅ | false | Use HTTPS or not |
SSL_CERT | ✅ | N/A | The SSL certificate file path (if ENABLE_SSL=true) |
SSL_KEY | ✅ | N/A | The SSL private key file path (if ENABLE_SSL=true) |
ENDPOINT | ✔️ | N/A | The Azure OpenAI Service endpoint URL |
DEPLOYMENT_NAME | ✔️ | N/A | The deployment name of Azure OpenAI Service |
API_VERSION | ✔️ | N/A | The API version of Azure OpenAI Service |
KEY | ✔️ | N/A | The API key for accessing the Azure OpenAI Service |
temperature | ❌ | 1 (A) | The default sampling temperature value for GPT model output |
top_p | ❌ | N/A | The default top_p value for GPT model output |
n | ❌ | 1 (A) | The default number of chat completion choices to generate for GPT model output |
stream | ❌ | false (A) | The default boolean value indicating whether to stream GPT model output |
stop | ❌ | null (A) | The default sequences where the GPT model stop output |
max_tokens | ❌ | inf (A) | The default maximum number of tokens allowed for GPT model output |
presence_penalty | ❌ | 0 (A) | The default presence penalty number for GPT model output |
frequency_penalty | ❌ | 0 (A) | The default frequency penalty number for GPT model output |
user | ❌ | N/A | The unique identifier of user for Azure OpenAI |
*(A): Azure OpenAI Default value (may be changed by Azure OpenAI Service)
**For the details of GPT options, you may refer to the API doc below or the Official document
- Request Method:
POST
- API Endpoint:
/v1/gpt/chat
Only prompt/userPrompt is required, all other params are optional.
Param Name | Type | Default Value | Description |
---|---|---|---|
prompt |
string | N/A | Alias of userPrompt |
userPrompt |
string | N/A | User prompt input for chat completions |
systemPrompt |
string | N/A | System prompt to instruct or set the behavior of the assistant |
assistantPrompt |
string | N/A | Assistant prompt provides responses to system-instructed, user-prompted input |
temperature |
number | 1 (A) | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.\nWe generally recommend altering this or top_p but not both. |
top_p |
number | 1 (A) | An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both. |
n |
integer | 1 (A) | How many chat completion choices to generate for each input message. |
stream |
boolean | false (A) | If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message." |
stop |
string / array | null (A) | Up to 4 sequences where the API will stop generating further tokens. |
max_tokens |
integer | inf (A) | The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens). |
presence_penalty |
number | 0 (A) | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. |
frequency_penalty |
number | 0 (A) | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. |
user |
string | N/A | A unique identifier representing your end-user, which can help Azure OpenAI to monitor and detect abuse. |
- You must have enabled the Azure AI services - Azure OpenAI of your Azure account first
git clone https://github.com/jasonfoknxu/azure-openai-chatgpt-api
to download the source codeyarn
ornpm install
to install all the dependencies- Copy the
sample.env
file and rename as.env
- Edit the config in the
.env
file yarn run build
ornpm run build
to compile the scriptsyarn start
ornpm start
to start the API server
https://learn.microsoft.com/en-us/azure/ai-services/openai/reference