This is a simple web server for calling OpenAI APIs, designed for PKU software course (aka. 软件设计实践) mid-term project.
Warning: The project is finished in a hurry, filled with awful practices.
DO NOT LEARN FROM IT.
git clone https://github.com/pku-software/ai-api-server.git
cd ai-api-server
cargo build --release
See the help message for more information. The config.toml is needed, otherwise the server will not start.
ai-api-server -b 0.0.0.0:4399 --debug
You can configure the server by editing the config.toml
file.
A token is needed for all requests. You should put the token in the Authorization
header using the Bearer
scheme.
For example, if your token is dGVzdA==
, just put it in your header.
Authorization: Bearer dGVzdA==
If the token is invalid, the server will return a 401 Unauthorized
response.
Translate text from one language to another.
{
"text": "Hello world!",
"from": "en",
"to": "zh"
}
{
"status": "ok",
"text": "你好,世界!"
}
Example JSON:
{
"status": "failed",
"text": "Invalid language code"
}
Interact with a chatbot. You should provide a prompt for the chatbot to generate a completition.
{
"prompt": "Hello, I am a chatbot. How are you?",
}
{
"status": "ok",
"text": "Hello, I am a chatbot. How are you? I am fine. How are you?"
}
{
"status": "failed",
"text": "Network error!"
}
Draw a picture. You should provide a prompt for the model to generate a completition.
{
"prompt": "Apple",
"kind": "1"
}
Valid kind: 1, 2, 3
- 1: 256x256
- 2: 512x512
- 3: 1024x1024
Return a base64 encoded image.
{
"status": "ok",
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAA"
}
{
"status": "failed",
"text": "Network error!"
}
Ask a question to wolfram alpha, return the answer as a picture.
{
"input": "What is the capital of China?"
}
Return a base64 encoded image.
{
"status": "ok",
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAA"
}
{
"status": "failed",
"text": "Network error!"
}