Skip to content

Commit 9b53f96

Browse files
committed
使用高性能json序列化
1 parent d7fa9d3 commit 9b53f96

File tree

3 files changed

+87
-56
lines changed

3 files changed

+87
-56
lines changed

README.md

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
3. 重新适配了vllm对模型适配较差,导致解码内容和hf不对齐的问题。
2020
4. 支持了**vllm****LMDeploy****hf**的加载方式
2121
5. 支持所有兼容sentence_transformers的语义向量模型(Embedding和Reranker)
22-
6. 支持了OpenAI接口规范的文本审核模型(text-moderation)
23-
7. 支持了Infinity后端,推理速度大于onnx/tensorrt,支持动态组批
24-
8. 支持guided_decoding,强制模型按照Schema的要求进行JSON格式输出。
25-
9. Chat模板无角色限制,使其完美支持了**LangGraph Agent**框架
26-
10. 支持多模态大模型
27-
11. **降低了模型适配的难度和项目使用的难度**(新模型的适配仅需修改低于5行代码),从而更容易的部署自己最新的模型。
22+
6. 支持了OpenAI接口规范的文本审核模型(text-moderation,/v1/moderations)
23+
7. 支持了OpenAI接口规范的TTS模型(tts,/v1/audio/speech),自带edge-tts(免费的TTS)
24+
8. 支持了Infinity后端,推理速度大于onnx/tensorrt,支持动态组批
25+
9. 支持guided_decoding,强制模型按照Schema的要求进行JSON格式输出。
26+
10. Chat模板无角色限制,使其完美支持了**LangGraph Agent**框架
27+
11. 支持多模态大模型
28+
12. **降低了模型适配的难度和项目使用的难度**(新模型的适配仅需修改低于5行代码),从而更容易的部署自己最新的模型。
2829

2930
(仓库初步构建中,构建过程中没有经过完善的回归测试,可能会发生已适配的模型不可用的Bug,欢迎提出改进或者适配模型的建议意见。)
3031

@@ -37,15 +38,17 @@
3738
2. 支持了Infinity后端,推理速度大于onnx/tensorrt,支持动态组批
3839
3. 全球唯一完美支持**Tools(Function Calling)**功能的开源框架。兼容**LangChain****bind_tools****AgentExecutor****with_structured_output**写法(目前支持Qwen系列、GLM系列)
3940
4. 支持了**cohere**库接口规范的 /v1/rerank 接口
40-
5. 全球唯一扩展了**openai**库,实现Reranker模型。(代码样例见gpt_server/tests/test_openai_rerank.py)
41-
6. 全球唯一支持了**openai**库的文本审核模型接口(text-moderation)。(代码样例见gpt_server/tests/test_openai_moderation.py)
42-
7. 支持多模态大模型
43-
8. 与FastChat相同的分布式架构
41+
5. 全球唯一扩展了**openai**库,实现Reranker模型(rerank, /v1/rerank)。(代码样例见gpt_server/tests/test_openai_rerank.py)
42+
6. 全球唯一支持了**openai**库的文本审核模型接口(text-moderation, /v1/moderations)。(代码样例见gpt_server/tests/test_openai_moderation.py)
43+
7. 全球唯一支持了**openai**库的文本审核模型接口(tts, /v1/audio/speech),自带edge-tts(免费的TTS)(代码样例见gpt_server/tests/test_openai_tts.py)
44+
8. 支持多模态大模型
45+
9. 与FastChat相同的分布式架构
4446

4547
## 更新信息
4648

