Skip to content

Commit

Permalink
Add chat view
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Oct 15, 2024
1 parent 146042a commit b3a8cda
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 0 deletions.
16 changes: 16 additions & 0 deletions MyHeartCounts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
5680DD3E2AB8CD84004E6D4A /* ContributionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5680DD3D2AB8CD84004E6D4A /* ContributionsTest.swift */; };
56E708352BB06B7100B08F0A /* SpeziLicense in Frameworks */ = {isa = PBXBuildFile; productRef = 56E708342BB06B7100B08F0A /* SpeziLicense */; };
56E7083B2BB06F6F00B08F0A /* SwiftPackageList in Frameworks */ = {isa = PBXBuildFile; productRef = 56E7083A2BB06F6F00B08F0A /* SwiftPackageList */; };
630AE0482CBDB27D0053F8C1 /* CoachChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 630AE0472CBDB27D0053F8C1 /* CoachChatView.swift */; };
630AE04B2CBDEA520053F8C1 /* OpenAIAPIKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 630AE04A2CBDEA520053F8C1 /* OpenAIAPIKey.swift */; };
638BA8C82CB9E28F00C58CD0 /* SpeziLLM in Frameworks */ = {isa = PBXBuildFile; productRef = 638BA8C72CB9E28F00C58CD0 /* SpeziLLM */; };
638BA8CA2CB9E28F00C58CD0 /* SpeziLLMFog in Frameworks */ = {isa = PBXBuildFile; productRef = 638BA8C92CB9E28F00C58CD0 /* SpeziLLMFog */; };
638BA8CC2CB9E28F00C58CD0 /* SpeziLLMLocal in Frameworks */ = {isa = PBXBuildFile; productRef = 638BA8CB2CB9E28F00C58CD0 /* SpeziLLMLocal */; };
Expand Down Expand Up @@ -127,6 +129,8 @@
2FE5DCAC29EE6107004B9AB4 /* AccountOnboarding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountOnboarding.swift; sourceTree = "<group>"; };
2FF53D8C2A8729D600042B76 /* MyHeartCountsStandard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyHeartCountsStandard.swift; sourceTree = "<group>"; };
5680DD3D2AB8CD84004E6D4A /* ContributionsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContributionsTest.swift; sourceTree = "<group>"; };
630AE0472CBDB27D0053F8C1 /* CoachChatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoachChatView.swift; sourceTree = "<group>"; };
630AE04A2CBDEA520053F8C1 /* OpenAIAPIKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenAIAPIKey.swift; sourceTree = "<group>"; };
653A254D283387FE005D4D48 /* MyHeartCounts.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MyHeartCounts.app; sourceTree = BUILT_PRODUCTS_DIR; };
653A2550283387FE005D4D48 /* MyHeartCounts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyHeartCounts.swift; sourceTree = "<group>"; };
653A255428338800005D4D48 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -225,6 +229,7 @@
2FE5DC2F29EDD7CA004B9AB4 /* Consent.swift */,
2FE5DC3029EDD7CA004B9AB4 /* HealthKitPermissions.swift */,
2F65B44D2A3B8B0600A36932 /* NotificationPermissions.swift */,
630AE04A2CBDEA520053F8C1 /* OpenAIAPIKey.swift */,
);
path = Onboarding;
sourceTree = "<group>";
Expand Down Expand Up @@ -264,6 +269,14 @@
path = SharedContext;
sourceTree = "<group>";
};
630AE0462CBD7AF30053F8C1 /* Coach */ = {
isa = PBXGroup;
children = (
630AE0472CBDB27D0053F8C1 /* CoachChatView.swift */,
);
path = Coach;
sourceTree = "<group>";
};
653A2544283387FE005D4D48 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -296,6 +309,7 @@
2F4E23822989D51F0013F3D9 /* MyHeartCountsTestingSetup.swift */,
A9720E412ABB68B300872D23 /* Account */,
2FE5DC2729EDD38D004B9AB4 /* Contacts */,
630AE0462CBD7AF30053F8C1 /* Coach */,
A9A3DCC62C75CB8D00FC9B69 /* Firestore */,
2FE5DC2829EDD398004B9AB4 /* Onboarding */,
2FE5DC2D29EDD792004B9AB4 /* Resources */,
Expand Down Expand Up @@ -544,6 +558,7 @@
buildActionMask = 2147483647;
files = (
2FE5DC4129EDD7EE004B9AB4 /* StorageKeys.swift in Sources */,
630AE04B2CBDEA520053F8C1 /* OpenAIAPIKey.swift in Sources */,
2FE5DCB129EE6107004B9AB4 /* AccountOnboarding.swift in Sources */,
2FE5DC3A29EDD7CA004B9AB4 /* Welcome.swift in Sources */,
2FE5DC3829EDD7CA004B9AB4 /* InterestingModules.swift in Sources */,
Expand All @@ -554,6 +569,7 @@
A9A3DCC82C75CBBD00FC9B69 /* FirebaseConfiguration.swift in Sources */,
2FE5DC3729EDD7CA004B9AB4 /* OnboardingFlow.swift in Sources */,
2F1AC9DF2B4E840E00C24973 /* MyHeartCounts.docc in Sources */,
630AE0482CBDB27D0053F8C1 /* CoachChatView.swift in Sources */,
2FF53D8D2A8729D600042B76 /* MyHeartCountsStandard.swift in Sources */,
A9720E432ABB68CC00872D23 /* AccountSetupHeader.swift in Sources */,
2FE5DC4029EDD7EE004B9AB4 /* FeatureFlags.swift in Sources */,
Expand Down
37 changes: 37 additions & 0 deletions MyHeartCounts/Coach/CoachChatView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// CoachChatView.swift
// MyHeartCounts
//
// Created by Vishnu Ravi on 10/14/24.
//

import SpeziChat
import SpeziLLM
import SpeziLLMOpenAI
import SwiftUI

struct CoachChatView: View {
static let schema = LLMOpenAISchema(
parameters: .init(
modelType: .gpt4_o,
systemPrompt: """
You are a health coach that helps people take care of their cardiovascular health.
"""
)
)

@LLMSessionProvider(schema: Self.schema) var llm: LLMOpenAISession
@State var showOnboarding = false
@State var muted = true

var body: some View {
LLMChatView(session: $llm)
.speak(llm.context.chat, muted: muted)
.speechToolbarButton(muted: $muted)
.navigationTitle("Health Coach")
}
}

#Preview {
CoachChatView()
}
6 changes: 6 additions & 0 deletions MyHeartCounts/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct HomeView: View {
enum Tabs: String {
case schedule
case contact
case coach
}


Expand All @@ -28,6 +29,11 @@ struct HomeView: View {
.tabItem {
Label("SCHEDULE_TAB_TITLE", systemImage: "list.clipboard")
}
CoachChatView()
.tag(Tabs.coach)
.tabItem {
Label("Chat", systemImage: "bubble")
}
Contacts(presentingAccount: $presentingAccount)
.tag(Tabs.contact)
.tabItem {
Expand Down
7 changes: 7 additions & 0 deletions MyHeartCounts/MyHeartCountsDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import SpeziFirebaseAccountStorage
import SpeziFirebaseStorage
import SpeziFirestore
import SpeziHealthKit
import SpeziLLM
import SpeziLLMFog
import SpeziLLMOpenAI
import SpeziOnboarding
import SpeziScheduler
import SwiftUI
Expand Down Expand Up @@ -44,6 +47,10 @@ class MyHeartCountsDelegate: SpeziAppDelegate {
FirebaseStorageConfiguration()
}
}

LLMRunner {
LLMOpenAIPlatform()
}

if HKHealthStore.isHealthDataAvailable() {
healthKit
Expand Down
2 changes: 2 additions & 0 deletions MyHeartCounts/Onboarding/OnboardingFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct OnboardingFlow: View {
if !localNotificationAuthorization {
NotificationPermissions()
}

OpenAIAPIKey()
}
.task {
localNotificationAuthorization = await scheduler.localNotificationAuthorization
Expand Down
25 changes: 25 additions & 0 deletions MyHeartCounts/Onboarding/OpenAIAPIKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// OpenAIAPIKey.swift
// MyHeartCounts
//
// Created by Vishnu Ravi on 10/14/24.
//

import SpeziLLM
import SpeziLLMOpenAI
import SpeziOnboarding
import SwiftUI


struct OpenAIAPIKey: View {
@Environment(OnboardingNavigationPath.self) private var onboardingNavigationPath

var body: some View {
LLMOpenAIAPITokenOnboardingStep {
onboardingNavigationPath.nextStep()
}
}
}
#Preview {
OpenAIAPIKey()
}
6 changes: 6 additions & 0 deletions MyHeartCounts/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
}
}
}
},
"Chat" : {

},
"CLOSE" : {
"comment" : "MARK: General",
Expand Down Expand Up @@ -103,6 +106,9 @@
}
}
}
},
"Health Coach" : {

},
"HEALTHKIT_PERMISSIONS_BUTTON" : {
"localizations" : {
Expand Down

0 comments on commit b3a8cda

Please sign in to comment.