LLMER必会技能:一行代码将任意python函数部署成http服务

LLMER必会技能:一行代码将任意python函数部署成http服务

LLMER: 一个化繁为简的大模型(LLM)应用开发者神器

llmer 是一个轻量级的 Python 库,旨在简化大型语言模型(LLMs)应用中的复杂过程。它提供了用于并行处理、运行时管理、文件处理和Prompt格式化等常用的高级 API 和实用工具,从而不用每次都需要重复开发相关代码,简化工作。

更多关于LLMER工具的详细功能,阅读原文

Notice: LLMER增加新功能,任意python函数,只需一行代码即可部署成FastAPI服务

一行代码帮你搞定 FastAPI 服务部署

LLMER 工具包 @deploy(host, port) 装饰器能快速便捷将任意函数部署成FastAPI服务。

安装LLMER

shell 复制代码
pip install llmer

使用举例:

在任意函数前加上装饰器@deploy(host=, port=),即可立即部署成FastAPI服务。

然后可通过 <函数名>.serve() 启动服务。

目前支持普通函数、异步函数、流式函数(生成器)、异步流式函数(异步生成器)

python 复制代码
from llmer.server import deploy
import time
import asyncio

# 普通服务
@deploy(host="127.0.0.1", port=9510)
def add(a: int, b: int):
    return a + b
# add.serve()

# 异步服务
@deploy(host="127.0.0.1", port=9510)
async def async_add(a: int, b: int):
    return a + b
# async_add.serve()

# 流式服务
@deploy(host="127.0.0.1", port=9511)
def stream_numbers(start: int, end: int):
    for i in range(start, end + 1):
        time.sleep(1)
        yield f'{{"number": {i}}}'
# stream_numbers.serve()

# 异步流式服务
@deploy(host="127.0.0.1", port=9511)
async def async_stream_numbers(start: int, end: int):
    for i in range(start, end + 1):
        await asyncio.sleep(1)
        yield {"number": i}
# async_stream_numbers.serve()

以最后一个异步流式服务为例,通过 async_stream_numbers.serve() 启动后

shell 复制代码
INFO:     Started server process [26081]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:9511 (Press CTRL+C to quit)

调用举例

shell 复制代码
curl -X POST "http://127.0.0.1:9511/async_stream_numbers" \
    -H "Content-Type: application/json" \
    -d '{"start": 1, "end": 5}'

流式输出

text 复制代码
data: {'number': 1}
data: {'number': 2}
data: {'number': 3}
data: {'number': 4}
data: {'number': 5}

更多关于LLMER工具的详细功能,快来阅读原文

相关推荐
装不满的克莱因瓶6 分钟前
掌握语义分割经典模型 FCN——从像素分类到端到端分割的奠基之作
人工智能·python·深度学习·算法·机器学习·分类·数据挖掘
学计算机的计算基11 分钟前
链表算法上篇:LeetCode 206/234/141/142/160/21 题解与易错点
java·笔记·算法·链表
大白话_NOI15 分钟前
【洛谷 P2678】 [NOIP2015 提高组] 跳石头 超详细题解
c++·算法
xwz小王子18 分钟前
ICRA 2026深度观察:全栈闭环成标配,中国具身智能势力显著崛起
大数据·人工智能·算法
孬甭_19 分钟前
深入解析归并排序:稳定高效的分治典范
算法·排序算法
DXM052127 分钟前
第14期|高阶分割模型:Transformer/SegFormer遥感应用
人工智能·python·神经网络·算法·计算机视觉·cnn·ageo
Kurisu_红莉栖1 小时前
前缀和的另外一种用法,前缀和分解
算法
88号技师1 小时前
2026年2月一区SCI-交叉传播优化算法Propagation Alongside Crossover-附Matlab免费代码
开发语言·算法·数学建模·matlab·优化算法
悠仁さん1 小时前
数据结构 图(代码实现篇 C语言版)
数据结构·算法·图论
aini_lovee1 小时前
多智能体粒子群优化(Multi-Agent Particle Swarm Optimization, MAPSO)
算法