Skip to content

Commit 868334d

Browse files
authored
[iOS] correct mistral q3 url and handle screen switch off (#2529)
This PR corrects the mistral q3 url This PR also add a handler for screen switch off. For now we just reset if the app is generating, we will update to pause/resume once they are supported.
1 parent 69c600c commit 868334d

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

ios/MLCChat/MLCChat.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@
415415
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
416416
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
417417
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
418+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
418419
LD_RUNPATH_SEARCH_PATHS = (
419420
"$(inherited)",
420421
"@executable_path/Frameworks",
@@ -467,6 +468,7 @@
467468
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
468469
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
469470
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
471+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
470472
LD_RUNPATH_SEARCH_PATHS = (
471473
"$(inherited)",
472474
"@executable_path/Frameworks",

ios/MLCChat/MLCChat/States/ChatState.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ final class ChatState: ObservableObject {
8787
})
8888
}
8989

90+
// reset the chat if we switch to background
91+
// during generation to avoid permission issue
92+
func requestSwitchToBackground() {
93+
if (getModelChatState() == .generating) {
94+
self.requestResetChat()
95+
}
96+
}
97+
98+
9099
func requestTerminateChat(callback: @escaping () -> Void) {
91100
assert(isInterruptible)
92101
interruptChat(prologue: {

ios/MLCChat/MLCChat/Views/ChatView.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import GameController
88

99
struct ChatView: View {
1010
@EnvironmentObject private var chatState: ChatState
11-
11+
@Environment(\.scenePhase) var scenePhase
1212
@State private var inputMessage: String = ""
1313
@FocusState private var inputIsFocused: Bool
1414
@Environment(\.dismiss) private var dismiss
@@ -20,7 +20,7 @@ struct ChatView: View {
2020
@State private var imageConfirmed: Bool = false
2121
@State private var imageSourceType: UIImagePickerController.SourceType = .photoLibrary
2222
@State private var image: UIImage?
23-
23+
2424
var body: some View {
2525
VStack {
2626
modelInfoView
@@ -30,6 +30,11 @@ struct ChatView: View {
3030
}
3131
.navigationBarTitle("MLC Chat: \(chatState.displayName)", displayMode: .inline)
3232
.navigationBarBackButtonHidden()
33+
.onChange(of: scenePhase) { oldPhase, newPhase in
34+
if newPhase == .background {
35+
self.chatState.requestSwitchToBackground()
36+
}
37+
}
3338
.toolbar {
3439
ToolbarItem(placement: .navigationBarLeading) {
3540
Button {
@@ -50,6 +55,7 @@ struct ChatView: View {
5055
.disabled(!chatState.isResettable)
5156
}
5257
}
58+
5359
}
5460
}
5561

ios/MLCChat/mlc-package-config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
}
2929
},
3030
{
31-
"model": "HF://mlc-ai/Mistral-7B-Instruct-v0.3-q4f16_1-MLC",
31+
"model": "HF://mlc-ai/Mistral-7B-Instruct-v0.3-q3f16_1-MLC",
3232
"model_id": "Mistral-7B-Instruct-v0.3-q3f16_1-MLC",
3333
"estimated_vram_bytes": 3316000000,
3434
"overrides": {
35-
"prefill_chunk_size": 128
35+
"prefill_chunk_size": 128,
36+
"context_window_size": 768
3637
}
3738
}
3839
]

0 commit comments

Comments
 (0)