Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lift to SpeziLLM #44

Merged
merged 10 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 161 additions & 81 deletions LLMonFHIR.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,103 +18,138 @@
"version" : "0.2.5"
}
},
{
"identity" : "llama.cpp",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/llama.cpp",
"state" : {
"revision" : "b0611c7d3cb049822f9911878514e4706b80e2ac",
"version" : "0.1.8"
}
},
{
"identity" : "openai",
"kind" : "remoteSourceControl",
"location" : "https://github.com/MacPaw/OpenAI",
"state" : {
"revision" : "ac5892fd0de8d283362ddc30f8e9f1a0eaba8cc0",
"version" : "0.2.5"
"revision" : "35afc9a6ee127b8f22a85a31aec2036a987478af"
}
},
{
"identity" : "semaphore",
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/Semaphore.git",
"state" : {
"revision" : "f1c4a0acabeb591068dea6cffdd39660b86dec28",
"version" : "0.0.8"
}
},
{
"identity" : "spezi",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/Spezi",
"state" : {
"revision" : "d56ed07327cce8254b919665eb61e20bfd1467b0",
"version" : "0.8.2"
"revision" : "c4bf0e99de40acfdd2baf0fa02769f06a4c3f0eb",
"version" : "1.1.0"
}
},
{
"identity" : "spezichat",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziChat",
"state" : {
"revision" : "ea5e21b4f42d99a5549dd7a7033e2a3efeb5fd36",
"version" : "0.1.5"
}
},
{
"identity" : "spezifhir",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziFHIR.git",
"location" : "https://github.com/StanfordSpezi/SpeziFHIR",
"state" : {
"revision" : "07c2e56b8dd08bbf33ae4e3dfa2f2b9ca24807ea",
"version" : "0.5.3"
"branch" : "feat/lift-to-spezi-llm",
"revision" : "b58ba7afc34ff1b83d4f4ab3525d3d13f372b080"
}
},
{
"identity" : "spezifoundation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziFoundation",
"state" : {
"revision" : "683c66f922a4cfe0882c4a86a43854f613b48541",
"version" : "0.1.0"
"revision" : "d1e6d4cddcf236038d21a73d671806d8ba51b01c",
"version" : "1.0.1"
}
},
{
"identity" : "spezihealthkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziHealthKit.git",
"state" : {
"revision" : "30e12a0f66bed98830dddd6ab2be06140d078aaa",
"version" : "0.4.0"
"revision" : "d882734a4ed31fce1bffd7b9977e2669080f21de",
"version" : "0.5.0"
}
},
{
"identity" : "speziml",
"identity" : "spezillm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziML.git",
"location" : "https://github.com/StanfordSpezi/SpeziLLM",
"state" : {
"revision" : "786dbba6023feaedf59aeff2f92d324cc7afaaba",
"version" : "0.3.1"
"branch" : "feat/structural-improvments",
"revision" : "f30f4d311cf99a396e76e5b732dca6462463f663"
}
},
{
"identity" : "spezionboarding",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziOnboarding.git",
"state" : {
"revision" : "70d1a740a0da8a5bc83d95bcff177ebd3e7402c0",
"version" : "0.7.0"
"revision" : "8fb6d9f1a080661c0cc564a93b82ead3c8d44d4f",
"version" : "1.0.2"
}
},
{
"identity" : "spezispeech",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziSpeech",
"state" : {
"revision" : "a1e1d021d8f605b5e6b23aee773115d7125a57e3",
"version" : "1.0.0"
}
},
{
"identity" : "spezistorage",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziStorage",
"state" : {
"revision" : "e9be3c2743e462894bf56d41339b040f4060b567",
"version" : "0.5.0"
"revision" : "eaed2220375c35400aa69d1f96a8d32b7e66b1c7",
"version" : "1.0.0"
}
},
{
"identity" : "speziviews",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordSpezi/SpeziViews.git",
"state" : {
"revision" : "dcd0bc10ae8f22cba771ff9ab3ce16549f46f667",
"version" : "0.6.3"
"revision" : "0137e69d156bf4001a8d6bf5661c9a37b2bbd0aa",
"version" : "1.0.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307",
"version" : "1.0.5"
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
}
},
{
"identity" : "xctestextensions",
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/XCTestExtensions.git",
"state" : {
"revision" : "388a6d6a5be48eff5d98a2c45e0b50f30ed21dc3",
"version" : "0.4.7"
"revision" : "fb7fcee97c574b950e03b0a53874e26db27db2fe",
"version" : "0.4.8"
}
},
{
Expand All @@ -131,8 +166,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/StanfordBDHG/XCTRuntimeAssertions",
"state" : {
"revision" : "9226052589b8faece98861bc3d7b33b3ebfe4f5a",
"version" : "0.2.5"
"revision" : "bb2a287c2544aa846e53670d1ece35e5949567be",
"version" : "1.0.0"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
3 changes: 1 addition & 2 deletions LLMonFHIR/FHIR Display/FHIRResourcesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
//

import ModelsR4
import OpenAI
import SpeziFHIR
import SpeziFHIRInterpretation
import SpeziLLMOpenAI
import SpeziOnboarding
import SpeziOpenAI
import SpeziViews
import SwiftUI

Expand Down
16 changes: 9 additions & 7 deletions LLMonFHIR/FHIR Display/InspectResourceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// SPDX-License-Identifier: MIT
//

import OpenAI
import SpeziFHIR
import SpeziFHIRInterpretation
import SpeziLLM
import SpeziViews
import SwiftUI

Expand All @@ -32,7 +32,9 @@
.viewStateAlert(state: $interpreting)
.viewStateAlert(state: $loadingSummary)
.task {
interpret()
if !FeatureFlags.testMode {
interpret()

Check warning on line 36 in LLMonFHIR/FHIR Display/InspectResourceView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/InspectResourceView.swift#L36

Added line #L36 was not covered by tests
}
}
}

Expand Down Expand Up @@ -115,10 +117,10 @@
do {
try await fhirResourceSummary.summarize(resource: resource, forceReload: forceReload)
loadingSummary = .idle
} catch let error as APIErrorResponse {
} catch let error as LLMError {

Check warning on line 120 in LLMonFHIR/FHIR Display/InspectResourceView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/InspectResourceView.swift#L120

Added line #L120 was not covered by tests
loadingSummary = .error(error)
} catch {
loadingSummary = .error("Unknown error")
loadingSummary = .error("Unknown LLM processing error")

Check warning on line 123 in LLMonFHIR/FHIR Display/InspectResourceView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/InspectResourceView.swift#L123

Added line #L123 was not covered by tests
philippzagar marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand All @@ -130,10 +132,10 @@
do {
try await fhirResourceInterpreter.interpret(resource: resource, forceReload: forceReload)
interpreting = .idle
} catch let error as APIErrorResponse {
loadingSummary = .error(error)
} catch let error as LLMError {
interpreting = .error(error)

Check warning on line 136 in LLMonFHIR/FHIR Display/InspectResourceView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/InspectResourceView.swift#L135-L136

Added lines #L135 - L136 were not covered by tests
} catch {
loadingSummary = .error("Unknown error")
interpreting = .error("Unknown LLM processing error")

Check warning on line 138 in LLMonFHIR/FHIR Display/InspectResourceView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/InspectResourceView.swift#L138

Added line #L138 was not covered by tests
}
}
}
Expand Down
45 changes: 25 additions & 20 deletions LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// SPDX-License-Identifier: MIT
//

