Skip to content

Commit

Permalink
Lift to SpeziLLM v0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
philippzagar committed Apr 7, 2024
1 parent 643c7bd commit 67543bf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ let package = Package(
.package(url: "https://github.com/StanfordBDHG/HealthKitOnFHIR", .upToNextMinor(from: "0.2.4")),
.package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.2.1"),
.package(url: "https://github.com/StanfordSpezi/SpeziHealthKit.git", .upToNextMinor(from: "0.5.1")),
.package(url: "https://github.com/StanfordSpezi/SpeziLLM.git", .upToNextMinor(from: "0.7.0")),
.package(url: "https://github.com/StanfordSpezi/SpeziLLM.git", .upToNextMinor(from: "0.8.1")),
.package(url: "https://github.com/StanfordSpezi/SpeziStorage.git", from: "1.0.0"),
.package(url: "https://github.com/StanfordSpezi/SpeziChat.git", .upToNextMinor(from: "0.1.8")),
.package(url: "https://github.com/StanfordSpezi/SpeziChat.git", .upToNextMinor(from: "0.2.0")),
.package(url: "https://github.com/StanfordSpezi/SpeziSpeech.git", from: "1.0.0")
],
targets: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct FHIRGetResourceLLMFunction: LLMFunction {

_resources = Parameter(
description: String(localized: "PARAMETER_DESCRIPTION"),
enumValues: Array(allResourcesFunctionCallIdentifiers)
enum: Array(allResourcesFunctionCallIdentifiers)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SwiftUI


private enum FHIRMultipleResourceInterpreterConstants {
static let chat = "FHIRMultipleResourceInterpreter.chat"
static let context = "FHIRMultipleResourceInterpreter.context"
}


Expand Down Expand Up @@ -65,7 +65,7 @@ public class FHIRMultipleResourceInterpreter {

let llm = llmRunner(with: llmSchema)
// Read initial conversation from storage
if let storedContext: Chat = try? localStorage.read(storageKey: FHIRMultipleResourceInterpreterConstants.chat) {
if let storedContext: LLMContext = try? localStorage.read(storageKey: FHIRMultipleResourceInterpreterConstants.context) {
llm.context = storedContext
} else {
llm.context.append(systemMessage: FHIRPrompt.interpretMultipleResources.prompt)
Expand All @@ -80,7 +80,7 @@ public class FHIRMultipleResourceInterpreter {
@MainActor
func queryLLM() {
guard let llm,
llm.context.last?.role == .user || !(llm.context.contains(where: { $0.role == .assistant }) ) else {
llm.context.last?.role == .user || !(llm.context.contains(where: { $0.role == .assistant() }) ) else {
return
}

Expand All @@ -96,7 +96,7 @@ public class FHIRMultipleResourceInterpreter {
}

// Store conversation to storage
try localStorage.store(llm.context, storageKey: FHIRMultipleResourceInterpreterConstants.chat)
try localStorage.store(llm.context, storageKey: FHIRMultipleResourceInterpreterConstants.context)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public struct MultipleResourcesChatView: View {
NavigationStack {
Group {
if let llm = multipleResourceInterpreter.llm {
let contextBinding = Binding { llm.context } set: { llm.context = $0 }
let contextBinding = Binding { llm.context.chat } set: { llm.context.chat = $0 }

ChatView(
contextBinding,
disableInput: llm.state.representation == .processing
)
.speak(llm.context, muted: !textToSpeech)
.speak(llm.context.chat, muted: !textToSpeech)
.speechToolbarButton(muted: !$textToSpeech)
.viewStateAlert(state: llm.state)
.onChange(of: llm.context, initial: true) { _, _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class FHIRResourceProcessor<Content: Codable & LosslessStringConvertible> {

let chatStreamResult: String = try await llmRunner.oneShot(
with: llmSchema,
chat: .init(systemMessages: [prompt.prompt(withFHIRResource: resource.jsonDescription)])
context: .init(systemMessages: [prompt.prompt(withFHIRResource: resource.jsonDescription)])
)

guard let content = Content(chatStreamResult) else {
Expand Down

0 comments on commit 67543bf

Please sign in to comment.