# LLM 应用和医疗数据

> 使用大型语言模型处理医疗数据：上下文 API 请求和响应、云端和本地模型、代理系统、检索与上下文，以及带来源的提示。

Source: https://developers.anpheros.com/zh/guides/llm-healthcare-data

**一个使用大型语言模型处理医疗数据的应用程序必须解决模型无法解决的一个问题：患者记录的哪一部分应放入提示中，以及如何标记它，以便模型能够区分事实和笔记。** Anpheros 通过上下文 API 在数据层面解决了这个问题：给定患者、任务和令牌预算，它会返回患者的 HL7 FHIR R4 记录的相关部分，每个项目都标有其来源。您的应用程序将该上下文发送到您选择的模型——托管或本地。

**如何将 LLM 连接到 FHIR 医疗数据？** 将记录保存在模型无法直接访问的 FHIR 存储中——使用 Anpheros，患者的 HL7 FHIR R4 记录——向其请求有预算、有来源标记的上下文（`POST /v1/context`），并将该上下文放入您选择的模型提示中。模型永远不会收到数据库或 API 凭据；您的应用程序会在患者同意的情况下进行调用。

Anpheros 不运行模型，并且与任何模型提供商或本地运行时都没有原生集成。

## 模式

```
1. your app  ── POST /v1/context {patient, task, question, budget_tokens, format} ──►  Anpheros
2. Anpheros  ── sections + text + omitted + warnings + manifest_id ──────────────────►  your app
3. your app  ── system prompt + context + user question ─────────────────────────────►  the model
4. the model ── answer ───────────────────────────────────────────────────────────────►  your app
5. your app  ── optional write-back with author_type "ai" ──────────────────────────►  Anpheros
```

## 上下文请求

```bash
curl -X POST https://platform.anpheros.com/v1/context -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' -d '{
  "patient": "'$PID'",
  "task": "medication review before a cardiology visit",
  "question": "How did blood pressure evolve over the last 3 months?",
  "budget_tokens": 1500,
  "format": "text"
}'
```

| 字段 | 含义 |
|---|---|
| `patient` | 您的凭证所见的患者 ID |
| `task`, `question` | 模型将执行的操作；平台规划记录的相关部分 |
| `needs` | 可选的显式需求，例如 `["labs:4548-4", "vitals:trend:85354-9", "timeline:180d"]` |
| `budget_tokens` | 上下文大小，300–8000（默认为 2000） |
| `format` | `structured`（JSON 部分）或 `text`（也返回一个即用型文本块） |
| `window_days` | 可选的回溯窗口 |

## 上下文响应

- `sections` — 例如，摘要卡片、病症、用药、过敏史、免疫接种、实验室结果、带有每周趋势和治疗前后标记的生命体征、症状、时间线和文档。**每个项目都带有 `author_type` 和 `source`。**
- `omitted` — 未包含在预算内的内容；告知模型其上下文是部分的。
- `warnings`、`provenance_note`。
- `text` — 当 `format` 为 `text` 时。
- `manifest_id` — 记录了使用了哪些部分和来源，并与访问日志关联。
- 一个 `ai_notes` 部分 — AI 之前编写的值仅出现在此处，标记为未经验证，绝不与临床部分混合。

## 云模型

使用托管模型——来自 OpenAI、Anthropic、Google、xAI 或其他提供商的模型——您的后端会将上下文放入提示中并调用提供商的 API。上下文将离开您的基础设施，进入该提供商，因此：

- 确保患者的同意和您的隐私声明涵盖将数据发送给它；
- 与提供商签订一份适合健康数据的处理协议；
- 只发送任务所需的内容——令牌预算和显式 `needs` 会有所帮助。

## 本地模型

使用您自己运行的模型（例如通过 Ollama 或其他本地运行时）时，唯一携带患者数据的网络调用是您的后端与 Anpheros 之间的调用；提示和答案保留在您的基础设施上。较小的本地模型具有较小的上下文窗口：因此 `budget_tokens` 较低，并且更倾向于 `format: "text"`。

## Agentic systems

当模型决定调用哪些函数时，请为其提供工具（上下文、搜索、时间线），而不是原始凭证，保持范围狭窄，并在每个 `manifest_id` 旁边记录答案。[AI agents and medical data](https://developers.anpheros.com/zh/guides/ai-agents-medical-data)

## 上下文 API 还是您自己的检索？

对于非结构化笔记，通过自由文本（嵌入文档块并搜索它们）的检索管道很有用。对于结构化的医疗数据，上下文 API 通常更简单、更安全：它处理编码的 FHIR 资源，保留来源信息，了解趋势和治疗周期，尊重同意并经过审计。两者可以结合使用——例如，来自 Anpheros 的上下文加上您管理的文档中的检索到的段落。

## 使用来源信息进行提示

在提示中保留标签，并告诉模型它们的含义：

```
The context below comes from the patient's record. Each item is labelled with its author type
(patient, practitioner, device, import, derived) and source. Items under ai_notes were written by an
AI earlier and are not verified. Say which items your answer relies on. If the context is marked as
partial, say so. Do not give a diagnosis or change a treatment; suggest discussing it with a clinician.
```

## 相关

- [AI 医疗应用](https://developers.anpheros.com/zh/guides/ai-healthcare)
- [AI 代理与医疗数据](https://developers.anpheros.com/zh/guides/ai-agents-medical-data)
- [如何使用结构化数据构建医疗聊天机器人](https://developers.anpheros.com/zh/guides/ai-medical-assistant)
- [安全、隐私与数据驻留](https://developers.anpheros.com/zh/guides/security)
