Repository navigation
Conversation
✧ When the chat is empty, display tappable example prompts so first-time users see what kinds of questions HealthGPT can answer. Suggestions disappear once the conversation has any messages. ✧ Closes StanfordBDHG#24 ✧ Signed-off-by: Ehan Shah <ehanrsha@gmail.com>
📝 WalkthroughWalkthroughThis PR implements starter query suggestions for empty chat sessions. A new ChangesEmpty Chat Suggestion Flow
Sequence DiagramssequenceDiagram
participant User
participant SuggestionBannerView
participant cycleSuggestions
participant SampleQueries
User->>SuggestionBannerView: View appears
activate cycleSuggestions
SuggestionBannerView->>cycleSuggestions: task starts
loop Rotate suggestions
cycleSuggestions->>SuggestionBannerView: fade out (opacity = 0)
SuggestionBannerView->>SampleQueries: random(excluding previous)
SampleQueries-->>cycleSuggestions: new suggestion
cycleSuggestions->>SuggestionBannerView: update currentSuggestion
cycleSuggestions->>SuggestionBannerView: fade in (opacity = 1)
cycleSuggestions->>cycleSuggestions: wait for interval
end
User->>SuggestionBannerView: tap suggestion pill
SuggestionBannerView->>User: onSuggestionTapped(currentSuggestion)
deactivate cycleSuggestions
sequenceDiagram
participant HealthGPTView
participant chatViewContent
participant isChatEmpty
participant SuggestionBannerView
participant healthDataInterpreter
HealthGPTView->>isChatEmpty: check if chat has messages
isChatEmpty-->>chatViewContent: boolean result
chatViewContent->>chatViewContent: condition on isChatEmpty
alt Chat is empty
chatViewContent->>SuggestionBannerView: render with ZStack overlay
SuggestionBannerView->>SuggestionBannerView: wait for user tap
SuggestionBannerView->>chatViewContent: onSuggestionTapped(query)
chatViewContent->>chatViewContent: append ChatEntity to context
else Chat has messages
chatViewContent->>chatViewContent: render chat messages
end
chatViewContent->>chatViewContent: onChange messageTaskId incremented
chatViewContent->>healthDataInterpreter: queryLLM() on new non-system message
healthDataInterpreter-->>chatViewContent: LLM response or error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
HealthGPT/HealthGPT/HealthGPTView.swift (1)
32-83:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winUnresolved merge conflict markers will break compilation.
Lines 32, 70, and 83 contain Git conflict markers (
<<<<<<< Updated upstream,=======,>>>>>>> Stashed changes). These must be resolved before merging. Based on the PR objectives, you likely want to keep the "Stashed changes" section (the newisChatEmptyproperty and refactoredbody).🐛 Proposed fix to resolve the merge conflict
Remove lines 32-70 and line 83 to keep the new implementation:
-<<<<<<< Updated upstream - var body: some View { - NavigationStack { - if let llm = self.healthDataInterpreter.llm { - let contextBinding = Binding { llm.context.chat } set: { llm.context.chat = $0 } - - ChatView(contextBinding, exportFormat: .text) - .speak(llm.context.chat, muted: !self.textToSpeech) - .speechToolbarButton(muted: !self.$textToSpeech) - .viewStateAlert(state: llm.state) - .navigationTitle("WELCOME_TITLE") - .toolbar { - ToolbarItem(placement: .primaryAction) { - self.settingsButton - } - ToolbarItem(placement: .primaryAction) { - self.resetChatButton - } - } - .onChange(of: llm.context, initial: true) { _, _ in - // Once the user enters a message in the chat, increase `messageTaskId` that triggers LLM inference - if !llm.context.isEmpty && llm.state != .generating && llm.context.last?.role != .system { - self.messageTaskId += 1 - } - } - // Triggered on every new user message in the chat via `messageTaskId` - // Automatically cancels the LLM inference once view disappears - .task(id: self.messageTaskId) { - do { - try await healthDataInterpreter.queryLLM() - } catch { - showErrorAlert = true - errorMessage = "Error querying LLM: \(error.localizedDescription)" - } - } - } else { - self.loadingChatView - } -======= /// Whether the chat has no user or assistant messages yet. /// Controls visibility of the suggestion banner overlay. private var isChatEmpty: Bool { ... } var body: some View { NavigationStack { chatViewContent ->>>>>>> Stashed changes }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@HealthGPT/HealthGPT/HealthGPTView.swift` around lines 32 - 83, Remove the Git conflict markers and the duplicated "Updated upstream" block so the file compiles; keep the "Stashed changes" implementation (the new isChatEmpty property and the refactored var body that uses chatViewContent) and delete the entire <<<<<<< Updated upstream ... ======= ... >>>>>>> Stashed changes section (including the old ChatView-based body that references messageTaskId/llm.context). Ensure only the single isChatEmpty property and the single var body { NavigationStack { chatViewContent } } remain and no conflict markers remain in HealthGPTView.swift.
🧹 Nitpick comments (1)
HealthGPT/HealthGPT/SuggestionBannerView.swift (1)
64-65: 💤 Low valueComment/code timing mismatches.
Several comments don't match the actual timing values:
- Line 64 says "10 seconds" but line 65 uses 7 seconds
- Lines 71 and 86 say "0.4s" but the code uses
duration: 0.6📝 Proposed fix to align comments with code
- // Wait 10 seconds before cycling + // Wait 7 seconds before cycling try? await Task.sleep(for: .seconds(7)) ... - // Phase 1: Fade out (0.4s) + // Phase 1: Fade out (0.6s) withAnimation(.easeInOut(duration: 0.6)) { ... - // Phase 3: Fade in (0.4s) + // Phase 3: Fade in (0.6s) withAnimation(.easeInOut(duration: 0.6)) {Also applies to: 71-72, 86-87
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@HealthGPT/HealthGPT/SuggestionBannerView.swift` around lines 64 - 65, Comments in SuggestionBannerView.swift are out of sync with the actual timing constants; update either the comments or the code so they match. Specifically, reconcile the "Wait 10 seconds before cycling" comment with the Task.sleep call (Task.sleep(for: .seconds(7))): either change the comment to "7 seconds" or change Task.sleep to .seconds(10). Also update the two comments that say "0.4s" to reflect the actual animation duration used (duration: 0.6) or change the duration parameter to 0.4 to match the comments; the relevant symbols to inspect are the Task.sleep(for: .seconds(7)) call and the animation blocks using duration: 0.6.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@HealthGPT/HealthGPT/SuggestionBannerView.swift`:
- Line 19: SuggestionBannerView references SampleQueries.random() and
SampleQueries.random(excluding:) but that type is missing; add a small utility
type (e.g., struct SampleQueries) that exposes a static collection of sample
strings and two static helpers: random() -> String and random(excluding:
String?) -> String (or update the calls to whatever existing provider type you
already have). Implement random(excluding:) to return a random sample different
from the excluded value and call it from SuggestionBannerView where
currentSuggestion is initialized and updated so the view compiles and behavior
remains the same.
---
Outside diff comments:
In `@HealthGPT/HealthGPT/HealthGPTView.swift`:
- Around line 32-83: Remove the Git conflict markers and the duplicated "Updated
upstream" block so the file compiles; keep the "Stashed changes" implementation
(the new isChatEmpty property and the refactored var body that uses
chatViewContent) and delete the entire <<<<<<< Updated upstream ... ======= ...
>>>>>>> Stashed changes section (including the old ChatView-based body that
references messageTaskId/llm.context). Ensure only the single isChatEmpty
property and the single var body { NavigationStack { chatViewContent } } remain
and no conflict markers remain in HealthGPTView.swift.
---
Nitpick comments:
In `@HealthGPT/HealthGPT/SuggestionBannerView.swift`:
- Around line 64-65: Comments in SuggestionBannerView.swift are out of sync with
the actual timing constants; update either the comments or the code so they
match. Specifically, reconcile the "Wait 10 seconds before cycling" comment with
the Task.sleep call (Task.sleep(for: .seconds(7))): either change the comment to
"7 seconds" or change Task.sleep to .seconds(10). Also update the two comments
that say "0.4s" to reflect the actual animation duration used (duration: 0.6) or
change the duration parameter to 0.4 to match the comments; the relevant symbols
to inspect are the Task.sleep(for: .seconds(7)) call and the animation blocks
using duration: 0.6.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8adde90d-7c69-48cd-8188-564c09e5a60f
📒 Files selected for processing (2)
HealthGPT/HealthGPT/HealthGPTView.swiftHealthGPT/HealthGPT/SuggestionBannerView.swift
| let onSuggestionTapped: (String) -> Void | ||
|
|
||
| /// The currently displayed suggestion text. | ||
| @State private var currentSuggestion: String = SampleQueries.random() |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for SampleQueries definition
ast-grep --pattern 'struct SampleQueries {
$$$
}'
ast-grep --pattern 'enum SampleQueries {
$$$
}'
# Also search with rg for any SampleQueries definition
rg -n 'SampleQueries' --type swift -C3Repository: StanfordBDHG/HealthGPT
Length of output: 1306
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate any SampleQueries declarations/definitions and related APIs
rg -n --type swift '(^|\s)(struct|enum|class)\s+SampleQueries\b' .
# Find all references to `SampleQueries.` to inspect which APIs are expected/implemented
rg -n --type swift 'SampleQueries\.' .
# Find any occurrences of `random(` near SampleQueries usage/definitions
rg -n --type swift 'SampleQueries.*random' .
# List files that mention SampleQueries (helps locate where it's defined)
rg -l --type swift '\bSampleQueries\b' .Repository: StanfordBDHG/HealthGPT
Length of output: 48
🏁 Script executed:
#!/bin/bash
set -uo pipefail
# Broader: find ANY mentions of SampleQueries
rg -n --type swift '\bSampleQueries\b' . || true
# Find possible declaration forms (struct/enum/class/static)
rg -n --type swift '((^|\s)(struct|enum|class)\s+SampleQueries\b)|((\bstatic\s+func\b|\bfunc\b)\s+random\b.*\bSampleQueries\b)|(\bSampleQueries\s*=)' . || true
# Find expected API usages explicitly
rg -n --type swift 'SampleQueries\s*\.\s*random\s*\(' . || true
rg -n --type swift 'SampleQueries\s*\.\s*random\s*\(\s*excluding\s*:' . || true
# Find any function named random(excluding:) across repo (to correlate with SampleQueries implementation)
rg -n --type swift '\brandom\s*\(\s*excluding\s*:' . || trueRepository: StanfordBDHG/HealthGPT
Length of output: 858
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect imports / context at top of the file under review
sed -n '1,60p' HealthGPT/HealthGPT/SuggestionBannerView.swift
# Search entire repo (all filetypes) for any SampleQueries declaration/definition hints
rg -n 'SampleQueries' . || true
# Specifically search for potential declaration forms across all filetypes
rg -n '(struct|enum|class)\s+SampleQueries\b|SampleQueries\s*=' . || trueRepository: StanfordBDHG/HealthGPT
Length of output: 2561
Fix missing SampleQueries type/API usage in SuggestionBannerView.
SuggestionBannerView.swift references SampleQueries.random() (line 19) and SampleQueries.random(excluding:) (line ~84), but SampleQueries is not defined anywhere in the repository (repo-wide search for SampleQueries only returns these usages). With only import SwiftUI, this will not compile unless SampleQueries is added or the calls are updated to the correct type/API.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@HealthGPT/HealthGPT/SuggestionBannerView.swift` at line 19,
SuggestionBannerView references SampleQueries.random() and
SampleQueries.random(excluding:) but that type is missing; add a small utility
type (e.g., struct SampleQueries) that exposes a static collection of sample
strings and two static helpers: random() -> String and random(excluding:
String?) -> String (or update the calls to whatever existing provider type you
already have). Implement random(excluding:) to return a random sample different
from the excluded value and call it from SuggestionBannerView where
currentSuggestion is initialized and updated so the view compiles and behavior
remains the same.
|
@vishnuravi Good afternoon! Were you able to review this by any change? Do you have any feedback, or do i need to make any changes? Thank you. ✧ Created A Video Demonstrating The Addition -> https://drive.google.com/file/d/1QnNQ4cw0hT9HTUWk4DZHG_FmUZxRZUuQ/view?usp=sharing |
|
Hi @ehanrsha thanks so much for the code contribution. I'll try this out and get back to you shortly! |
Good evening @vishnuravi Dr. Ravi, |
✧ When the chat is empty, display tappable example prompts so first-time users see what kinds of questions HealthGPT can answer. Suggestions disappear once the conversation has any messages.
✧ Closes #24
✧ Signed-off-by: Ehan Shah ehanrsha@gmail.com
✧ Created A Video Demonstrating The Addition -> https://drive.google.com/file/d/1QnNQ4cw0hT9HTUWk4DZHG_FmUZxRZUuQ/view?usp=sharing