serving-openmed-rest-api
できること
このスキルは、他のプログラムがWeb越しに呼び出せる、医療テキストの分析サービスを動かす方法をエージェントに教えます。個人情報を見つけて伏せる、社内向けのサービスがほしいチーム向けです。
使う場面
- ✓医療テキストの中の医学用語を見つける、社内のプライベートなWebサービスがほしいとき。
- ✓他のアプリがHTTPで呼び出せる、匿名化のルートが必要な開発者がいるとき。
- ✓サービスをデプロイするため、コンテナにまとめたいとき。
スキルのリンク
https://github.com/maziyarpanahi/openmed/blob/master/skills/serving-openmed-rest-api/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“当社のアプリがノートから患者の名前を取り除くために呼び出せる、社内のWebサービスを設定するのを手伝ってください。”
毎週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エージェントが、匿名化済みの臨床テキストに残っている識別子(SSN、カード番号、メール、日付など)をスキャンし、残っていれば公開を止めます。
似ているスキル
api-connector-builder
280kエージェントが既存のパターンに従って、新しいAPI連携を構築します。新しい方式を作らずに、もう一つ連携を追加したいときに使います。
api-design
280kエージェントがベストプラクティスに沿ってREST APIを設計できるようにします。APIの通信方法、エラーの表示方法、データの整理方法を決めるのに役立ちます。
backend-patterns
280kエージェントのサーバーサイドのアーキテクチャパターンとデータベースの最適化を支援します。サーバー上で動くコードを作成またはレビューするときに役立ちます。