Skip to content
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

Adds support for on-device LLMs with SpeziLLMLocal #39

Merged
merged 14 commits into from
May 13, 2024
Prev Previous commit
Next Next commit
Remove redundant extensions
vishnuravi committed Apr 4, 2024
commit 9a3083708f4eacfc7e3ea6c3a3ca7d46fa80f52f
54 changes: 2 additions & 52 deletions HealthGPT/HealthGPT/HealthGPTView.swift
Original file line number Diff line number Diff line change
@@ -28,10 +28,10 @@
var body: some View {
NavigationStack {
if let llm = healthDataInterpreter.llm {
let contextBinding = Binding { llm.context.chatEntity } set: { llm.context = $0.llmContextEntity }
let contextBinding = Binding { llm.context.chat } set: { llm.context.chat = $0 }

ChatView(contextBinding, exportFormat: .text)
.speak(llm.context.chatEntity, muted: !textToSpeech)
.speak(llm.context.chat, muted: !textToSpeech)
.speechToolbarButton(muted: !$textToSpeech)
.viewStateAlert(state: llm.state)
.navigationTitle("WELCOME_TITLE")
@@ -71,7 +71,7 @@
if FeatureFlags.mockMode {
await healthDataInterpreter.prepareLLM(with: LLMMockSchema())
} else if FeatureFlags.localLLM || llmSource == .local {
await healthDataInterpreter.prepareLLM(with: LLMLocalSchema(modelPath: .cachesDirectory.appending(path: "llm.gguf")))

Check warning on line 74 in HealthGPT/HealthGPT/HealthGPTView.swift

Codecov / codecov/patch

HealthGPT/HealthGPT/HealthGPTView.swift#L74

Added line #L74 was not covered by tests
} else {
await healthDataInterpreter.prepareLLM(with: LLMOpenAISchema(parameters: .init(modelType: openAIModel)))
}
@@ -113,53 +113,3 @@
}
}
}

extension Array where Element == LLMContextEntity {
var chatEntity: [ChatEntity] {
self.map { llmContextEntity in
let role: ChatEntity.Role

switch llmContextEntity.role {
case .user:
role = .user
case .assistant:
role = .assistant
case .system, .tool:
role = .hidden(type: .unknown)
}

return ChatEntity(
role: role,
content: llmContextEntity.content,
complete: llmContextEntity.complete,
id: llmContextEntity.id,
date: llmContextEntity.date
)
}
}
}

extension Array where Element == ChatEntity {
var llmContextEntity: [LLMContextEntity] {
self.map { chatEntity in
let role: LLMContextEntity.Role

switch chatEntity.role {
case .user:
role = .user
case .assistant:
role = .assistant()
case .hidden:
role = .system
}

return LLMContextEntity(
role: role,
content: chatEntity.content,
complete: chatEntity.complete,
id: chatEntity.id,
date: chatEntity.date
)
}
}
}
1 change: 1 addition & 0 deletions HealthGPT/Onboarding/LLMSource.swift
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
//

import Foundation
import SpeziLLMOpenAI


enum LLMSource: String, CaseIterable, Identifiable, Codable {
Loading