Skip to content

Commit

Permalink
Feature/improve prompt and patients (#42)
Browse files Browse the repository at this point in the history
# Improve Patient Selection & Interpretation Prompt

## ⚙️ Release Notes 
- Improve Patient Selection
- Improve Interpretation Prompt


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
PSchmiedmayer authored Dec 15, 2023
1 parent 98f1a87 commit 30e02d6
Show file tree
Hide file tree
Showing 22 changed files with 92,221 additions and 285,574 deletions.
28 changes: 4 additions & 24 deletions LLMonFHIR.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Test"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
Expand Down
1 change: 1 addition & 0 deletions LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct MultipleResourcesChatView: View {
.accessibilityLabel(Text("Reset Chat"))
}
)
.disabled(multipleResourceInterpreter.viewState == .processing)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ class FHIRMultipleResourceInterpreter {
chat.append(
Chat(
role: .system,
content: String(
localized: "Here is the JSON content of the patient resource as an initial context: \n\n \(patient.jsonDescription)",
comment: "System prompt used by the FHIRMultipleResourceInterpreter to pass in the patient JSON."
)
content: patient.jsonDescription
)
)
}
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions LLMonFHIR/FHIR Interpretation/FHIRStore+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ extension FHIRStore {
if FeatureFlags.testMode {
let mockObservation = Observation(
code: CodeableConcept(coding: [Coding(code: "1234".asFHIRStringPrimitive())]),
id: FHIRPrimitive<FHIRString>("1234"),
issued: FHIRPrimitive<Instant>(try? Instant(date: .now)),
status: FHIRPrimitive(ObservationStatus.final)
)
Expand Down
98 changes: 17 additions & 81 deletions LLMonFHIR/Mock Data/MockData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ import SpeziFHIRMockPatients


extension ModelsR4.Bundle {
private static var _allen322Ferry570: ModelsR4.Bundle?
static var allen322Ferry570: ModelsR4.Bundle {
get async {
if let allen322Ferry570 = _allen322Ferry570 {
return allen322Ferry570
}

let allen322Ferry570 = await Foundation.Bundle.main.loadFHIRBundle(
withName: "Allen322_Ferry570_ad134528-56a5-35fd-c37f-466ff119c625"
)
ModelsR4.Bundle._allen322Ferry570 = allen322Ferry570
return allen322Ferry570
}
}

private static var _beatris270Bogan287: ModelsR4.Bundle?
static var beatris270Bogan287: ModelsR4.Bundle {
get async {
Expand All @@ -27,21 +42,6 @@ extension ModelsR4.Bundle {
}
}

private static var _domingo513Bashirian201: ModelsR4.Bundle?
static var domingo513Bashirian201: ModelsR4.Bundle {
get async {
if let domingo513Bashirian201 = _domingo513Bashirian201 {
return domingo513Bashirian201
}

let domingo513Bashirian201 = await Foundation.Bundle.main.loadFHIRBundle(
withName: "Domingo513_Bashirian201_ff0e4d0e-6181-e36e-d817-64dbcaecb5d0"
)
ModelsR4.Bundle._domingo513Bashirian201 = domingo513Bashirian201
return domingo513Bashirian201
}
}

private static var _edythe31Morar593: ModelsR4.Bundle?
static var edythe31Morar593: ModelsR4.Bundle {
get async {
Expand Down Expand Up @@ -72,21 +72,6 @@ extension ModelsR4.Bundle {
}
}

private static var _gregoria352Shan714: ModelsR4.Bundle?
static var gregoria352Shan714: ModelsR4.Bundle {
get async {
if let gregoria352Shan714 = _gregoria352Shan714 {
return gregoria352Shan714
}

let gregoria352Shan714 = await Foundation.Bundle.main.loadFHIRBundle(
withName: "Gregoria352_Shan714_Koss676_b5fab35c-8cd1-49f0-b28c-122866af8614"
)
ModelsR4.Bundle._gregoria352Shan714 = gregoria352Shan714
return gregoria352Shan714
}
}

private static var _jacklyn830Veum823: ModelsR4.Bundle?
static var jacklyn830Veum823: ModelsR4.Bundle {
get async {
Expand All @@ -102,21 +87,6 @@ extension ModelsR4.Bundle {
}
}

private static var _micah422Stehr398: ModelsR4.Bundle?
static var micah422Stehr398: ModelsR4.Bundle {
get async {
if let micah422Stehr398 = _micah422Stehr398 {
return micah422Stehr398
}

let micah422Stehr398 = await Foundation.Bundle.main.loadFHIRBundle(
withName: "Micah422_Stehr398_10acd373-14d9-6077-f0fc-790e06d7c6c5"
)
ModelsR4.Bundle._micah422Stehr398 = micah422Stehr398
return micah422Stehr398
}
}

private static var _milton509Ortiz186: ModelsR4.Bundle?
static var milton509Ortiz186: ModelsR4.Bundle {
get async {
Expand All @@ -132,50 +102,16 @@ extension ModelsR4.Bundle {
}
}

private static var _pasquale620Kuhn96: ModelsR4.Bundle?
static var pasquale620Kuhn96: ModelsR4.Bundle {
get async {
if let pasquale620Kuhn96 = _pasquale620Kuhn96 {
return pasquale620Kuhn96
}

let pasquale620Kuhn96 = await Foundation.Bundle.main.loadFHIRBundle(
withName: "Pasquale620_Kuhn96_792a51c0-a2a4-ee26-c23c-7cb24f8a0e35"
)
ModelsR4.Bundle._pasquale620Kuhn96 = pasquale620Kuhn96
return pasquale620Kuhn96
}
}

private static var _porfirio146Jakubowski832: ModelsR4.Bundle?
static var porfirio146Jakubowski832: ModelsR4.Bundle {
get async {
if let porfirio146Jakubowski832 = _porfirio146Jakubowski832 {
return porfirio146Jakubowski832
}

let porfirio146Jakubowski832 = await Foundation.Bundle.main.loadFHIRBundle(
withName: "Porfirio146_Jakubowski832_5b70be80-a0f2-849f-a286-8a8d2eab86b9"
)
ModelsR4.Bundle._porfirio146Jakubowski832 = porfirio146Jakubowski832
return porfirio146Jakubowski832
}
}


static var llmOnFHIRMockPatients: [Bundle] {
get async {
await [
.allen322Ferry570,
.beatris270Bogan287,
.domingo513Bashirian201,
.edythe31Morar593,
.gonzalo160Duenas839,
.gregoria352Shan714,
.jacklyn830Veum823,
.micah422Stehr398,
.milton509Ortiz186,
.pasquale620Kuhn96,
.porfirio146Jakubowski832
.milton509Ortiz186
]
}
}
Expand Down
5 changes: 1 addition & 4 deletions LLMonFHIR/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1168,9 +1168,6 @@
}
}
},
"Here is the JSON content of the patient resource as an initial context: \n\n %@" : {
"comment" : "System prompt used by the FHIRMultipleResourceInterpreter to pass in the patient JSON."
},
"Immunizations" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -1198,7 +1195,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "You are the LLM on FHIR application.\nYour task is to interpret FHIR resources from the user's clinical records.\n\nThroughout the conversation with the user, use the \"get_resources\" function to obtain the FHIR health resources necessary to answer the user's question properly. For example, if the user asks about their allergies, you must use the \"get_resources\" function to output the FHIR resource titles for allergy records so you can then use them to answer the question. The end goal is to answer the user's question in the best way possible while taking the FHIR resources obtained using \"get_resources\" into consideration.\n\nIf there is a Patient FHIR resource available, ensure that you request this resource first to get adequate information about the patient. Only request relevant resources and focus on recent resources. Try to reduce the number of requested resources to a reasonable scope.\n\nThese are the resource titles of the resources you can request using \"get_resources\":\n{{FHIR_RESOURCE}}\n\nE.g. if the user asks about their Medication it would be recommended to request all MedicationRequest FHIR resource types.\n\nInterpret the resources by explaining the data relevant to the user's health.\nExplain the relevant medical context in a language understandable by a user who is not a medical professional, ideally at a 5th-grade reading level.\nYou should provide factual and precise information in a compact summary in short responses.\n\nDo not introduce yourself at the beginning, and start with your interpretation. \n\nImmediately return a summary of the user based on the FHIR patient resources if available to start the conversation. You may already request FHIR resources using the \"get_resources\" function.\nThe initial summary should be short and simple and NOT list the records' titles or any resource's detailed content; stay at a high level.\nEnd with a question asking the user if they have any questions. Make sure that this question is not generic but specific to their health records.\nMake sure your response is in the same language the user writes to you in.\nThe tense should be present.\n"
"value" : "You are the LLM on FHIR application. Your task is to interpret FHIR resources from the user's clinical records.\n\nThroughout the conversation with the user, use the \"get_resources\" function to obtain the FHIR health resources necessary to answer the user's question properly. For example, if the user asks about their allergies, you must use the \"get_resources\" function to output the FHIR resource titles for allergy records so you can then use them to answer the question. The end goal is to answer the user's question in the best way possible while taking the FHIR resources obtained using \"get_resources\" into consideration. Leave out any technical details like JSON, FHIR resources, and other implementation details of the underlying data resources.\nOnly request relevant resources and focus on recent resources. Try to reduce the number of requested resources to a reasonable scope.\nE.g. if the user asks about their Medication it would be recommended to request all MedicationRequest FHIR resource types.\n\nInterpret the resources by explaining the data relevant to the user's health. Explain the relevant medical context in a language understandable by a user who is not a medical professional, ideally at a 5th-grade reading level. You should provide factual and precise information in a compact summary in short responses.\n\nThe patient resource is provided as the initial context. Ensure to leave out any like SSN, passport number, and telephone number. \nDo not introduce yourself at the beginning and immediately return a summary of the user based on the FHIR patient resources. No not request any FHIR resources using the \"get_resources\" function for your first message. The initial summary should be short and simple; stay at a high level. End with a question asking the user if they have any questions. Make sure your response is in the same language the user writes to you in, not the one stated in the patient resource. The tense should be present."
}
}
}
Expand Down
Loading

0 comments on commit 30e02d6

Please sign in to comment.