Langfuse 速查表
Langfuse 是开源的 LLM 可观测性平台,提供 trace/span 追踪、token 用量统计、评分评估、prompt 版本管理、数据集管理等功能。支持自托管和云服务,与 LangChain、OpenAI 等框架深度集成。
更新: 2026-07-20·14 条命令
快速开始
``bash
pip install langfuse
export LANGFUSE_PUBLIC_KEY=pk-lf-xxx
export LANGFUSE_SECRET_KEY=sk-lf-xxx
export LANGFUSE_HOST=https://cloud.langfuse.com
``
启动模式(12)
| 命令 | 难度 | ||
|---|---|---|---|
langfuse --help显示 Langfuse CLI 帮助 | 基础 | langfuse --help | |
pip install langfuse安装 Langfuse Python SDK | 基础 | pip install langfuse | |
git clone langfuse克隆 Langfuse 源码 | 基础 | git clone https://github.com/langfuse/langfuse.git | |
export LANGFUSE_PUBLIC_KEY设置 Langfuse 公钥 | 基础 | export LANGFUSE_PUBLIC_KEY=pk-lf-xxx | |
export LANGFUSE_SECRET_KEY设置 Langfuse 密钥 | 基础 | export LANGFUSE_SECRET_KEY=sk-lf-xxx | |
export LANGFUSE_HOST设置 Langfuse 服务器地址 | 基础 | export LANGFUSE_HOST=http://localhost:3000 | |
langfuse trace创建 Langfuse trace | 中级 | python -c 'from langfuse import Langfuse; lf = Langfuse(); trace = lf.trace(name="my-llm-call"); trace.update(output="result")'
| |
langfuse span创建 span(追踪的子步骤) | 中级 | python -c 'from langfuse import Langfuse; lf = Langfuse(); trace = lf.trace(name="pipeline"); span = trace.span(name="llm-call"); span.end()'
| |
langfuse generation追踪 LLM 生成(含 token 计数) | 中级 | python -c 'from langfuse import Langfuse; lf = Langfuse(); lf.generation(name="chat", model="gpt-4", input="Hello", output="Hi", usage={"promptTokens":10,"completionTokens":5})'
| |
langfuse score为 trace 添加评分 | 高级 | python -c 'from langfuse import Langfuse; lf = Langfuse(); lf.score(name="accuracy", value=0.95, trace_id="xxx")'
| |
langfuse prompt从 Langfuse 获取管理的 prompt 模板 | 中级 | python -c 'from langfuse import Langfuse; lf = Langfuse(); prompt = lf.get_prompt("my-prompt"); print(prompt.compile(input="value"))'
| |
langfuse dataset创建或获取评估数据集 | 高级 | python -c 'from langfuse import Langfuse; lf = Langfuse(); dataset = lf.get_dataset("eval-data"); print(len(dataset.items))'
|
ai-server(2)
| 命令 | 难度 | ||
|---|---|---|---|
langfuse server启动 Langfuse 本地服务器(Docker) | 中级 | langfuse server | |
docker compose langfuse通过 Docker Compose 启动 Langfuse | 中级 | docker compose -f docker-compose.yml up -d |
常见问题
本速查表数据整理自各工具官方文档。最后更新: 2026-07-20。