01 / 检查 Python 并创建独立环境
项目要求 Python 3.10 或更新版本。独立虚拟环境可以避免与其他项目依赖互相影响。
SHELL / 本地环境
python3 -m venv .venv
source .venv/bin/activate02 / 用 pip 安装 Laya
SHELL / 本地环境
python -m pip install laya安装失败时检查原仓库的平台说明,并确认 pip 和脚本使用同一个解释器。首次使用可能下载权重,需要网络、存储空间和更长的首次请求时间。
03 / 运行本地分类示例
将下方代码保存为 first_decision.py,再执行 python first_decision.py。示例沿用官方 Router 接口,保留英文输入以匹配原示例任务。
PYTHON / 本地示例
from laya import Router
router = Router()
questions = {
"queue": {
"type": "choice",
"instructions": "Which team should handle this message?",
"criteria": {
"billing": "Charges, invoices, and refunds",
"technical": "Bugs, errors, and outages",
"other": "Anything else",
},
}
}
result = router.predict("I was charged twice.", questions)
print(result["answers"]["queue"]["choice"])代码打印选中的标签。此例预期为 billing,但不能保证模型每次都正确。
04 / 用边界输入检查标签定义
- “My invoice page shows an error.” 发票页面出错,应归财务还是技术?
- “Thanks, everything works now.” 感谢消息是否进入 other?
- “I need a refund and I cannot sign in.” 多意图消息用单个标签是否足够?
先写下预期答案,再检查分歧。这既是在测模型,也是在测任务定义。
接入实际请求前
记录软件包和检查点版本,测量内存,设置失败处理。如果开放服务接口,还需配置认证、输入限制和监控。
来源与核查说明
资料核查日期:2026 年 9 月 27 日。本站未重新执行模型推理;引用的测试结果属于原作者,产品文档可能继续更新。
- Laya 官方仓库 — Python 要求、安装命令及 Router 接口