Skip to content

Commit

Permalink
Better error handling in HealthGPTView
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Mar 27, 2024
1 parent 971a1cb commit 56c479e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
1 change: 0 additions & 1 deletion HealthGPT/HealthGPT/HealthDataInterpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class HealthDataInterpreter: DefaultInitializable, Module, EnvironmentAccessible
}

let llm = llmRunner(with: llmSchema)

systemPrompt = try await generateSystemPrompt()
llm.context.append(systemMessage: systemPrompt)
self.llm = llm
Expand Down
21 changes: 19 additions & 2 deletions HealthGPT/HealthGPT/HealthGPTView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct HealthGPTView: View {

@Environment(HealthDataInterpreter.self) private var healthDataInterpreter
@State private var showSettings = false
@State private var showErrorAlert = false
@State private var errorMessage = ""

var body: some View {
NavigationStack {
Expand All @@ -38,7 +40,12 @@ struct HealthGPTView: View {
.onChange(of: llm.context, initial: true) { _, _ in
Task {
if llm.state != .generating {
try? await healthDataInterpreter.queryLLM()
do {
try await healthDataInterpreter.queryLLM()
} catch {
showErrorAlert = true
errorMessage = "Error querying LLM: \(error.localizedDescription)"

Check warning on line 47 in HealthGPT/HealthGPT/HealthGPTView.swift

View check run for this annotation

Codecov / codecov/patch

HealthGPT/HealthGPT/HealthGPTView.swift#L46-L47

Added lines #L46 - L47 were not covered by tests
}
}
}
}
Expand All @@ -52,8 +59,18 @@ struct HealthGPTView: View {
.sheet(isPresented: $showSettings) {
SettingsView()
}
.alert("ERROR_ALERT_TITLE", isPresented: $showErrorAlert) {
Button("ERROR_ALERT_CANCEL", role: .cancel) {}
} message: {
Text(errorMessage)
}
.task {
try? await healthDataInterpreter.prepareLLM(with: openAIModel)
do {
try await healthDataInterpreter.prepareLLM(with: openAIModel)
} catch {
showErrorAlert = true
errorMessage = "Error preparing LLM: \(error.localizedDescription)"

Check warning on line 72 in HealthGPT/HealthGPT/HealthGPTView.swift

View check run for this annotation

Codecov / codecov/patch

HealthGPT/HealthGPT/HealthGPTView.swift#L71-L72

Added lines #L71 - L72 were not covered by tests
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions HealthGPT/Supporting Files/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@
}
}
},
"ERROR_ALERT_CANCEL" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "OK"
}
}
}
},
"ERROR_ALERT_TITLE" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Error"
}
}
}
},
"HEALTHKIT_PERMISSIONS_BUTTON" : {
"localizations" : {
"en" : {
Expand Down

0 comments on commit 56c479e

Please sign in to comment.