Install
openclaw skills install langextractGoogle 出品的 Python 库,用 LLM 从非结构化文本中提取结构化信息,每个提取结果精确对应源文本位置,支持交互式可视化,适配 Gemini/OpenAI/Ollama 等多种模型
openclaw skills install langextractLangExtract 是 Google 出品的 Python 库,利用 LLM 从临床笔记、法律文书、新闻报道等非结构化文本中提取结构化信息。其核心优势是精确源文本定位:每个提取结果都映射到源文本的精确字符位置,支持可视化高亮审查,适合需要可追溯性的企业级数据提取场景。只需几个示例即可定义提取任务,无需微调模型。
pip install langextract 并配置 API 密钥lx.extract() 处理文本或文档 URLlx.visualize() 生成交互式 HTML 审查界面char_interval=None 的结果,保留有源文本依据的提取使用本技能时,AI 可以:
prompt_description 和 exampleslx.extract() 处理文本字符串或文档 URLchar_interval=None)的提取结果char_interval(字符偏移)import langextract as lx
# 定义提取任务
result = lx.extract(
text_or_documents="John took aspirin 500mg twice daily for headache.",
prompt_description="Extract medications and dosages.",
examples=[
lx.data.ExampleData(
text="Patient was prescribed ibuprofen 400mg.",
extractions=[
lx.data.Extraction(
extraction_class="medication",
extraction_text="ibuprofen 400mg",
attributes={"dosage": "400mg"}
)
]
)
],
model_id="gemini-2.5-flash",
)
# 只保留有源文本依据的结果
grounded = [e for e in result.extractions if e.char_interval]
print(grounded)
# 生成可视化
lx.io.save_annotated_documents([result], output_name="out.jsonl", output_dir=".")
html = lx.visualize("out.jsonl")
| 依赖 | 版本要求 |
|---|---|
| Python | >= 3.9 |
| Gemini API Key | 推荐(或 OpenAI/Ollama) |
| pip | 任意版本 |