LitServe 快速部署类openai 接口服务
以前简单说明过LitServe 支持openai 接口格式的服务api,以下是一个简单试用
参考代码
- app.py
import litserve as ls
class SimpleLitAPI(ls.LitAPI):
def setup(self, device):
self.model = None
def predict(self, prompt):
# `prompt` is a list of dictionary containing role and content
# example: [{'role': 'user', 'content': 'How can I help you today?'}]
yield "This is a sample generated output"
if __name__ == "__main__":
# Enable the OpenAISpec in LitServer
api = SimpleLitAPI()
server = ls.LitServer(api, spec=ls.OpenAISpec())
server.run(port=8000)
- 运行效果
- 接口调用
curl -X 'POST' \
'http://0.0.0.0:8000/v1/chat/completions' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"model": "",
"messages": [
{
"role": "user",
"content": "demo"
}
]
}'
- stream 模式
import litserve as ls
class SimpleLitAPI(ls.LitAPI):
def setup(self, device):
self.model = None
def predict(self, prompt):
# 基于生成器进行数据生成
for chunk in "This is a sample generated output".split():
yield chunk
if __name__ == "__main__":
api = SimpleLitAPI()
server = ls.LitServer(api, spec=ls.OpenAISpec())
server.run(port=8000)
说明
基于LitServe快速开发ai 推理服务接口还是很方便的,快速、简单,让我们将核心能力放到业务处理上
参考资料
https://lightning.ai/docs/litserve/features/open-ai-spec
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· spring官宣接入deepseek,真的太香了~
2023-11-08 cmake 进行rpm包构建
2022-11-08 go-npm 基于npm 进行跨平台分发golang 二进制程序
2022-11-08 grafana agent 动态配置内部机制简单说明
2022-11-08 minio 一些配置策略
2022-11-08 minio policy 使用
2020-11-08 kotlin 学习 三 maven 集成+java 互调用
2020-11-08 kotlin 学习 二 命令行模式运行