Skip to content

Commit

Permalink
Add reset chat button to toolbar in HealthGPTView
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Mar 28, 2024
1 parent 2cd1404 commit aafbe95
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
1 change: 0 additions & 1 deletion HealthGPT/HealthGPT/HealthDataInterpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class HealthDataInterpreter: DefaultInitializable, Module, EnvironmentAccessible
/// and passes it to the `PromptGenerator` to create the system prompt.
private func generateSystemPrompt() async -> String {
let healthData = await healthDataFetcher.fetchAndProcessHealthData()
print(healthData)
return PromptGenerator(with: healthData).buildMainPrompt()
}
}
30 changes: 26 additions & 4 deletions HealthGPT/HealthGPT/HealthGPTView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ struct HealthGPTView: View {
ToolbarItem(placement: .primaryAction) {
settingsButton
}
ToolbarItem(placement: .primaryAction) {
resetChatButton
}
}
.onChange(of: llm.context, initial: true) { _, _ in
Task {
Expand All @@ -50,10 +53,7 @@ struct HealthGPTView: View {
}
}
} else {
VStack {
Text("LOADING_CHAT_VIEW")
ProgressView()
}
loadingChatView
}
}
.sheet(isPresented: $showSettings) {
Expand Down Expand Up @@ -81,4 +81,26 @@ struct HealthGPTView: View {
)
.accessibilityIdentifier("settingsButton")
}

private var resetChatButton: some View {
Button(
action: {
Task {
await healthDataInterpreter.resetChat()
}
},
label: {
Image(systemName: "arrow.counterclockwise")
.accessibilityLabel(Text("RESET"))
}
)
.accessibilityIdentifier("resetChatButton")
}

private var loadingChatView: some View {
VStack {
Text("LOADING_CHAT_VIEW")
ProgressView()
}
}
}
2 changes: 1 addition & 1 deletion HealthGPT/HealthGPT/PromptGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PromptGenerator {

func buildMainPrompt() -> String {
let today = DateFormatter.localizedString(from: Date(), dateStyle: .full, timeStyle: .none)
var mainPrompt = "You are HealthGPT, an enthusiastic, expert caretaker with a deep understanding in personal health. Given the context, provide a short response that could answer the user's question. Do NOT provide statistics. Do not provide any advice on how to improve. Do not provide any recommendations. Just provide pure data. \n\nSome health metrics over the past two weeks (14 days) to incorporate is given below. If a value is zero, the user has not inputted anything for that day. Today is \(today). Note that you do not have data about the current day. \n\n"
var mainPrompt = "You are HealthGPT, an enthusiastic, expert caretaker with a deep understanding in personal health. Given the context, provide a short response that could answer the user's question. Do NOT provide statistics. If numbers seem low, provide advice on how they can improve.\n\nSome health metrics over the past two weeks (14 days) to incorporate is given below. If a value is zero, the user has not inputted anything for that day. Today is \(today). Note that you do not have data about the current day. \n\n"
mainPrompt += buildFourteenDaysHealthDataPrompt()
return mainPrompt
}
Expand Down
4 changes: 3 additions & 1 deletion HealthGPT/Onboarding/HealthKitPermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// SPDX-License-Identifier: MIT
//

import OSLog
import SpeziHealthKit
import SpeziOnboarding
import SwiftUI
Expand All @@ -15,6 +16,7 @@ struct HealthKitPermissions: View {
@Environment(HealthKit.self) var healthKitDataSource
@Environment(OnboardingNavigationPath.self) private var onboardingNavigationPath
@State var healthKitProcessing = false
let logger = Logger(subsystem: "HealthGPT", category: "Onboarding")


var body: some View {
Expand Down Expand Up @@ -48,7 +50,7 @@ struct HealthKitPermissions: View {
try await healthKitDataSource.askForAuthorization()
}
} catch {
print("Could not request HealthKit permissions.")
logger.error("Could not request HealthKit permissions: \(error.localizedDescription)")
}
onboardingNavigationPath.nextStep()
healthKitProcessing = false
Expand Down
10 changes: 10 additions & 0 deletions HealthGPT/Supporting Files/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@
}
}
},
"RESET" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Reset"
}
}
}
},
"SETTINGS_CHAT" : {
"localizations" : {
"en" : {
Expand Down
9 changes: 9 additions & 0 deletions HealthGPTUITests/HealthGPTViewUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@ final class HealthGPTViewUITests: XCTestCase {

XCTAssert(app.staticTexts["HealthGPT"].waitForExistence(timeout: 2))
}

func testResetChat() throws {
let app = XCUIApplication()
try app.conductOnboardingIfNeeded()

let resetChatButton = app.buttons["resetChatButton"]
XCTAssertTrue(resetChatButton.waitForExistence(timeout: 5))
resetChatButton.tap()
}
}

0 comments on commit aafbe95

Please sign in to comment.