import OpenAI
import SpeziChat
import SpeziFHIR
import SpeziFHIRInterpretation
import SpeziOpenAI
import SpeziLLMOpenAI
import SpeziSpeechSynthesizer
import SpeziViews
import SwiftUI
Expand All @@ -20,31 +20,36 @@

@Environment(FHIRMultipleResourceInterpreter.self) private var multipleResourceInterpreter

@StateObject private var speechSynthesizer = SpeechSynthesizer()
@State private var speechSynthesizer = SpeechSynthesizer()

Check warning on line 23 in LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift#L23

Added line #L23 was not covered by tests
@AppStorage(StorageKeys.enableTextToSpeech) private var textToSpeech = StorageKeys.Defaults.enableTextToSpeech


private var disableInput: Binding<Bool> {
Binding(
get: {
multipleResourceInterpreter.viewState == .processing
},
set: { _ in }
)
}

var body: some View {
@Bindable var multipleResourceInterpreter = multipleResourceInterpreter
NavigationStack {
ChatView($multipleResourceInterpreter.chat, disableInput: disableInput)
Group {
if let llm = multipleResourceInterpreter.llm {
let contextBinding = Binding { llm.context } set: { llm.context = $0 }
philippzagar marked this conversation as resolved.
Show resolved Hide resolved
ChatView(
contextBinding,
disableInput: llm.state.representation == .processing
)
.viewStateAlert(state: llm.state)
.onChange(of: llm.context) {
if llm.state == .ready {
multipleResourceInterpreter.queryLLM()
}
}
} else {
ChatView(
.constant([])
)
}
philippzagar marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 48 in LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift#L30-L48

Added lines #L30 - L48 were not covered by tests
.navigationTitle("LLM on FHIR")
.toolbar {
toolbar
}
.viewStateAlert(state: $multipleResourceInterpreter.viewState)
.onChange(of: multipleResourceInterpreter.chat) {
multipleResourceInterpreter.queryLLM()
}
.onAppear {
multipleResourceInterpreter.queryLLM()
}
Expand All @@ -53,9 +58,9 @@
}


@ToolbarContentBuilder private var toolbar: some ToolbarContent {
@MainActor @ToolbarContentBuilder private var toolbar: some ToolbarContent {

Check warning on line 61 in LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift#L61

Added line #L61 was not covered by tests
ToolbarItem(placement: .cancellationAction) {
if multipleResourceInterpreter.viewState == .processing {
if multipleResourceInterpreter.llm?.state.representation == .processing {

Check warning on line 63 in LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift#L63

Added line #L63 was not covered by tests
ProgressView()
} else {
Button("Close") {
Expand Down Expand Up @@ -89,7 +94,7 @@
.accessibilityLabel(Text("Reset Chat"))
}
)
.disabled(multipleResourceInterpreter.viewState == .processing)
.disabled(multipleResourceInterpreter.llm?.state.representation == .processing)

Check warning on line 97 in LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift

View check run for this annotation

Codecov / codecov/patch

LLMonFHIR/FHIR Display/MultipleResourcesChatView.swift#L97

Added line #L97 was not covered by tests
}
}
}
Loading
Loading