serving-openmed-rest-api
它能做什么
这项技能教智能体如何运行一个医学文本分析服务,供其他程序通过网络调用。适合希望搭建内部服务、用于查找和遮盖个人信息的团队。
适用场景
- ✓当团队想要一个私有的内部网络服务,用于在文本中查找医学术语的时候。
- ✓当开发者需要一个可供其他应用通过 HTTP 调用的去标识化接口的时候。
- ✓当用户想把服务打包到容器中进行部署的时候。
技能链接
https://github.com/maziyarpanahi/openmed/blob/master/skills/serving-openmed-rest-api/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我搭建一个内部网络服务,让我们的应用可以调用它,从记录中去除患者姓名。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会安装 FastAPI 服务并启动它,然后添加 analyze 和 deidentify 等路由。这项技能说明该服务为自托管,模型在设备上运行。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Serving OpenMed over REST
openmed.service is a hardened FastAPI app exposing OpenMed's NER, PII
extraction, and de-identification over HTTP. It is built to be self-hosted:
models run on-device, there's no telemetry, and the request schemas reject raw
PHI from spilling into errors. Use it when callers need request/response
inference; use batch-processing-clinical-text for corpora.
When to use this skill
To put OpenMed behind an HTTP endpoint your own apps call — an internal de-id
microservice, an NER backend, a containerized inference tier. For agent/tool
integration prefer the MCP server (deploying-openmed-mcp); for offline bulk
work use batch processing.
Quick start
pip install "openmed[service]" # FastAPI + uvicorn + pydantic
# Launch the ASGI app (factory create_app, or the module-level `app`)
python -m openmed.service.logging --host 127.0.0.1 --port 8000
# Or build it in-process (e.g. to mount under a parent app / add middleware):
from openmed.service import create_app
app = create_app()
curl -s localhost:8000/health
# {"status":"ok","service":"openmed-rest","version":"...","profile":"prod"}
curl -s localhost:8000/analyze -H 'content-type: application/json' -d '{
"text": "Patient received 75mg clopidogrel for NSTEMI.",
"model_name": "disease_detection_superclinical"
}'
curl -s localhost:8000/pii/deidentify -H 'content-type: application/json' -d '{
"text": "John Doe called 555-123-4567 on 01/15/2020.",
"method": "mask"
}'
Endpoints (confirmed in openmed/service/app.py)
| Method & path | Purpose | Request schema |
|---|---|---|
GET /health |
liveness + version + active profile | — |
GET /models/loaded |
cache/keep-alive status of resident models | — |
POST /models/unload |
unload one model or all inactive models | ModelUnloadRequest (model_name or all=true) |
POST /analyze |
clinical NER | AnalyzeRequest |
POST /pii/extract |
detect PII/PHI spans | PIIExtractRequest |
POST /pii/deidentify |
mask/remove/replace/hash/shift-dates PHI | PIIDeidentifyRequest |
Request fields (from openmed/service/schemas.py, strict — unknown fields are
rejected):
AnalyzeRequest:text(required),model_name("disease_detection_superclinical"),confidence_threshold(0.0),group_entities,aggregation_strategy(simple|first|average|max),sentence_detection,sentence_language,sentence_clean,use_fast_tokenizer,keep_alive.PIIExtractRequest:text,model_name(defaultOpenMed/OpenMed-PII-SuperClinical-Small-44M-v1),confidence_threshold(0.5),use_smart_merging,lang(en/fr/de/it/es/nl/hi/te/pt/ar/ja/tr),normalize_accents,keep_alive.PIIDeidentifyRequest: same base plusmethod(mask|remove|replace|hash|shift_dates, defaultmask),confidence_threshold(0.7),keep_year,shift_dates,date_shift_days,keep_mapping,policy,use_smart_merging,use_safety_sweep.
Responses are the OpenMed result to_dict() (e.g. {text, entities[...], ...}).
Errors use a stable envelope: {"error": {"code", "message", "details"}} with
422 validation_error, 400 bad_request, 504 timeout, 500 internal_error.
Configuring the runtime (env vars)
ServiceRuntime.from_env() reads the process environment at startup
(openmed/service/runtime.py):
| Env var | Effect |
|---|---|
OPENMED_PROFILE |
config profile (prod default) |
OPENMED_SERVICE_PRELOAD_MODELS |
comma list of models to warm at startup |
OPENMED_SERVICE_KEEP_ALIVE |
default idle keep-alive before unload |
OPENMED_SERVICE_MAX_RESIDENT_MODELS |
cap resident models (warm pool) |
OPENMED_SERVICE_BATCHING_ENABLED |
enable dynamic request batching |
OPENMED_SERVICE_BATCH_MAX_SIZE |
max dynamic batch size (default 8) |
OPENMED_SERVICE_BATCH_MAX_WAIT_MS |
batch-collection window (default 5ms) |
OPENMED_SERVICE_PRELOAD_MODELS="disease_detection_superclinical" \
OPENMED_SERVICE_BATCHING_ENABLED=true \
python -m openmed.service.logging --host 0.0.0.0 --port 8000
Preloading avoids first-request latency; the warm pool keeps hot models resident
and idle-unloads the rest. /analyze and /pii/extract coalesce concurrent
requests when batching is enabled.
Workflow
- Install + launch.
pip install "openmed[service]", then runpython -m openmed.service.logging(or build withcreate_app()). - **Config
常见问题
服务会把数据发送到其他地方吗?
这项技能说明它不做任何遥测,模型在设备上运行。
有健康检查吗?
有。这项技能展示了一个健康检查端点,用于报告服务状态。
如果要一次处理大量文档怎么办?
这项技能会指引用户使用单独的批处理技能来处理大型文档集。
详情
作者的原始描述
Stand up OpenMed's FastAPI REST service for clinical NER, PII extraction, and de-identification, with health checks, model keep-alive/unload, optional dynamic batching, and no-PHI logging. Use when the user wants to serve OpenMed over HTTP, deploy a de-id/NER REST API, run an inference endpoint for clinical text, add a /analyze or /pii/deidentify route, or containerize OpenMed as a service. Covers the service extra, launching create_app with uvicorn, the real endpoints (/health, /analyze, /pii/extract, /pii/deidentify, /models/loaded, /models/unload), request/response shapes, ServiceRuntime en
repo: maziyarpanahi/openmed
热度
- GitHub 星标
- 5.8k
- 排名
- #14733
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
annotating-variants
5.8k帮你的智能体预测基因变异的作用,把 HGVS 名称转换为基因组位置,并使用免费的公共注释工具添加人群频率。
ask-openmed
5.8k帮你的智能体为临床文本请求选择合适的 OpenMed 工作流程,并在可能涉及患者数据时,先进行隐私检查。
assembling-fhir-bundles
5.8k把多份 FHIR 健康记录打包成一个事务 Bundle,可直接发送给 EHR 系统,并正确链接其中的内部引用。
auditing-deid-leakage
5.8k扫描已去标识化的临床文本,查找残留的标识符,例如社会安全号、银行卡号、电子邮件地址和日期,若仍有残留则阻止发布。