AidGenSE API
💡注意
该版本是 AidGenSE 的一个临时版本,下一个发布的版本是正式版,接口调用方式会有细微改动,使用案例也会更丰富
所有api都支持两个请求地址,一个带了api版本号,一个是默认api请求地址。
例如下面两个接口访问了同样的功能:
GET /v1/models HTTP/1.1
GET /models HTTP/1.1
1 异常访问
1.1 所有非实现访问
Response 403
Not support method or endpoint, Please check your request.
特别注意:在V0.10A版本中,当--device是cpu/gpu时,未对请求进行拦截,因此不会有如上信息。
1.2 设备未激活
在此状态下,所有接口返回如下Response
{
"status": "error",
"msg": "This device has not been activated, please contact aplux."
}
设备未激活相关信息请参考UserGuide文档。
特别注意:在V0.10A版本中,当--device是cpu/gpu时,不校验设备是否激活,因此不会有如上信息。
2 模型相关
2.1 查询可用模型
💡注意
此 API 非 OpenAI 适配接口
api参考: https://platform.openai.com/docs/api-reference/models/list
Request
GET /v1/models HTTP/1.1
Ok Response
{
"object": "list",
"loaded_id":"aplux_qwen2_7b",
"data": [
{
"id": "aplux_qwen2_0-5b",
"created": "1733304878498",
"owned_by": "aplux",
"object": "model"
},
{
"id": "aplux_qwen2_1-5b",
"created": "1733304878498",
"owned_by": "aplux",
"object": "model"
},
{
"id": "aplux_qwen2_7b",
"created": "1733304878498",
"owned_by": "aplux",
"object": "model"
},
{
"model_id":"aplux_qwen2-5_3b",
"model_create":"1736215538226",
"model_owner":"aplux",
"cfg_path":"./res/qwen2.5-3b-htp.json"
}
]
}
2.2 切换模型
💡注意
此 API 非 OpenAI 适配接口
Request
GET /v1/models/switch/model_id HTTP/1.1
Ok Response
{
"id": "aplux_qwen2_7b",
"object": "model"
}
Error Response
{
"error": {
"message": "Model does not exist or the switch is wrong",
"type": "invalid_request_error",
"param": null,
"code": "aplux_qwen2_71b"
}
}
注意,不要频繁切换模型,否则会导致api发生模型加载错误而退出。
特别注意:在V0.10A版本中,当--device是cpu/gpu时,当前后端只输入了一个模型的信息,因此不支持/v1/models/switch api。
3 聊天相关
3.1 创建聊天
api参考: https://platform.openai.com/docs/api-reference/chat/create
No-Stream Request (返回chat completion object)
POST /v1/chat/completions HTTP/1.1
Content-Type: application/json
{
"model": "aplux_qwen2_7b",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "给我写一个python打印hello world的例子"
}
]
}
Stream Request (返回chat completion chunk object)
POST /v1/chat/completions HTTP/1.1
Content-Type: application/json
{
"model": "aplux_qwen2_7b",
"messages": [
{
"role": "user",
"content": "给我写一个python打印hello world的例子"
}
],
"stream": true
}
Ok Response (For No-Stream Chat)
{
"id": "chatcmpl-sV1IqqE1ONeyBDGw9aak0JSxBLcwHjRl",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "当然,下面是一个简单的Python程序,用于打印\"Hello World!\"。\n\n```python\nprint(\"Hello World!\")\n```\n\n只需将上述代码复制到Python环境中并运行,即可看到\"Hello World!\"被打印出来。",
"role": "assistant",
"refusal": null
},
"logprobs": null
}
],
"created": 1733364801,
"model": "aplux_qwen2_7b",
"object": "chat.completion",
"usage": {
"completion_tokens": 46,
"prompt_tokens": 0,
"total_tokens": 46
},
"system_fingerprint": "fp_nj0KZoURMe3zP90dZWUjjIJZvNIOt8Fn"
}
Ok Response (For Stream Chat)
data: {"choices":[{"finish_reason":null,"index":0,"delta":{"role":"assistant"}}],"created":1733364537,"id":"chatcmpl-wuwZhLmQDyfcX6YAUSC7xL5pcZDDkOb1","model":"aplux_qwen2_7b","object":"chat.completion.chunk"}
data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"当然"}}],"created":1733364537,"id":"chatcmpl-wuwZhLmQDyfcX6YAUSC7xL5pcZDDkOb1","model":"aplux_qwen2_7b","object":"chat.completion.chunk"}
....
data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"出来"}}],"created":1733364543,"id":"chatcmpl-wuwZhLmQDyfcX6YAUSC7xL5pcZDDkOb1","model":"aplux_qwen2_7b","object":"chat.completion.chunk","system_fingerprint":"fp_Oy1cNzDki9Qgiyuv01gkzXtqPkzbQvfU"}
data: {"choices":[{"finish_reason":null,"index":0,"delta":{"content":"。"}}],"created":1733364543,"id":"chatcmpl-wuwZhLmQDyfcX6YAUSC7xL5pcZDDkOb1","model":"aplux_qwen2_7b","object":"chat.completion.chunk","system_fingerprint":"fp_5BAbMptvnugjLMsCfaum4x6Vfx5jhpLT"}
data: {"choices":[{"finish_reason":"stop","index":0,"delta":{}}],"created":1733364543,"id":"chatcmpl-wuwZhLmQDyfcX6YAUSC7xL5pcZDDkOb1","model":"aplux_qwen2_7b","object":"chat.completion.chunk","system_fingerprint":"fp_ciYnF3vTj3fV38yX0wuhZUbJZfQIe0tE","usage":{"completion_tokens":46,"prompt_tokens":0,"total_tokens":46}}
data: [DONE]
Error Response
{
"error": {
"code": 400,
"message": "request model(aplux_qwen2_71b) is not available.",
"type": "invalid_request_error"
}
}
{
"error": {
"code": 400,
"message": "request model(aplux_qwen2_1-5b) is not loaded, please switch model",
"type": "invalid_request_error"
}
}
3.2 停止当前对话
💡注意
此 API 非 OpenAI 适配接口
Request
POST /v1/chat/completed HTTP/1.1
Content-Type: application/json
{
"chat_id": "chatcmpl-sV1IqqE1ONeyBDGw9aak0JSxBLcwHjRl"
}
Ok Response
{
"status":"ok",
"msg":""
}
Error Response
{
"status": "error",
"msg": "the chat_id = chatcmpl-sV1IqqE1ONeyBDGw9aak0JSxBLcwHjRl not found"
}