4749
```plaintext
48-
2024-12-21 支持了 text-moderation 文本审核模型
50+
2024-12-22 支持了 tts, /v1/audio/speech TTS模型
51+
2024-12-21 支持了 text-moderation, /v1/moderations 文本审核模型
4952
2024-12-14 支持了 phi-4
5053
2024-12-7 支持了 /v1/rerank 接口
5154
2024-12-1 支持了 QWQ-32B-Preview
@@ -168,30 +171,30 @@ streamlit run server_ui.py
168171

169172
### **LLM**
170173

171-
| Models / BackEnd |model_type | HF | vllm | LMDeploy TurboMind | LMDeploy PyTorch |
172-
| :--------------------: |:-: | :-: | :--: | :----------------: | :--------------: |
173-
| chatglm4-9b |chatglm |||||
174-
| chatglm3-6b |chatglm ||| × ||
175-
| Qwen (7B, 14B, etc.)) |qwen |||||
176-
| Qwen-1.5 (0.5B--72B) |qwen|||||
177-
| Qwen-2 |qwen|||||
178-
| Qwen-2.5 |qwen|||||
179-
| Yi-34B |yi|||||
180-
| Internlm-1.0 |internlm|||||
181-
| Internlm-2.0 |internlm|||||
182-
| Deepseek |deepseek|||||
183-
| Llama-3 |llama|||||
184-
| Baichuan-2 |baichuan|||||
185-
| QWQ-32B-Preview |qwen|||||
186-
| Phi-4 |phi||| × | × |
174+
| Models / BackEnd | model_type | HF | vllm | LMDeploy TurboMind | LMDeploy PyTorch |
175+
| :-------------------: | :--------: | :---: | :---: | :----------------: | :--------------: |
176+
| chatglm4-9b | chatglm || | | |
177+
| chatglm3-6b | chatglm || | × | |
178+
| Qwen (7B, 14B, etc.)) | qwen || | | |
179+
| Qwen-1.5 (0.5B--72B) | qwen || | | |
180+
| Qwen-2 | qwen || | | |
181+
| Qwen-2.5 | qwen || | | |
182+
| Yi-34B | yi || | | |
183+
| Internlm-1.0 | internlm || | | |
184+
| Internlm-2.0 | internlm || | | |
185+
| Deepseek | deepseek || | | |
186+
| Llama-3 | llama || | | |
187+
| Baichuan-2 | baichuan || | | |
188+
| QWQ-32B-Preview | qwen || | | |
189+
| Phi-4 | phi || | × | × |
187190
### **VLM** (视觉大模型榜单 https://rank.opencompass.org.cn/leaderboard-multimodal)
188191

189-
| Models / BackEnd |model_type| HF | vllm | LMDeploy TurboMind | LMDeploy PyTorch |
190-
| :--------------: | :-: | :-: | :--: | :----------------: | :--------------: |
191-
| glm-4v-9b |chatglm| × | × | × ||
192-
| InternVL2 |internvl2| × | × |||
193-
| MiniCPM-V-2_6 |minicpmv | × ||| × |
194-
| Qwen2-VL |qwen | × || × ||
192+
| Models / BackEnd | model_type | HF | vllm | LMDeploy TurboMind | LMDeploy PyTorch |
193+
| :--------------: | :--------: | :---: | :---: | :----------------: | :--------------: |
194+
| glm-4v-9b | chatglm | × | × | × | |
195+
| InternVL2 | internvl2 | × | × | | |
196+
| MiniCPM-V-2_6 | minicpmv | × | | | × |
197+
| Qwen2-VL | qwen | × | | × | |
195198
<br>
196199

197200
### Embedding/Rerank/Classify模型
@@ -202,21 +205,21 @@ streamlit run server_ui.py
202205

203206
以下模型经过测试可放心使用:
204207

205-
| Embedding/Rerank/Classify | HF | Infinity |
206-
| ------------------------- | -- | -------- |
207-
| bge-reranker |||
208-
| bce-reranker |||
209-
| bge-embedding |||
210-
| bce-embedding |||
211-
|puff |||
212-
| piccolo-base-zh-embedding |||
213-
| acge_text_embedding |||
214-
| Yinka |||
215-
| zpoint_large_embedding_zh |||
216-
| xiaobu-embedding |||
217-
|Conan-embedding-v1 |||
218-
|KoalaAI/Text-Moderation | × ||
219-
|protectai/deberta-v3-base-prompt-injection-v2| × ||
208+
| Embedding/Rerank/Classify | HF | Infinity |
209+
| --------------------------------------------- | --- | -------- |
210+
| bge-reranker | | |
211+
| bce-reranker | | |
212+
| bge-embedding | | |
213+
| bce-embedding | | |
214+
| puff | | |
215+
| piccolo-base-zh-embedding | | |
216+
| acge_text_embedding | | |
217+
| Yinka | | |
218+
| zpoint_large_embedding_zh | | |
219+
| xiaobu-embedding | | |
220+
| Conan-embedding-v1 | | |
221+
| KoalaAI/Text-Moderation(文本审核/多分类,审核文本是否存在暴力、色情等) | × | |
222+
| protectai/deberta-v3-base-prompt-injection-v2(提示注入/2分类,审核文本为提示注入) | × | |
220223

221224
目前 TencentBAC的 **Conan-embedding-v1** C-MTEB榜单排行第一(MTEB: https://huggingface.co/spaces/mteb/leaderboard)
222225

gpt_server/serving/openai_api_server.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import aiohttp
1818
import fastapi
19-
from fastapi import Depends, HTTPException
19+
from fastapi import Depends, HTTPException, responses
2020
from fastapi.exceptions import RequestValidationError
2121
from fastapi.middleware.cors import CORSMiddleware
2222
from fastapi.responses import StreamingResponse, JSONResponse, FileResponse
@@ -362,7 +362,11 @@ async def get_conv(model_name: str, worker_addr: str):
362362
from gpt_server.openai_api_protocol.custom_api_protocol import CustomModelCard
363363

364364

365-
@app.get("/v1/models", dependencies=[Depends(check_api_key)])
365+
@app.get(
366+
"/v1/models",
367+
dependencies=[Depends(check_api_key)],
368+
response_class=responses.ORJSONResponse,
369+
)
366370
async def show_available_models():
367371
controller_address = app_settings.controller_address
368372
ret = await fetch_remote(controller_address + "/refresh_all_workers")
@@ -386,7 +390,11 @@ async def show_available_models():
386390
)
387391

388392

389-
@app.post("/v1/chat/completions", dependencies=[Depends(check_api_key)])
393+
@app.post(
394+
"/v1/chat/completions",
395+
dependencies=[Depends(check_api_key)],
396+
response_class=responses.ORJSONResponse,
397+
)
390398
async def create_chat_completion(request: CustomChatCompletionRequest):
391399
"""Creates a completion for the chat message"""
392400
error_check_ret = await check_model(request)
@@ -531,7 +539,11 @@ async def chat_completion_stream_generator(
531539
yield "data: [DONE]\n\n"
532540

533541

534-
@app.post("/v1/completions", dependencies=[Depends(check_api_key)])
542+
@app.post(
543+
"/v1/completions",
544+
dependencies=[Depends(check_api_key)],
545+
response_class=responses.ORJSONResponse,
546+
)
535547
async def create_completion(request: CompletionRequest):
536548
error_check_ret = await check_model(request)
537549
if error_check_ret is not None:
@@ -732,7 +744,11 @@ async def speech(request: SpeechRequest):
732744
return FileResponse(output_path, media_type="audio/mpeg", filename=filename)
733745

734746

735-
@app.post("/v1/moderations", dependencies=[Depends(check_api_key)])
747+
@app.post(
748+
"/v1/moderations",
749+
dependencies=[Depends(check_api_key)],
750+
response_class=responses.ORJSONResponse,
751+
)
736752
async def classify(request: ModerationsRequest):
737753
error_check_ret = await check_model(request)
738754
if error_check_ret is not None:
@@ -770,7 +786,11 @@ async def classify(request: ModerationsRequest):
770786
}
771787

772788

773-
@app.post("/v1/rerank", dependencies=[Depends(check_api_key)])
789+
@app.post(
790+
"/v1/rerank",
791+
dependencies=[Depends(check_api_key)],
792+
response_class=responses.ORJSONResponse,
793+
)
774794
async def rerank(request: RerankRequest):
775795
error_check_ret = await check_model(request)
776796
if error_check_ret is not None:
@@ -809,8 +829,16 @@ async def rerank(request: RerankRequest):
809829
return {"results": results, "id": shortuuid.random()}
810830

811831

812-
@app.post("/v1/embeddings", dependencies=[Depends(check_api_key)])
813-
@app.post("/v1/engines/{model_name}/embeddings", dependencies=[Depends(check_api_key)])
832+
@app.post(
833+
"/v1/embeddings",
834+
dependencies=[Depends(check_api_key)],
835+
response_class=responses.ORJSONResponse,
836+
)
837+
@app.post(
838+
"/v1/engines/{model_name}/embeddings",
839+
dependencies=[Depends(check_api_key)],
840+
response_class=responses.ORJSONResponse,
841+
)
814842
async def create_embeddings(request: CustomEmbeddingsRequest, model_name: str = None):
815843
"""Creates embeddings for the text"""
816844
if request.model is None:

0 commit comments

Comments
 (0)