-
Notifications
You must be signed in to change notification settings - Fork 352
Ios demo polish #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Ios demo polish #454
Changes from 4 commits
fe562c8
bb77403
13dc851
4a6150f
e2ab620
8aab1fa
c9c6ca6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ struct ChatInterfaceView: View { | |
| @State private var showingLoRAManagement = false | ||
| @State private var pendingLoRAURL: URL? | ||
| @State private var loraScale: Float = 1.0 | ||
| @ObservedObject private var toolSettingsViewModel = ToolSettingsViewModel.shared | ||
| @AppStorage("thinkingModeEnabled") private var thinkingModeEnabled = false | ||
|
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid a second source of truth for thinking mode.
Suggested direction- `@ObservedObject` private var toolSettingsViewModel = ToolSettingsViewModel.shared
- `@AppStorage`("thinkingModeEnabled") private var thinkingModeEnabled = false
+ `@ObservedObject` private var toolSettingsViewModel = ToolSettingsViewModel.shared
+ `@ObservedObject` private var settingsViewModel = SettingsViewModel.shared
...
- if thinkingModeEnabled && viewModel.loadedModelSupportsThinking {
+ if settingsViewModel.thinkingModeEnabled && viewModel.loadedModelSupportsThinking {
thinkingModeBadge
}
...
- .padding(.top, ((thinkingModeEnabled && viewModel.loadedModelSupportsThinking) || viewModel.useToolCalling || !viewModel.loraAdapters.isEmpty || hasModelSelected) ? 8 : 0)
+ .padding(.top, ((settingsViewModel.thinkingModeEnabled && viewModel.loadedModelSupportsThinking) || viewModel.useToolCalling || !viewModel.loraAdapters.isEmpty || hasModelSelected) ? 8 : 0)
...
var thinkingModeBadge: some View {
Button {
- thinkingModeEnabled.toggle()
+ settingsViewModel.thinkingModeEnabled.toggle()
} label: {Also applies to: 502-518 🤖 Prompt for AI Agents |
||
| @FocusState private var isTextFieldFocused: Bool | ||
|
|
||
| private let logger = Logger( | ||
|
|
@@ -369,8 +371,8 @@ extension ChatInterfaceView { | |
| .onReceive( | ||
| NotificationCenter.default.publisher(for: Notification.Name("MessageContentUpdated")) | ||
| ) { _ in | ||
| if viewModel.isGenerating { | ||
| proxy.scrollTo("typing", anchor: .bottom) | ||
| if viewModel.isGenerating, let lastMessage = viewModel.messages.last { | ||
| proxy.scrollTo(lastMessage.id, anchor: .bottom) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -412,7 +414,7 @@ extension ChatInterfaceView { | |
| .animation(nil, value: message.content) | ||
| } | ||
|
|
||
| if viewModel.isGenerating { | ||
| if viewModel.isGenerating, viewModel.messages.last?.content.isEmpty == true { | ||
| TypingIndicatorView() | ||
| .id("typing") | ||
| .transition(typingTransition) | ||
|
|
@@ -445,9 +447,13 @@ extension ChatInterfaceView { | |
| VStack(spacing: 0) { | ||
| Divider() | ||
|
|
||
| // Status badges (tool calling + LoRA) | ||
| // Status badges (thinking mode + tool calling + LoRA) | ||
| HStack(spacing: 8) { | ||
| if viewModel.useToolCalling { | ||
| if thinkingModeEnabled && viewModel.loadedModelSupportsThinking { | ||
| thinkingModeBadge | ||
| } | ||
|
|
||
| if viewModel.useToolCalling && !toolSettingsViewModel.registeredTools.isEmpty { | ||
| toolCallingBadge | ||
| } | ||
|
|
||
|
|
@@ -459,7 +465,7 @@ extension ChatInterfaceView { | |
| loraAddButton | ||
| } | ||
| } | ||
| .padding(.top, (viewModel.useToolCalling || !viewModel.loraAdapters.isEmpty || hasModelSelected) ? 8 : 0) | ||
| .padding(.top, ((thinkingModeEnabled && viewModel.loadedModelSupportsThinking) || viewModel.useToolCalling || !viewModel.loraAdapters.isEmpty || hasModelSelected) ? 8 : 0) | ||
|
|
||
| HStack(spacing: AppSpacing.mediumLarge) { | ||
| TextField("Type a message...", text: $viewModel.currentInput, axis: .vertical) | ||
|
|
@@ -493,6 +499,24 @@ extension ChatInterfaceView { | |
| } | ||
| } | ||
|
|
||
| var thinkingModeBadge: some View { | ||
| Button { | ||
| thinkingModeEnabled.toggle() | ||
| } label: { | ||
| HStack(spacing: 6) { | ||
| Image(systemName: "lightbulb.min.fill") | ||
| .font(.system(size: 10)) | ||
| Text("Thinking") | ||
| .font(AppTypography.caption2) | ||
| } | ||
| .foregroundColor(AppColors.primaryPurple) | ||
| .padding(.horizontal, 10) | ||
| .padding(.vertical, 4) | ||
| .background(AppColors.primaryPurple.opacity(0.1)) | ||
| .cornerRadius(6) | ||
| } | ||
| } | ||
|
|
||
| var toolCallingBadge: some View { | ||
| HStack(spacing: 6) { | ||
| Image(systemName: "wrench.and.screwdriver") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip no-op UI updates while the model is still inside
<think>.stripThinkTagscan keepdisplayTextunchanged for many hidden tokens, but this loop still rebuilds the message and posts a scroll notification on every token. On long thinking traces that becomes avoidable main-thread churn.Suggested simplification
func generateStreamingResponse( prompt: String, options: LLMGenerationOptions, messageIndex: Int ) async throws { var fullResponse = "" + var lastDisplayText = "" let streamingResult = try await RunAnywhere.generateStream(prompt, options: options) let stream = streamingResult.stream let metricsTask = streamingResult.result for try await token in stream { fullResponse += token let displayText = Self.stripThinkTags(from: fullResponse) + guard displayText != lastDisplayText else { continue } + lastDisplayText = displayText await updateMessageContent(at: messageIndex, content: displayText) NotificationCenter.default.post( name: Notification.Name("MessageContentUpdated"), object: nil )📝 Committable suggestion
🤖 Prompt for AI Agents