Skip to content

Commit

Permalink
Merge branch 'main' of github.com:AugustDev/enchanted-ios-llm
Browse files Browse the repository at this point in the history
  • Loading branch information
gluonfield committed Mar 12, 2024
2 parents bccb0ec + 54cf859 commit d4c570b
Show file tree
Hide file tree
Showing 27 changed files with 334 additions and 109 deletions.
33 changes: 29 additions & 4 deletions Enchanted.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
FF1002752B278C170011A4DC /* AppStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF1002742B278C170011A4DC /* AppStore.swift */; };
FF10027A2B27B6070011A4DC /* MarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = FF1002792B27B6070011A4DC /* MarkdownUI */; };
FF15EF6A2B826C0300D4A541 /* SimpleFloatingButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF15EF692B826C0300D4A541 /* SimpleFloatingButton.swift */; };
FF1BC3C52BA0753400A58043 /* Splash in Frameworks */ = {isa = PBXBuildFile; productRef = FF1BC3C42BA0753400A58043 /* Splash */; };
FF1BC3C72BA0757700A58043 /* SplashSyntaxHighlighter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF1BC3C62BA0757700A58043 /* SplashSyntaxHighlighter+Extension.swift */; };
FF24B30E2B66BE8500AB618F /* RunningBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF24B30D2B66BE8500AB618F /* RunningBorder.swift */; };
FF2F03422B795E0B00349855 /* Clipboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF2F03412B795E0B00349855 /* Clipboard.swift */; };
FF2F03442B79631800349855 /* Button+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF2F03432B79631800349855 /* Button+Extension.swift */; };
Expand Down Expand Up @@ -76,6 +78,7 @@
FFD5FAD52B8130CE0055AB51 /* OllamaKit in Frameworks */ = {isa = PBXBuildFile; productRef = FFD5FAD42B8130CE0055AB51 /* OllamaKit */; };
FFE21C782B82353A00A69B9C /* SleepTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFE21C772B82353A00A69B9C /* SleepTest.swift */; };
FFE2C8232B9A657A00BD82F3 /* Accessibility.plist in Resources */ = {isa = PBXBuildFile; fileRef = FFE2C8222B9A657A00BD82F3 /* Accessibility.plist */; };
FFEB9CA82BA04304004B1F3D /* NotificationMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEB9CA72BA04304004B1F3D /* NotificationMessage.swift */; };
FFEC32912B24779A003E5C04 /* EnchantedApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFEC32902B24779A003E5C04 /* EnchantedApp.swift */; };
FFEC32972B24779B003E5C04 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FFEC32962B24779B003E5C04 /* Assets.xcassets */; };
FFEC329B2B24779B003E5C04 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FFEC329A2B24779B003E5C04 /* Preview Assets.xcassets */; };
Expand Down Expand Up @@ -115,6 +118,7 @@
FF1002722B276EC10011A4DC /* AppColorScheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppColorScheme.swift; sourceTree = "<group>"; };
FF1002742B278C170011A4DC /* AppStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStore.swift; sourceTree = "<group>"; };
FF15EF692B826C0300D4A541 /* SimpleFloatingButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleFloatingButton.swift; sourceTree = "<group>"; };
FF1BC3C62BA0757700A58043 /* SplashSyntaxHighlighter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SplashSyntaxHighlighter+Extension.swift"; sourceTree = "<group>"; };
FF24B30D2B66BE8500AB618F /* RunningBorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunningBorder.swift; sourceTree = "<group>"; };
FF2F03412B795E0B00349855 /* Clipboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clipboard.swift; sourceTree = "<group>"; };
FF2F03432B79631800349855 /* Button+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Button+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -155,6 +159,7 @@
FFBBF48B2B35051D008D611C /* UIImage+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Extension.swift"; sourceTree = "<group>"; };
FFE21C772B82353A00A69B9C /* SleepTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepTest.swift; sourceTree = "<group>"; };
FFE2C8222B9A657A00BD82F3 /* Accessibility.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Accessibility.plist; sourceTree = "<group>"; };
FFEB9CA72BA04304004B1F3D /* NotificationMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationMessage.swift; sourceTree = "<group>"; };
FFEC328D2B24779A003E5C04 /* Enchanted.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Enchanted.app; sourceTree = BUILT_PRODUCTS_DIR; };
FFEC32902B24779A003E5C04 /* EnchantedApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnchantedApp.swift; sourceTree = "<group>"; };
FFEC32962B24779B003E5C04 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -174,6 +179,7 @@
buildActionMask = 2147483647;
files = (
FFFD00C62B94CA1300392AE6 /* Magnet in Frameworks */,
FF1BC3C52BA0753400A58043 /* Splash in Frameworks */,
FFD5FAD52B8130CE0055AB51 /* OllamaKit in Frameworks */,
FFD5FAD22B8130490055AB51 /* Vortex in Frameworks */,
FF10027A2B27B6070011A4DC /* MarkdownUI in Frameworks */,
Expand Down Expand Up @@ -433,6 +439,7 @@
FFBBF48B2B35051D008D611C /* UIImage+Extension.swift */,
FFBBF4872B34F9C8008D611C /* View+Extension.swift */,
FFB21A862B7BD0BA00D148A4 /* KeyboardReadable+Extension.swift */,
FF1BC3C62BA0757700A58043 /* SplashSyntaxHighlighter+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand All @@ -443,6 +450,7 @@
FF10025D2B2648460011A4DC /* ConversationState.swift */,
FF1002722B276EC10011A4DC /* AppColorScheme.swift */,
FF7FBE4B2B78E384000901F7 /* SamplePrompt.swift */,
FFEB9CA72BA04304004B1F3D /* NotificationMessage.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -516,6 +524,7 @@
FFFD00C52B94CA1300392AE6 /* Magnet */,
FFFD00C82B94CB5E00392AE6 /* AsyncAlgorithms */,
FF911DF02B98F08800915E94 /* WrappingHStack */,
FF1BC3C42BA0753400A58043 /* Splash */,
);
productName = Enchanted;
productReference = FFEC328D2B24779A003E5C04 /* Enchanted.app */;
Expand Down Expand Up @@ -553,6 +562,7 @@
FFFD00C42B94CA1300392AE6 /* XCRemoteSwiftPackageReference "Magnet" */,
FFFD00C72B94CB5E00392AE6 /* XCRemoteSwiftPackageReference "swift-async-algorithms" */,
FF911DEF2B98F08800915E94 /* XCRemoteSwiftPackageReference "WrappingHStack" */,
FF1BC3C32BA0753400A58043 /* XCRemoteSwiftPackageReference "Splash" */,
);
productRefGroup = FFEC328E2B24779A003E5C04 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -592,6 +602,7 @@
FF1002302B2482BA0011A4DC /* ChatMessageView.swift in Sources */,
FF1002322B2483A20011A4DC /* Colours+Extension.swift in Sources */,
FFB21A872B7BD0BA00D148A4 /* KeyboardReadable+Extension.swift in Sources */,
FF1BC3C72BA0757700A58043 /* SplashSyntaxHighlighter+Extension.swift in Sources */,
FF33066E2B83CFEC007B33E5 /* KeyboardShortcuts.swift in Sources */,
FF66A51D2B76949A00FAAC1E /* Helpers.swift in Sources */,
FF10026A2B2731C60011A4DC /* ModelSelectorView.swift in Sources */,
Expand All @@ -613,6 +624,7 @@
FF38F8512B7A919C00546B56 /* MenuBarControl_macOS.swift in Sources */,
FF38F85A2B7AB28300546B56 /* PromptPanelView.swift in Sources */,
FF1002462B25BCE70011A4DC /* LanguageModelStore.swift in Sources */,
FFEB9CA82BA04304004B1F3D /* NotificationMessage.swift in Sources */,
FF10025C2B2625BE0011A4DC /* SidebarView.swift in Sources */,
FF1002392B24BBF20011A4DC /* Chat.swift in Sources */,
FFB0327D2B312F3D0066A9DB /* RecordingView.swift in Sources */,
Expand Down Expand Up @@ -782,7 +794,7 @@
CODE_SIGN_ENTITLEMENTS = Enchanted/Enchanted.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Enchanted/Preview Content\"";
DEVELOPMENT_TEAM = JDDZ55DT74;
Expand All @@ -808,7 +820,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.5.4;
MARKETING_VERSION = 1.5.5;
PRODUCT_BUNDLE_IDENTIFIER = subj.Enchanted;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -831,7 +843,7 @@
CODE_SIGN_ENTITLEMENTS = Enchanted/Enchanted.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 14;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Enchanted/Preview Content\"";
DEVELOPMENT_TEAM = JDDZ55DT74;
Expand All @@ -857,7 +869,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.5.4;
MARKETING_VERSION = 1.5.5;
PRODUCT_BUNDLE_IDENTIFIER = subj.Enchanted;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -911,6 +923,14 @@
minimumVersion = 2.2.0;
};
};
FF1BC3C32BA0753400A58043 /* XCRemoteSwiftPackageReference "Splash" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/JohnSundell/Splash";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.16.0;
};
};
FF464B112B8026DA008E5130 /* XCRemoteSwiftPackageReference "Vortex" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/twostraws/Vortex";
Expand Down Expand Up @@ -964,6 +984,11 @@
package = FF1002782B27B6070011A4DC /* XCRemoteSwiftPackageReference "swift-markdown-ui" */;
productName = MarkdownUI;
};
FF1BC3C42BA0753400A58043 /* Splash */ = {
isa = XCSwiftPackageProductDependency;
package = FF1BC3C32BA0753400A58043 /* XCRemoteSwiftPackageReference "Splash" */;
productName = Splash;
};
FF464B122B8026DA008E5130 /* Vortex */ = {
isa = XCSwiftPackageProductDependency;
package = FF464B112B8026DA008E5130 /* XCRemoteSwiftPackageReference "Vortex" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "5ab8135bb7491a11d5d5f5e45e52eedcdb6d5d9cc31b72a44d00105aef626d9a",
"originHash" : "296b8f815386856ae8cad4b4d35d8e4f655586b0d27111939442184e40904bd0",
"pins" : [
{
"identity" : "activityindicatorview",
Expand Down Expand Up @@ -43,7 +43,7 @@
"location" : "https://github.com/AugustDev/OllamaKit",
"state" : {
"branch" : "main",
"revision" : "d9284533d59c0c0241120baec9f082246e3e37d6"
"revision" : "487bbb54e2f7dc8ea09d8542e21899376c89602d"
}
},
{
Expand All @@ -55,6 +55,15 @@
"version" : "2.4.0"
}
},
{
"identity" : "splash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/JohnSundell/Splash",
"state" : {
"revision" : "7f4df436eb78fe64fe2c32c58006e9949fa28ad8",
"version" : "0.16.0"
}
},
{
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableThreadSanitizer = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
11 changes: 8 additions & 3 deletions Enchanted/Application/EnchantedApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftData

@main
struct EnchantedApp: App {
@State private var appStore = AppStore.shared
#if os(macOS)
@NSApplicationDelegateAdaptor(PanelManager.self) var panelManager
#endif
Expand All @@ -30,14 +31,18 @@ struct EnchantedApp: App {
#endif

#if os(macOS)
#if false
//#if false
MenuBarExtra {
MenuBarControl()
} label: {
MenuBarControlView.icon
if let iconName = appStore.menuBarIcon {
Image(systemName: iconName)
} else {
MenuBarControlView.icon
}
}
.menuBarExtraStyle(.window)
#endif
//#endif
#endif
}
}
Expand Down
2 changes: 0 additions & 2 deletions Enchanted/Enchanted.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.temporary-exception.apple-events</key>
<true/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
Expand Down
75 changes: 75 additions & 0 deletions Enchanted/Extensions/SplashSyntaxHighlighter+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// SplashSyntaxHighlighter+Extension.swift
// Enchanted
//
// Created by Augustinas Malinauskas on 12/03/2024.
//

import MarkdownUI
import Splash
import SwiftUI

struct SplashCodeSyntaxHighlighter: CodeSyntaxHighlighter {
private let syntaxHighlighter: SyntaxHighlighter<TextOutputFormat>

init(theme: Splash.Theme) {
self.syntaxHighlighter = SyntaxHighlighter(format: TextOutputFormat(theme: theme))
}

func highlightCode(_ content: String, language: String?) -> Text {
guard language != nil else {
return Text(content)
}

return self.syntaxHighlighter.highlight(content)
}
}

extension CodeSyntaxHighlighter where Self == SplashCodeSyntaxHighlighter {
static func splash(theme: Splash.Theme) -> Self {
SplashCodeSyntaxHighlighter(theme: theme)
}
}

struct TextOutputFormat: OutputFormat {
private let theme: Splash.Theme

init(theme: Splash.Theme) {
self.theme = theme
}

func makeBuilder() -> Builder {
Builder(theme: self.theme)
}
}

extension TextOutputFormat {
struct Builder: OutputBuilder {
private let theme: Splash.Theme
private var accumulatedText: [Text]

fileprivate init(theme: Splash.Theme) {
self.theme = theme
self.accumulatedText = []
}

mutating func addToken(_ token: String, ofType type: TokenType) {
let color = self.theme.tokenColors[type] ?? self.theme.plainTextColor
self.accumulatedText.append(Text(token).foregroundColor(.init(color)))
}

mutating func addPlainText(_ text: String) {
self.accumulatedText.append(
Text(text).foregroundColor(.init(self.theme.plainTextColor))
)
}

mutating func addWhitespace(_ whitespace: String) {
self.accumulatedText.append(Text(whitespace))
}

func build() -> Text {
self.accumulatedText.reduce(Text(""), +)
}
}
}
3 changes: 1 addition & 2 deletions Enchanted/Helpers/Accessibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AppKit
import ApplicationServices
import CoreGraphics

class Accessibility {
final class Accessibility {
static let shared = Accessibility()

/// Check if Enchanted has the right permissions
Expand All @@ -20,7 +20,6 @@ class Accessibility {
return AXIsProcessTrustedWithOptions(options as CFDictionary)
}

@MainActor
func showAccessibilityInstructionsWindow() {
if checkAccessibility() {
return
Expand Down
28 changes: 28 additions & 0 deletions Enchanted/Models/NotificationMessage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// NotificationMessage.swift
// Enchanted
//
// Created by Augustinas Malinauskas on 12/03/2024.
//

import Foundation

struct NotificationMessage: Identifiable {
var id = UUID()
var message: String
var status: Status
var timestamp = Date()

enum Status {
case error
case info
}
}

// MARK: Sample data
extension NotificationMessage {
static let sample: [NotificationMessage] = [
.init(message: "Querying ollama", status: .info),
.init(message: "Window changed. Stopping writing.", status: .info)
]
}
10 changes: 5 additions & 5 deletions Enchanted/Services/OllamaService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ class OllamaService: @unchecked Sendable {
initEndpoint()
}

func initEndpoint(url: String? = nil) {
func initEndpoint(url: String? = nil, bearerToken: String? = "okki") {
let defaultUrl = "http://localhost:11434"
let localStorageUrl = UserDefaults.standard.string(forKey: "ollamaUri")
let bearerToken = UserDefaults.standard.string(forKey: "ollamaBearerToken")
if var ollamaUrl = [localStorageUrl, defaultUrl].compactMap({$0}).filter({$0.count > 0}).first {
if !ollamaUrl.contains("http") {
ollamaUrl = "http://" + ollamaUrl
}

if let url = URL(string: ollamaUrl) {
ollamaKit = OllamaKit(baseURL: url)
ollamaKit = OllamaKit(baseURL: url, bearerToken: bearerToken)
return
}
}
}

func getModels() async throws -> [LanguageModelSD] {
func getModels() async throws -> [String] {
let response = try await ollamaKit.models()
let models = response.models.map{model in LanguageModelSD(name: model.name)}
return models
return response.models.map{$0.name}
}

func reachable() async -> Bool {
Expand Down
Loading

0 comments on commit d4c570b

Please sign in to comment.