diff --git a/HealthGPT/HealthGPT/HealthDataInterpreter.swift b/HealthGPT/HealthGPT/HealthDataInterpreter.swift index a794b52..5c1bcf1 100644 --- a/HealthGPT/HealthGPT/HealthDataInterpreter.swift +++ b/HealthGPT/HealthGPT/HealthDataInterpreter.swift @@ -32,10 +32,13 @@ class HealthDataInterpreter: DefaultInitializable, Module, EnvironmentAccessible /// /// - Parameter schema: the LLMSchema to use @MainActor - func prepareLLM(with schema: any LLMSchema) async { + func prepareLLM(with schema: any LLMSchema) async throws { let llm = llmRunner(with: schema) systemPrompt = await generateSystemPrompt() llm.context.append(systemMessage: systemPrompt) + if let localLLM = llm as? LLMLocalSession { + try await localLLM.setup() + } self.llm = llm } diff --git a/HealthGPT/HealthGPT/HealthGPTView.swift b/HealthGPT/HealthGPT/HealthGPTView.swift index 6c536a6..bbb32bb 100644 --- a/HealthGPT/HealthGPT/HealthGPTView.swift +++ b/HealthGPT/HealthGPT/HealthGPTView.swift @@ -68,12 +68,17 @@ struct HealthGPTView: View { Text(errorMessage) } .task { - if FeatureFlags.mockMode { - await healthDataInterpreter.prepareLLM(with: LLMMockSchema()) - } else if FeatureFlags.localLLM || llmSource == .local { - await healthDataInterpreter.prepareLLM(with: LLMLocalSchema(model: .llama3_8B_4bit)) - } else { - await healthDataInterpreter.prepareLLM(with: LLMOpenAISchema(parameters: .init(modelType: openAIModel))) + do { + if FeatureFlags.mockMode { + try await healthDataInterpreter.prepareLLM(with: LLMMockSchema()) + } else if FeatureFlags.localLLM || llmSource == .local { + try await healthDataInterpreter.prepareLLM(with: LLMLocalSchema(model: .llama3_8B_4bit)) + } else { + try await healthDataInterpreter.prepareLLM(with: LLMOpenAISchema(parameters: .init(modelType: openAIModel))) + } + } catch { + showErrorAlert = true + errorMessage = "Error querying LLM: \(error.localizedDescription)" } } } diff --git a/HealthGPT/HealthGPT/SettingsView.swift b/HealthGPT/HealthGPT/SettingsView.swift index 15d5333..129dfda 100644 --- a/HealthGPT/HealthGPT/SettingsView.swift +++ b/HealthGPT/HealthGPT/SettingsView.swift @@ -106,7 +106,7 @@ struct SettingsView: View { ) { model in Task { openAIModel = model - await healthDataInterpreter.prepareLLM(with: LLMOpenAISchema(parameters: .init(modelType: model))) + try? await healthDataInterpreter.prepareLLM(with: LLMOpenAISchema(parameters: .init(modelType: model))) path.removeLast() } } diff --git a/HealthGPT/Supporting Files/HealthGPT.entitlements b/HealthGPT/Supporting Files/HealthGPT.entitlements index dab226c..ee45c67 100644 --- a/HealthGPT/Supporting Files/HealthGPT.entitlements +++ b/HealthGPT/Supporting Files/HealthGPT.entitlements @@ -8,5 +8,7 @@ com.apple.developer.healthkit.background-delivery + com.apple.developer.kernel.increased-memory-limit +