joelmontavon/fhir4px-model-webllm
0
fhir4px-model Integration
This directory contains the integration package required to use the fhir4px-model and lookup table inside a web application.
1. Hosting Requirements
Before using this integration, you need to host the compiled model artifacts:
- Model Weights: Host the contents of
dist/fhir4px-q4f16_1-MLC/on a CDN or a HuggingFace model repository. - WebGPU WASM: Host
dist/libs/fhir4px-q4f16_1-webgpu.wasmon a CDN. - Lookup Table: Copy
dist/lookup.jsoninto your web application's static assets orsrcdirectory.
Once hosted, update the URLs in src/integration/config.ts to point to your live assets.
2. Dependencies
You will need the @mlc.ai/web-llm package in your web project.
npm install @mlc.ai/web-llm3. Usage Example
Here is how you use the pipeline to translate FHIR codes in your app:
import { FhirLookup, initializeLLM, translateClinicalTerm } from './integration';
// Import your bundled lookup table
import lookupJson from './lookup.json';
async function main() {
// 1. Initialize the local, deterministic lookup table
const lookup = new FhirLookup(lookupJson);
// 2. Initialize the WebGPU LLM for fallbacks
console.log("Downloading and initializing model...");
const engine = await initializeLLM((report) => {
console.log(`Loading: ${report.text}`);
});
// 3. Translate a known code (will be fast, no LLM required)
const knownTerm = await translateClinicalTerm(
engine,
lookup,
"O00.20",
"ICD10CM",
"Ovarian pregnancy without intrauterine pregnancy"
);
console.log("Known term:", knownTerm); // Output: "ovarian pregnancy"
// 4. Translate an unknown code (will fallback to WebGPU LLM)
const unknownTerm = await translateClinicalTerm(
engine,
lookup,
"UNKNOWN-999",
"SNOMEDCT_US",
"Acute myocardial infarction of inferolateral wall"
);
console.log("Unknown term:", unknownTerm); // Output: "Heart attack (myocardial infarction)"
}
main();