├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── Package.resolved ├── Package.swift ├── README.md ├── Sources └── SwiftLlama │ ├── LlamaModel.swift │ ├── Models │ ├── Batch.swift │ ├── Chat.swift │ ├── Configuration.swift │ ├── Prompt.swift │ ├── Session.swift │ ├── StopToken.swift │ ├── SwiftLlamaError.swift │ └── TypeAlias.swift │ ├── Swiftllama.swift │ └── SwiftllamaActor.swift ├── TestProjects ├── README.md ├── Shared │ ├── ContentView.swift │ └── ViewModel.swift ├── TestApp-Commandline │ └── main.swift ├── TestApp-Macos │ ├── Assets.xcassets │ │ ├── AccentColor.colorset │ │ │ └── Contents.json │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Preview Content │ │ └── Preview Assets.xcassets │ │ │ └── Contents.json │ ├── TestApp_Macos.entitlements │ └── TestApp_MacosApp.swift ├── TestApp-iOS │ ├── Assets.xcassets │ │ ├── AccentColor.colorset │ │ │ └── Contents.json │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Preview Content │ │ └── Preview Assets.xcassets │ │ │ └── Contents.json │ └── TestApp_iOSApp.swift └── TestApp.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── swiftpm │ │ └── Package.resolved │ └── xcshareddata │ └── xcschemes │ ├── TestApp-Commandline.xcscheme │ └── TestApp-iOS.xcscheme └── Tests └── SwiftLlamaTests └── SwiftLlamaTests.swift /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [ShenghaiWang] 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | xcuserdata/ 5 | DerivedData/ 6 | .swiftpm/configuration/registries.json 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | .netrc 9 | TestProjects/Shared/Models/llama-2-7b.Q4_K_M.gguf 10 | IDEWorkspaceChecks.plist -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Tim Wang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "llama.cpp", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/ggerganov/llama.cpp/", 7 | "state" : { 8 | "branch" : "master", 9 | "revision" : "b6d6c5289f1c9c677657c380591201ddb210b649" 10 | } 11 | } 12 | ], 13 | "version" : 2 14 | } 15 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 6.0 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "SwiftLlama", 7 | platforms: [ 8 | .macOS(.v15), 9 | .iOS(.v18), 10 | .watchOS(.v11), 11 | .tvOS(.v18), 12 | .visionOS(.v2) 13 | ], 14 | products: [ 15 | .library(name: "SwiftLlama", targets: ["SwiftLlama"]), 16 | ], 17 | dependencies: [ 18 | .package(url: "https://github.com/ggerganov/llama.cpp.git", branch: "master") 19 | ], 20 | targets: [ 21 | .target(name: "SwiftLlama", 22 | dependencies: [ 23 | .product(name: "llama", package: "llama.cpp") 24 | ]), 25 | .testTarget(name: "SwiftLlamaTests", dependencies: ["SwiftLlama"]), 26 | ] 27 | ) 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftLlama 2 | 3 | This is basically a wrapper of [llama.cpp](https://github.com/ggerganov/llama.cpp.git) package 4 | and the purpose of this repo is to provide a swiftier API for Swift developers. 5 | 6 | ## Install 7 | 8 | .package(url: "https://github.com/ShenghaiWang/SwiftLlama.git", from: "0.3.0") 9 | 10 | ## Usage 11 | 12 | ### 1 Initialise swiftLlama using model path. 13 | 14 | let swiftLlama = try SwiftLlama(modelPath: path)) 15 | 16 | ### 2 Call it 17 | 18 | ### Call without streaming 19 | 20 | let response: String = try await swiftLlama.start(for: prompt) 21 | 22 | #### Using AsyncStream for streaming 23 | 24 | for try await value in await swiftLlama.start(for: prompt) { 25 | result += value 26 | } 27 | 28 | #### Using Combine publisher for streaming 29 | 30 | await swiftLlama.start(for: prompt) 31 | .sink { _ in 32 | 33 | } receiveValue: {[weak self] value in 34 | self?.result += value 35 | }.store(in: &cancallable) 36 | 37 | ## Test projects 38 | 39 | [This video](https://youtu.be/w1VEM00cJWo) was the command line app running with Llama 3 model. 40 | 41 | For using it in iOS or MacOS app, please refer to the [TestProjects](https://github.com/ShenghaiWang/SwiftLlama/tree/main/TestProjects) folder. 42 | 43 | 44 | ## Supported Models 45 | 46 | In theory, it should support all the models that llama.cpp suports. However, the prompt format might need to be updated for some models. 47 | 48 | If you want to test it out quickly, please use this model [codellama-7b-instruct.Q4_K_S.gguf](https://huggingface.co/TheBloke/CodeLlama-7B-Instruct-GGUF/resolve/main/codellama-7b-instruct.Q4_K_S.gguf?download=true) 49 | 50 | ## Welcome to contribute!!! 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/LlamaModel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import llama 3 | 4 | class LlamaModel { 5 | private let model: Model 6 | private let configuration: Configuration 7 | private let context: OpaquePointer 8 | private let sampler: UnsafeMutablePointer 9 | private var batch: Batch 10 | private var tokens: [Token] 11 | private var temporaryInvalidCChars: [CChar] = [] 12 | private var generatedTokenAccount: Int32 = 0 13 | private var ended = false 14 | private let n_len: Int32 = 1024 15 | 16 | var shouldContinue: Bool { 17 | generatedTokenAccount < configuration.maxTokenCount && !ended 18 | } 19 | 20 | init(path: String, configuration: Configuration = .init()) throws { 21 | self.configuration = configuration 22 | llama_backend_init() 23 | llama_numa_init(GGML_NUMA_STRATEGY_DISABLED) 24 | var model_params = llama_model_default_params() 25 | #if targetEnvironment(simulator) 26 | model_params.n_gpu_layers = 0 27 | #endif 28 | guard let model = llama_load_model_from_file(path, model_params) else { 29 | throw SwiftLlamaError.others("Cannot load model at path \(path)") 30 | } 31 | self.model = model 32 | guard let context = llama_new_context_with_model(model, configuration.contextParameters) else { 33 | throw SwiftLlamaError.others("Cannot load model context") 34 | } 35 | self.context = context 36 | self.tokens = [] 37 | self.batch = llama_batch_init(Int32(configuration.batchSize * Configuration.historySize * 2), 0, 1) 38 | self.sampler = llama_sampler_chain_init(llama_sampler_chain_default_params()) 39 | llama_sampler_chain_add(sampler, llama_sampler_init_temp(configuration.temperature)) 40 | llama_sampler_chain_add(sampler, llama_sampler_init_softmax()) 41 | llama_sampler_chain_add(sampler, llama_sampler_init_dist(1234)) 42 | try checkContextLength(context: context, model: model) 43 | } 44 | 45 | private func checkContextLength(context: Context, model: Model) throws { 46 | let n_ctx = llama_n_ctx(context) 47 | let n_ctx_train = llama_n_ctx_train(model) 48 | if n_ctx > n_ctx_train { 49 | throw SwiftLlamaError.others("Model was trained on \(n_ctx_train) context but tokens \(n_ctx) specified") 50 | } 51 | } 52 | 53 | func start(for prompt: Prompt) throws { 54 | ended = false 55 | tokens = tokenize(text: prompt.prompt, addBos: true) 56 | temporaryInvalidCChars = [] 57 | batch.clear() 58 | 59 | tokens.enumerated().forEach { index, token in 60 | batch.add(token: token, position: Int32(index), seqIDs: [0], logit: false) 61 | } 62 | batch.logits[Int(batch.n_tokens) - 1] = 1 // true 63 | 64 | if llama_decode(context, batch) != 0 { 65 | throw SwiftLlamaError.decodeError 66 | } 67 | generatedTokenAccount = batch.n_tokens 68 | } 69 | 70 | func `continue`() throws -> String { 71 | let newToken = llama_sampler_sample(sampler, context, batch.n_tokens - 1) 72 | 73 | if llama_token_is_eog(model, newToken) || generatedTokenAccount == n_len { 74 | temporaryInvalidCChars.removeAll() 75 | ended = true 76 | return "" 77 | } 78 | 79 | 80 | let newTokenCChars = tokenToCChars(token: newToken) 81 | temporaryInvalidCChars.append(contentsOf: newTokenCChars) 82 | 83 | let newTokenStr: String 84 | if let validString = String(validating: temporaryInvalidCChars + [0], as: UTF8.self) { 85 | newTokenStr = validString 86 | temporaryInvalidCChars.removeAll() 87 | } else if let suffixIndex = temporaryInvalidCChars.firstIndex(where: { $0 != 0 }), 88 | let validSuffix = String(validating: Array(temporaryInvalidCChars.suffix(from: suffixIndex)) + [0], 89 | as: UTF8.self) { 90 | newTokenStr = validSuffix 91 | temporaryInvalidCChars.removeAll() 92 | } else { 93 | newTokenStr = "" 94 | } 95 | 96 | batch.clear() 97 | batch.add(token: newToken, position: generatedTokenAccount, seqIDs: [0], logit: true) 98 | generatedTokenAccount += 1 99 | 100 | if llama_decode(context, batch) != 0 { 101 | throw SwiftLlamaError.decodeError 102 | } 103 | return newTokenStr 104 | } 105 | 106 | private func tokenToCChars(token: llama_token) -> [CChar] { 107 | var length: Int32 = 8 108 | var piece = Array(repeating: 0, count: Int(length)) 109 | 110 | let nTokens = llama_token_to_piece(model, token, &piece, length, 0, false) 111 | if nTokens >= 0 { 112 | return Array(piece.prefix(Int(nTokens))) 113 | } else { 114 | length = -nTokens 115 | piece = Array(repeating: 0, count: Int(length)) 116 | let nNewTokens = llama_token_to_piece(model, token, &piece, length, 0, false) 117 | return Array(piece.prefix(Int(nNewTokens))) 118 | } 119 | } 120 | 121 | private func tokenize(text: String, addBos: Bool) -> [Token] { 122 | let utf8Count = text.utf8.count 123 | let n_tokens = utf8Count + (addBos ? 1 : 0) + 1 124 | 125 | return Array(unsafeUninitializedCapacity: n_tokens) { buffer, initializedCount in 126 | initializedCount = Int( 127 | llama_tokenize(model, text, Int32(utf8Count), buffer.baseAddress, Int32(n_tokens), addBos, false) 128 | ) 129 | } 130 | } 131 | 132 | func clear() { 133 | tokens.removeAll() 134 | temporaryInvalidCChars.removeAll() 135 | llama_kv_cache_clear(context) 136 | } 137 | 138 | deinit { 139 | llama_batch_free(batch) 140 | llama_free(context) 141 | llama_free_model(model) 142 | llama_backend_free() 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Models/Batch.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import llama 3 | 4 | extension Batch { 5 | mutating func clear() { 6 | self.n_tokens = 0 7 | } 8 | 9 | mutating func add(token: Token, 10 | position: Position, 11 | seqIDs: [SeqID], 12 | logit: Bool) { 13 | let nextIndex = Int(n_tokens) 14 | self.token[nextIndex] = token 15 | self.pos[nextIndex] = position 16 | self.n_seq_id[nextIndex] = Int32(seqIDs.count) 17 | seqIDs.enumerated().forEach { index, id in 18 | seq_id[nextIndex]?[index] = id 19 | } 20 | self.logits[nextIndex] = logit ? 1 : 0 21 | self.n_tokens += 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Models/Chat.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct Chat { 4 | public let user: String 5 | public let bot: String 6 | 7 | public init(user: String, bot: String) { 8 | self.user = user 9 | self.bot = bot 10 | } 11 | } 12 | 13 | extension Chat { 14 | var chatMLPrompt: String { 15 | """ 16 | "<|im_start|>user 17 | \(user)<|im_end|> 18 | <|im_start|>assistant 19 | \(bot)<|im_end|> 20 | """ 21 | } 22 | 23 | var llamaPrompt: String { 24 | """ 25 | "[INST]"\(user)"[/INST]", 26 | "[INST]<>"\(bot)"<>[/INST]", 27 | """ 28 | } 29 | 30 | var llama3Prompt: String { 31 | [ 32 | user.isEmpty ? nil : "<|start_header_id|>user<|end_header_id|>\(user)<|eot_id|>", 33 | bot.isEmpty ? nil : "<|start_header_id|>assistant<|end_header_id|>\(bot)<|eot_id|>", 34 | ].compactMap{ $0 }.joined(separator: "\n") 35 | } 36 | 37 | var mistralPrompt: String { 38 | """ 39 | "[INST]"\(user)"[/INST]" 40 | "[INST]"\(bot)"[/INST]" 41 | """ 42 | } 43 | 44 | var phiPrompt: String { 45 | """ 46 | <|user|> 47 | \(user) 48 | <|end|> 49 | <|assistant|> 50 | \(bot) 51 | """ 52 | } 53 | 54 | var gemmaPrompt: String { 55 | """ 56 | user 57 | \(user) 58 | 59 | model 60 | \(bot) 61 | 62 | """ 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Models/Configuration.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import llama 3 | 4 | public struct Configuration { 5 | static let historySize = 5 6 | public let seed: Int 7 | public let topK: Int 8 | public let topP: Float 9 | public let nCTX: Int 10 | public let temperature: Float 11 | public let maxTokenCount: Int 12 | public let batchSize: Int 13 | public let stopTokens: [String] 14 | 15 | public init(seed: Int = 1234, 16 | topK: Int = 40, 17 | topP: Float = 0.9, 18 | nCTX: Int = 2048, 19 | temperature: Float = 0.2, 20 | batchSize: Int = 2048, 21 | stopSequence: String? = nil, 22 | maxTokenCount: Int = 1024, 23 | stopTokens: [String] = []) { 24 | self.seed = seed 25 | self.topK = topK 26 | self.topP = topP 27 | self.nCTX = nCTX 28 | self.batchSize = batchSize 29 | self.temperature = temperature 30 | self.maxTokenCount = maxTokenCount 31 | self.stopTokens = stopTokens 32 | } 33 | } 34 | 35 | extension Configuration { 36 | var contextParameters: ContextParameters { 37 | var params = llama_context_default_params() 38 | let processorCount = max(1, min(16, ProcessInfo.processInfo.processorCount - 2)) 39 | params.n_ctx = max(8, UInt32(self.nCTX)) // minimum context size is 8 40 | params.n_threads = Int32(processorCount) 41 | params.n_threads_batch = Int32(processorCount) 42 | return params 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Models/Prompt.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct Prompt { 4 | public enum `Type` { 5 | case chatML 6 | case alpaca 7 | case llama 8 | case llama3 9 | case mistral 10 | case phi 11 | case gemma 12 | } 13 | 14 | public let type: `Type` 15 | public let systemPrompt: String 16 | public let userMessage: String 17 | public let history: [Chat] 18 | 19 | public init(type: `Type`, 20 | systemPrompt: String = "", 21 | userMessage: String, 22 | history: [Chat] = []) { 23 | self.type = type 24 | self.systemPrompt = systemPrompt 25 | self.userMessage = userMessage 26 | self.history = history 27 | } 28 | 29 | var prompt: String { 30 | switch type { 31 | case .llama: encodeLlamaPrompt() 32 | case .llama3: encodeLlama3Prompt() 33 | case .alpaca: encodeAlpacaPrompt() 34 | case .chatML: encodeChatMLPrompt() 35 | case .mistral: encodeMistralPrompt() 36 | case .phi: encodePhiPrompt() 37 | case .gemma: encodeGemmaPrompt() 38 | } 39 | } 40 | 41 | private func encodeLlamaPrompt() -> String { 42 | """ 43 | [INST]<> 44 | \(systemPrompt) 45 | <> 46 | \(history.suffix(Configuration.historySize).map { $0.llamaPrompt }.joined()) 47 | [/INST] 48 | [INST] 49 | \(userMessage) 50 | [/INST] 51 | """ 52 | } 53 | 54 | private func encodeLlama3Prompt() -> String { 55 | let prompt = """ 56 | <|start_header_id|>system<|end_header_id|>\(systemPrompt)<|eot_id|> 57 | 58 | \(history.suffix(Configuration.historySize).map { $0.llama3Prompt }.joined()) 59 | 60 | <|start_header_id|>user<|end_header_id|>\(userMessage)<|eot_id|> 61 | <|start_header_id|>assistant<|end_header_id|> 62 | """ 63 | return prompt 64 | } 65 | 66 | private func encodeAlpacaPrompt() -> String { 67 | """ 68 | Below is an instruction that describes a task. 69 | Write a response that appropriately completes the request. 70 | \(userMessage) 71 | """ 72 | } 73 | 74 | private func encodeChatMLPrompt() -> String { 75 | """ 76 | \(history.suffix(Configuration.historySize).map { $0.chatMLPrompt }.joined()) 77 | "<|im_start|>user" 78 | \(userMessage)<|im_end|> 79 | <|im_start|>assistant 80 | """ 81 | } 82 | 83 | private func encodeMistralPrompt() -> String { 84 | """ 85 | 86 | \(history.suffix(Configuration.historySize).map { $0.mistralPrompt }.joined()) 87 | 88 | [INST] \(userMessage) [/INST] 89 | """ 90 | } 91 | 92 | private func encodePhiPrompt() -> String { 93 | """ 94 | \(systemPrompt) 95 | \(history.suffix(Configuration.historySize).map { $0.phiPrompt }.joined()) 96 | <|user|> 97 | \(userMessage) 98 | <|end|> 99 | <|assistant|> 100 | """ 101 | } 102 | 103 | private func encodeGemmaPrompt() -> String { 104 | """ 105 | system 106 | \(systemPrompt) 107 | 108 | \(history.suffix(Configuration.historySize).map { $0.gemmaPrompt }.joined()) 109 | user 110 | \(userMessage) 111 | 112 | model 113 | """ 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Models/Session.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | struct Session { 4 | private var history: [Chat] = [] 5 | var lastPrompt: Prompt 6 | var currentResponse: String = "" 7 | 8 | init(history: [Chat] = [], lastPrompt: Prompt) { 9 | self.history = history 10 | self.lastPrompt = lastPrompt 11 | } 12 | 13 | mutating func endResponse() { 14 | history.append(Chat(user: lastPrompt.userMessage, bot: currentResponse)) 15 | currentResponse = "" 16 | } 17 | 18 | mutating func response(delta: String) { 19 | currentResponse += delta 20 | } 21 | 22 | var sessionPrompt: Prompt { 23 | Prompt(type: lastPrompt.type, 24 | systemPrompt: lastPrompt.systemPrompt, 25 | userMessage: lastPrompt.userMessage, 26 | history: history) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Models/StopToken.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public enum StopToken {} 4 | 5 | public extension StopToken { 6 | static var phi: [String] { 7 | [ 8 | "<|end|>", 9 | ] 10 | } 11 | 12 | static var llama: [String] { 13 | [ 14 | "[/INST]", 15 | ] 16 | } 17 | 18 | static var llama3: [String] { 19 | [ 20 | "<|eot_id|>", 21 | ] 22 | } 23 | 24 | static var chatML: [String] { 25 | [ 26 | "<|im_end|>" 27 | ] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Models/SwiftLlamaError.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public enum SwiftLlamaError: Error { 4 | case decodeError 5 | case others(String) 6 | } 7 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Models/TypeAlias.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import llama 3 | 4 | typealias Batch = llama_batch 5 | typealias Model = OpaquePointer 6 | typealias Context = OpaquePointer 7 | typealias Token = llama_token 8 | typealias Position = llama_pos 9 | typealias SeqID = llama_seq_id 10 | typealias ContextParameters = llama_context_params 11 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/Swiftllama.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import llama 3 | import Combine 4 | 5 | public class SwiftLlama { 6 | private let model: LlamaModel 7 | private let configuration: Configuration 8 | private var contentStarted = false 9 | private var sessionSupport = false { 10 | didSet { 11 | if !sessionSupport { 12 | session = nil 13 | } 14 | } 15 | } 16 | 17 | private var session: Session? 18 | private lazy var resultSubject: CurrentValueSubject = { 19 | .init("") 20 | }() 21 | private var generatedTokenCache = "" 22 | 23 | var maxLengthOfStopToken: Int { 24 | configuration.stopTokens.map { $0.count }.max() ?? 0 25 | } 26 | 27 | public init(modelPath: String, 28 | modelConfiguration: Configuration = .init()) throws { 29 | self.model = try LlamaModel(path: modelPath, configuration: modelConfiguration) 30 | self.configuration = modelConfiguration 31 | } 32 | 33 | private func prepare(sessionSupport: Bool, for prompt: Prompt) -> Prompt { 34 | contentStarted = false 35 | generatedTokenCache = "" 36 | self.sessionSupport = sessionSupport 37 | if sessionSupport { 38 | if session == nil { 39 | session = Session(lastPrompt: prompt) 40 | } else { 41 | session?.lastPrompt = prompt 42 | } 43 | return session?.sessionPrompt ?? prompt 44 | } else { 45 | return prompt 46 | } 47 | } 48 | 49 | private func isStopToken() -> Bool { 50 | configuration.stopTokens.reduce(false) { partialResult, stopToken in 51 | generatedTokenCache.hasSuffix(stopToken) 52 | } 53 | } 54 | 55 | private func response(for prompt: Prompt, output: (String) -> Void, finish: () -> Void) { 56 | func finaliseOutput() { 57 | configuration.stopTokens.forEach { 58 | generatedTokenCache = generatedTokenCache.replacingOccurrences(of: $0, with: "") 59 | } 60 | output(generatedTokenCache) 61 | finish() 62 | generatedTokenCache = "" 63 | } 64 | defer { model.clear() } 65 | do { 66 | try model.start(for: prompt) 67 | while model.shouldContinue { 68 | var delta = try model.continue() 69 | if contentStarted { // remove the prefix empty spaces 70 | if needToStop(after: delta, output: output) { 71 | finish() 72 | break 73 | } 74 | } else { 75 | delta = delta.trimmingCharacters(in: .whitespacesAndNewlines) 76 | if !delta.isEmpty { 77 | contentStarted = true 78 | if needToStop(after: delta, output: output) { 79 | finish() 80 | break 81 | } 82 | } 83 | } 84 | } 85 | finaliseOutput() 86 | } catch { 87 | finaliseOutput() 88 | } 89 | } 90 | 91 | /// Handling logic of StopToken 92 | private func needToStop(after delta: String, output: (String) -> Void) -> Bool { 93 | guard maxLengthOfStopToken > 0 else { 94 | output(delta) 95 | return false 96 | } 97 | generatedTokenCache += delta 98 | if generatedTokenCache.count >= maxLengthOfStopToken * 2 { 99 | if let stopToken = configuration.stopTokens.first(where: { generatedTokenCache.contains($0) }), 100 | let index = generatedTokenCache.range(of: stopToken) { 101 | let outputCandidate = String(generatedTokenCache[.. AsyncThrowingStream { 117 | let sessionPrompt = prepare(sessionSupport: sessionSupport, for: prompt) 118 | return .init { continuation in 119 | Task { 120 | response(for: sessionPrompt) { [weak self] delta in 121 | continuation.yield(delta) 122 | self?.session?.response(delta: delta) 123 | } finish: { [weak self] in 124 | continuation.finish() 125 | self?.session?.endResponse() 126 | } 127 | } 128 | } 129 | } 130 | 131 | @SwiftLlamaActor 132 | public func start(for prompt: Prompt, sessionSupport: Bool = false) -> AnyPublisher { 133 | let sessionPrompt = prepare(sessionSupport: sessionSupport, for: prompt) 134 | Task { 135 | response(for: sessionPrompt) { delta in 136 | resultSubject.send(delta) 137 | session?.response(delta: delta) 138 | } finish: { 139 | resultSubject.send(completion: .finished) 140 | session?.endResponse() 141 | } 142 | } 143 | return resultSubject.eraseToAnyPublisher() 144 | } 145 | 146 | @SwiftLlamaActor 147 | public func start(for prompt: Prompt, sessionSupport: Bool = false) async throws -> String { 148 | var result = "" 149 | for try await value in start(for: prompt) { 150 | result += value 151 | } 152 | return result 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /Sources/SwiftLlama/SwiftllamaActor.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | @globalActor 4 | public actor SwiftLlamaActor { 5 | public static let shared = SwiftLlamaActor() 6 | } 7 | -------------------------------------------------------------------------------- /TestProjects/README.md: -------------------------------------------------------------------------------- 1 | # Test project for SwiftLlama package 2 | 3 | There are three targets in this demostration: 4 | one iOS app target, one MacOS app target and one command line app, 5 | which are located in different folder group. Also, there is a Shared folder group 6 | that contains code/resources that are shared. 7 | 8 | Please note there's no models are included in this repo. 9 | If you want to run these apps, 10 | you need to download your own models and modify the code to use them accordingly. 11 | In cased of the command line app, you just need to give the right path to the app 12 | in scheme settings or in terminal app when you run it in terminal. 13 | 14 | -------------------------------------------------------------------------------- /TestProjects/Shared/ContentView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct ContentView: View { 4 | @State private var viewModel = ViewModel() 5 | @State private var prompt = "" 6 | 7 | var body: some View { 8 | VStack { 9 | Text("Swift Llama Demo").font(.title) 10 | Toggle(isOn: $viewModel.usingStream, label: { 11 | Text("Choice of AsyncStream or Combine Publisher, on for Stream, off for Publisher") 12 | }) 13 | TextField("Prompt", text: $prompt, axis: .vertical) 14 | .textFieldStyle(.roundedBorder) 15 | .onSubmit { 16 | viewModel.run(for: prompt) 17 | } 18 | Text(viewModel.result) 19 | Spacer() 20 | } 21 | .padding() 22 | } 23 | } 24 | 25 | #Preview { 26 | ContentView() 27 | } 28 | -------------------------------------------------------------------------------- /TestProjects/Shared/ViewModel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftLlama 3 | import SwiftUI 4 | import Combine 5 | 6 | @Observable 7 | class ViewModel { 8 | let swiftLlama: SwiftLlama 9 | var result = "" 10 | var usingStream = true 11 | private var cancallable: Set = [] 12 | 13 | init() { 14 | let path = Bundle.main.path(forResource: "llama-2-7b.Q4_K_M", ofType: "gguf") ?? "" 15 | swiftLlama = (try? SwiftLlama(modelPath: path))! 16 | } 17 | 18 | func run(for userMessage: String) { 19 | result = "" 20 | let prompt = Prompt(type: .llama, 21 | systemPrompt: "You are a helpful coding AI assistant.", 22 | userMessage: userMessage) 23 | Task { 24 | switch usingStream { 25 | case true: 26 | for try await value in await swiftLlama.start(for: prompt) { 27 | result += value 28 | } 29 | case false: 30 | await swiftLlama.start(for: prompt) 31 | .sink { _ in 32 | 33 | } receiveValue: {[weak self] value in 34 | self?.result += value 35 | }.store(in: &cancallable) 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TestProjects/TestApp-Commandline/main.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftLlama 3 | 4 | if CommandLine.arguments.count < 2 { 5 | print("Usage: swiftllama model_file_path") 6 | exit(1) 7 | } 8 | 9 | guard let modelPath = CommandLine.arguments.last else { 10 | exit(1) 11 | } 12 | 13 | guard let swiftLlama = try? SwiftLlama(modelPath: modelPath, 14 | modelConfiguration: .init(stopTokens: StopToken.llama )) else { 15 | print("Cannot load model.") 16 | exit(1) 17 | } 18 | 19 | while true { 20 | print("You:", terminator: " ") 21 | let userMessage = readLine() ?? "" 22 | print("Bot:", terminator: " ") 23 | 24 | for try await value in await swiftLlama 25 | .start(for: .init(type: .llama, 26 | systemPrompt: 27 | """ 28 | You are a helpful AI assistant! 29 | """, 30 | userMessage: userMessage), 31 | sessionSupport: true) { 32 | print(value, terminator: "") 33 | } 34 | print("") 35 | // 36 | // let result: String = try await swiftLlama.start(for: .init(type: .mistral, userMessage: userMessage)) 37 | // print(result) 38 | // print("") 39 | } 40 | -------------------------------------------------------------------------------- /TestProjects/TestApp-Macos/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /TestProjects/TestApp-Macos/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "scale" : "1x", 6 | "size" : "16x16" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "scale" : "2x", 11 | "size" : "16x16" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "scale" : "1x", 16 | "size" : "32x32" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "scale" : "2x", 21 | "size" : "32x32" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "scale" : "1x", 26 | "size" : "128x128" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "scale" : "2x", 31 | "size" : "128x128" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "scale" : "1x", 36 | "size" : "256x256" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "scale" : "2x", 41 | "size" : "256x256" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "scale" : "1x", 46 | "size" : "512x512" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "scale" : "2x", 51 | "size" : "512x512" 52 | } 53 | ], 54 | "info" : { 55 | "author" : "xcode", 56 | "version" : 1 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /TestProjects/TestApp-Macos/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /TestProjects/TestApp-Macos/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /TestProjects/TestApp-Macos/TestApp_Macos.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /TestProjects/TestApp-Macos/TestApp_MacosApp.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @main 4 | struct TestApp_MacosApp: App { 5 | var body: some Scene { 6 | WindowGroup { 7 | ContentView() 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /TestProjects/TestApp-iOS/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /TestProjects/TestApp-iOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "platform" : "ios", 6 | "size" : "1024x1024" 7 | } 8 | ], 9 | "info" : { 10 | "author" : "xcode", 11 | "version" : 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /TestProjects/TestApp-iOS/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /TestProjects/TestApp-iOS/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /TestProjects/TestApp-iOS/TestApp_iOSApp.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @main 4 | struct TestAppApp: App { 5 | var body: some Scene { 6 | WindowGroup { 7 | ContentView() 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /TestProjects/TestApp.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 60; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4B0B057A2BE5C451002BC7AF /* TestApp_MacosApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B0B05792BE5C451002BC7AF /* TestApp_MacosApp.swift */; }; 11 | 4B0B057E2BE5C452002BC7AF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B0B057D2BE5C452002BC7AF /* Assets.xcassets */; }; 12 | 4B0B05812BE5C452002BC7AF /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B0B05802BE5C452002BC7AF /* Preview Assets.xcassets */; }; 13 | 4B10A3322BE5CD6600BEA6A1 /* llama-2-7b.Q4_K_M.gguf in Resources */ = {isa = PBXBuildFile; fileRef = 4B10A3312BE5CD6600BEA6A1 /* llama-2-7b.Q4_K_M.gguf */; }; 14 | 4B1334FA2BE5C4AC0020AB8E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B1334F42BE5C4AC0020AB8E /* Assets.xcassets */; }; 15 | 4B1334FB2BE5C4AC0020AB8E /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1334F52BE5C4AC0020AB8E /* ViewModel.swift */; }; 16 | 4B1334FC2BE5C4AC0020AB8E /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B1334F72BE5C4AC0020AB8E /* Preview Assets.xcassets */; }; 17 | 4B1334FD2BE5C4AC0020AB8E /* TestApp_iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1334F82BE5C4AC0020AB8E /* TestApp_iOSApp.swift */; }; 18 | 4B1334FE2BE5C4AC0020AB8E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1334F92BE5C4AC0020AB8E /* ContentView.swift */; }; 19 | 4B58A1432BE607B900A6CF3C /* llama-2-7b.Q4_K_M.gguf in Resources */ = {isa = PBXBuildFile; fileRef = 4B10A3312BE5CD6600BEA6A1 /* llama-2-7b.Q4_K_M.gguf */; }; 20 | 4BB1E3E12BE6464F00F1D21A /* SwiftLlama in Frameworks */ = {isa = PBXBuildFile; productRef = 4BB1E3E02BE6464F00F1D21A /* SwiftLlama */; }; 21 | 4BB1E3E32BE6466A00F1D21A /* SwiftLlama in Frameworks */ = {isa = PBXBuildFile; productRef = 4BB1E3E22BE6466A00F1D21A /* SwiftLlama */; }; 22 | 4BB1E3E52BE646CF00F1D21A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1334F92BE5C4AC0020AB8E /* ContentView.swift */; }; 23 | 4BB1E3E62BE646CF00F1D21A /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1334F52BE5C4AC0020AB8E /* ViewModel.swift */; }; 24 | 4BEE1DB62BE70024001CE949 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEE1DB52BE70024001CE949 /* main.swift */; }; 25 | 4BEE1DBB2BE7003E001CE949 /* SwiftLlama in Frameworks */ = {isa = PBXBuildFile; productRef = 4BEE1DBA2BE7003E001CE949 /* SwiftLlama */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXCopyFilesBuildPhase section */ 29 | 4BEE1DB12BE70024001CE949 /* CopyFiles */ = { 30 | isa = PBXCopyFilesBuildPhase; 31 | buildActionMask = 2147483647; 32 | dstPath = /usr/share/man/man1/; 33 | dstSubfolderSpec = 0; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 1; 37 | }; 38 | /* End PBXCopyFilesBuildPhase section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 4B0B055A2BE5B44E002BC7AF /* TestApp-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "TestApp-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 4B0B05772BE5C451002BC7AF /* TestApp-Macos.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "TestApp-Macos.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 4B0B05792BE5C451002BC7AF /* TestApp_MacosApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestApp_MacosApp.swift; sourceTree = ""; }; 44 | 4B0B057D2BE5C452002BC7AF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 45 | 4B0B05802BE5C452002BC7AF /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 46 | 4B0B05822BE5C452002BC7AF /* TestApp_Macos.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TestApp_Macos.entitlements; sourceTree = ""; }; 47 | 4B10A3312BE5CD6600BEA6A1 /* llama-2-7b.Q4_K_M.gguf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "llama-2-7b.Q4_K_M.gguf"; sourceTree = ""; }; 48 | 4B1334F42BE5C4AC0020AB8E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | 4B1334F52BE5C4AC0020AB8E /* ViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = ""; }; 50 | 4B1334F72BE5C4AC0020AB8E /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 51 | 4B1334F82BE5C4AC0020AB8E /* TestApp_iOSApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestApp_iOSApp.swift; sourceTree = ""; }; 52 | 4B1334F92BE5C4AC0020AB8E /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 53 | 4B51A47B2BE7449700F65BFC /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 54 | 4BEE1DB32BE70024001CE949 /* swiftllama */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = swiftllama; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | 4BEE1DB52BE70024001CE949 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 56 | /* End PBXFileReference section */ 57 | 58 | /* Begin PBXFrameworksBuildPhase section */ 59 | 4B0B05572BE5B44E002BC7AF /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | 4BB1E3E12BE6464F00F1D21A /* SwiftLlama in Frameworks */, 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | 4B0B05742BE5C451002BC7AF /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | 4BB1E3E32BE6466A00F1D21A /* SwiftLlama in Frameworks */, 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | 4BEE1DB02BE70024001CE949 /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | 4BEE1DBB2BE7003E001CE949 /* SwiftLlama in Frameworks */, 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | /* End PBXFrameworksBuildPhase section */ 84 | 85 | /* Begin PBXGroup section */ 86 | 4B0B05512BE5B44E002BC7AF = { 87 | isa = PBXGroup; 88 | children = ( 89 | 4B51A47B2BE7449700F65BFC /* README.md */, 90 | 4BB1E3E42BE646BB00F1D21A /* Shared */, 91 | 4B1334F32BE5C4AC0020AB8E /* TestApp-iOS */, 92 | 4B0B05782BE5C451002BC7AF /* TestApp-Macos */, 93 | 4BEE1DB42BE70024001CE949 /* TestApp-Commandline */, 94 | 4B0B055B2BE5B44E002BC7AF /* Products */, 95 | ); 96 | sourceTree = ""; 97 | }; 98 | 4B0B055B2BE5B44E002BC7AF /* Products */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 4B0B055A2BE5B44E002BC7AF /* TestApp-iOS.app */, 102 | 4B0B05772BE5C451002BC7AF /* TestApp-Macos.app */, 103 | 4BEE1DB32BE70024001CE949 /* swiftllama */, 104 | ); 105 | name = Products; 106 | sourceTree = ""; 107 | }; 108 | 4B0B05782BE5C451002BC7AF /* TestApp-Macos */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 4B0B05792BE5C451002BC7AF /* TestApp_MacosApp.swift */, 112 | 4B0B057D2BE5C452002BC7AF /* Assets.xcassets */, 113 | 4B0B05822BE5C452002BC7AF /* TestApp_Macos.entitlements */, 114 | 4B0B057F2BE5C452002BC7AF /* Preview Content */, 115 | ); 116 | path = "TestApp-Macos"; 117 | sourceTree = ""; 118 | }; 119 | 4B0B057F2BE5C452002BC7AF /* Preview Content */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 4B0B05802BE5C452002BC7AF /* Preview Assets.xcassets */, 123 | ); 124 | path = "Preview Content"; 125 | sourceTree = ""; 126 | }; 127 | 4B10A3302BE5CD6600BEA6A1 /* Models */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 4B10A3312BE5CD6600BEA6A1 /* llama-2-7b.Q4_K_M.gguf */, 131 | ); 132 | name = Models; 133 | path = Shared/Models; 134 | sourceTree = SOURCE_ROOT; 135 | }; 136 | 4B1334F32BE5C4AC0020AB8E /* TestApp-iOS */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | 4B1334F82BE5C4AC0020AB8E /* TestApp_iOSApp.swift */, 140 | 4B1334F42BE5C4AC0020AB8E /* Assets.xcassets */, 141 | 4B1334F62BE5C4AC0020AB8E /* Preview Content */, 142 | ); 143 | path = "TestApp-iOS"; 144 | sourceTree = ""; 145 | }; 146 | 4B1334F62BE5C4AC0020AB8E /* Preview Content */ = { 147 | isa = PBXGroup; 148 | children = ( 149 | 4B1334F72BE5C4AC0020AB8E /* Preview Assets.xcassets */, 150 | ); 151 | path = "Preview Content"; 152 | sourceTree = ""; 153 | }; 154 | 4BB1E3E42BE646BB00F1D21A /* Shared */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | 4B10A3302BE5CD6600BEA6A1 /* Models */, 158 | 4B1334F92BE5C4AC0020AB8E /* ContentView.swift */, 159 | 4B1334F52BE5C4AC0020AB8E /* ViewModel.swift */, 160 | ); 161 | path = Shared; 162 | sourceTree = ""; 163 | }; 164 | 4BEE1DB42BE70024001CE949 /* TestApp-Commandline */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | 4BEE1DB52BE70024001CE949 /* main.swift */, 168 | ); 169 | path = "TestApp-Commandline"; 170 | sourceTree = ""; 171 | }; 172 | /* End PBXGroup section */ 173 | 174 | /* Begin PBXNativeTarget section */ 175 | 4B0B05592BE5B44E002BC7AF /* TestApp-iOS */ = { 176 | isa = PBXNativeTarget; 177 | buildConfigurationList = 4B0B05682BE5B450002BC7AF /* Build configuration list for PBXNativeTarget "TestApp-iOS" */; 178 | buildPhases = ( 179 | 4B0B05562BE5B44E002BC7AF /* Sources */, 180 | 4B0B05572BE5B44E002BC7AF /* Frameworks */, 181 | 4B0B05582BE5B44E002BC7AF /* Resources */, 182 | ); 183 | buildRules = ( 184 | ); 185 | dependencies = ( 186 | ); 187 | name = "TestApp-iOS"; 188 | packageProductDependencies = ( 189 | 4BB1E3E02BE6464F00F1D21A /* SwiftLlama */, 190 | ); 191 | productName = TestApp; 192 | productReference = 4B0B055A2BE5B44E002BC7AF /* TestApp-iOS.app */; 193 | productType = "com.apple.product-type.application"; 194 | }; 195 | 4B0B05762BE5C451002BC7AF /* TestApp-Macos */ = { 196 | isa = PBXNativeTarget; 197 | buildConfigurationList = 4B0B05832BE5C452002BC7AF /* Build configuration list for PBXNativeTarget "TestApp-Macos" */; 198 | buildPhases = ( 199 | 4B0B05732BE5C451002BC7AF /* Sources */, 200 | 4B0B05742BE5C451002BC7AF /* Frameworks */, 201 | 4B0B05752BE5C451002BC7AF /* Resources */, 202 | ); 203 | buildRules = ( 204 | ); 205 | dependencies = ( 206 | ); 207 | name = "TestApp-Macos"; 208 | packageProductDependencies = ( 209 | 4BB1E3E22BE6466A00F1D21A /* SwiftLlama */, 210 | ); 211 | productName = "TestApp-Macos"; 212 | productReference = 4B0B05772BE5C451002BC7AF /* TestApp-Macos.app */; 213 | productType = "com.apple.product-type.application"; 214 | }; 215 | 4BEE1DB22BE70024001CE949 /* swiftllama */ = { 216 | isa = PBXNativeTarget; 217 | buildConfigurationList = 4BEE1DB92BE70024001CE949 /* Build configuration list for PBXNativeTarget "swiftllama" */; 218 | buildPhases = ( 219 | 4BEE1DAF2BE70024001CE949 /* Sources */, 220 | 4BEE1DB02BE70024001CE949 /* Frameworks */, 221 | 4BEE1DB12BE70024001CE949 /* CopyFiles */, 222 | ); 223 | buildRules = ( 224 | ); 225 | dependencies = ( 226 | ); 227 | name = swiftllama; 228 | packageProductDependencies = ( 229 | 4BEE1DBA2BE7003E001CE949 /* SwiftLlama */, 230 | ); 231 | productName = "TestApp-Commandline"; 232 | productReference = 4BEE1DB32BE70024001CE949 /* swiftllama */; 233 | productType = "com.apple.product-type.tool"; 234 | }; 235 | /* End PBXNativeTarget section */ 236 | 237 | /* Begin PBXProject section */ 238 | 4B0B05522BE5B44E002BC7AF /* Project object */ = { 239 | isa = PBXProject; 240 | attributes = { 241 | BuildIndependentTargetsInParallel = 1; 242 | LastSwiftUpdateCheck = 1520; 243 | LastUpgradeCheck = 1520; 244 | TargetAttributes = { 245 | 4B0B05592BE5B44E002BC7AF = { 246 | CreatedOnToolsVersion = 15.2; 247 | }; 248 | 4B0B05762BE5C451002BC7AF = { 249 | CreatedOnToolsVersion = 15.2; 250 | }; 251 | 4BEE1DB22BE70024001CE949 = { 252 | CreatedOnToolsVersion = 15.2; 253 | }; 254 | }; 255 | }; 256 | buildConfigurationList = 4B0B05552BE5B44E002BC7AF /* Build configuration list for PBXProject "TestApp" */; 257 | compatibilityVersion = "Xcode 14.0"; 258 | developmentRegion = en; 259 | hasScannedForEncodings = 0; 260 | knownRegions = ( 261 | en, 262 | Base, 263 | ); 264 | mainGroup = 4B0B05512BE5B44E002BC7AF; 265 | packageReferences = ( 266 | 4B1335012BE5C58A0020AB8E /* XCLocalSwiftPackageReference ".." */, 267 | ); 268 | productRefGroup = 4B0B055B2BE5B44E002BC7AF /* Products */; 269 | projectDirPath = ""; 270 | projectRoot = ""; 271 | targets = ( 272 | 4B0B05592BE5B44E002BC7AF /* TestApp-iOS */, 273 | 4B0B05762BE5C451002BC7AF /* TestApp-Macos */, 274 | 4BEE1DB22BE70024001CE949 /* swiftllama */, 275 | ); 276 | }; 277 | /* End PBXProject section */ 278 | 279 | /* Begin PBXResourcesBuildPhase section */ 280 | 4B0B05582BE5B44E002BC7AF /* Resources */ = { 281 | isa = PBXResourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | 4B1334FC2BE5C4AC0020AB8E /* Preview Assets.xcassets in Resources */, 285 | 4B1334FA2BE5C4AC0020AB8E /* Assets.xcassets in Resources */, 286 | 4B58A1432BE607B900A6CF3C /* llama-2-7b.Q4_K_M.gguf in Resources */, 287 | ); 288 | runOnlyForDeploymentPostprocessing = 0; 289 | }; 290 | 4B0B05752BE5C451002BC7AF /* Resources */ = { 291 | isa = PBXResourcesBuildPhase; 292 | buildActionMask = 2147483647; 293 | files = ( 294 | 4B0B05812BE5C452002BC7AF /* Preview Assets.xcassets in Resources */, 295 | 4B0B057E2BE5C452002BC7AF /* Assets.xcassets in Resources */, 296 | 4B10A3322BE5CD6600BEA6A1 /* llama-2-7b.Q4_K_M.gguf in Resources */, 297 | ); 298 | runOnlyForDeploymentPostprocessing = 0; 299 | }; 300 | /* End PBXResourcesBuildPhase section */ 301 | 302 | /* Begin PBXSourcesBuildPhase section */ 303 | 4B0B05562BE5B44E002BC7AF /* Sources */ = { 304 | isa = PBXSourcesBuildPhase; 305 | buildActionMask = 2147483647; 306 | files = ( 307 | 4B1334FB2BE5C4AC0020AB8E /* ViewModel.swift in Sources */, 308 | 4B1334FD2BE5C4AC0020AB8E /* TestApp_iOSApp.swift in Sources */, 309 | 4B1334FE2BE5C4AC0020AB8E /* ContentView.swift in Sources */, 310 | ); 311 | runOnlyForDeploymentPostprocessing = 0; 312 | }; 313 | 4B0B05732BE5C451002BC7AF /* Sources */ = { 314 | isa = PBXSourcesBuildPhase; 315 | buildActionMask = 2147483647; 316 | files = ( 317 | 4BB1E3E62BE646CF00F1D21A /* ViewModel.swift in Sources */, 318 | 4BB1E3E52BE646CF00F1D21A /* ContentView.swift in Sources */, 319 | 4B0B057A2BE5C451002BC7AF /* TestApp_MacosApp.swift in Sources */, 320 | ); 321 | runOnlyForDeploymentPostprocessing = 0; 322 | }; 323 | 4BEE1DAF2BE70024001CE949 /* Sources */ = { 324 | isa = PBXSourcesBuildPhase; 325 | buildActionMask = 2147483647; 326 | files = ( 327 | 4BEE1DB62BE70024001CE949 /* main.swift in Sources */, 328 | ); 329 | runOnlyForDeploymentPostprocessing = 0; 330 | }; 331 | /* End PBXSourcesBuildPhase section */ 332 | 333 | /* Begin XCBuildConfiguration section */ 334 | 4B0B05662BE5B450002BC7AF /* Debug */ = { 335 | isa = XCBuildConfiguration; 336 | buildSettings = { 337 | ALWAYS_SEARCH_USER_PATHS = NO; 338 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 339 | CLANG_ANALYZER_NONNULL = YES; 340 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 341 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 342 | CLANG_ENABLE_MODULES = YES; 343 | CLANG_ENABLE_OBJC_ARC = YES; 344 | CLANG_ENABLE_OBJC_WEAK = YES; 345 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 346 | CLANG_WARN_BOOL_CONVERSION = YES; 347 | CLANG_WARN_COMMA = YES; 348 | CLANG_WARN_CONSTANT_CONVERSION = YES; 349 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 350 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 351 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 352 | CLANG_WARN_EMPTY_BODY = YES; 353 | CLANG_WARN_ENUM_CONVERSION = YES; 354 | CLANG_WARN_INFINITE_RECURSION = YES; 355 | CLANG_WARN_INT_CONVERSION = YES; 356 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 357 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 358 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 359 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 360 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 361 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 362 | CLANG_WARN_STRICT_PROTOTYPES = YES; 363 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 364 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 365 | CLANG_WARN_UNREACHABLE_CODE = YES; 366 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 367 | COPY_PHASE_STRIP = NO; 368 | DEBUG_INFORMATION_FORMAT = dwarf; 369 | ENABLE_STRICT_OBJC_MSGSEND = YES; 370 | ENABLE_TESTABILITY = YES; 371 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 372 | GCC_C_LANGUAGE_STANDARD = gnu17; 373 | GCC_DYNAMIC_NO_PIC = NO; 374 | GCC_NO_COMMON_BLOCKS = YES; 375 | GCC_OPTIMIZATION_LEVEL = 0; 376 | GCC_PREPROCESSOR_DEFINITIONS = ( 377 | "DEBUG=1", 378 | "$(inherited)", 379 | ); 380 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 381 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 382 | GCC_WARN_UNDECLARED_SELECTOR = YES; 383 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 384 | GCC_WARN_UNUSED_FUNCTION = YES; 385 | GCC_WARN_UNUSED_VARIABLE = YES; 386 | IPHONEOS_DEPLOYMENT_TARGET = 17.2; 387 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 388 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 389 | MTL_FAST_MATH = YES; 390 | ONLY_ACTIVE_ARCH = YES; 391 | SDKROOT = iphoneos; 392 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; 393 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 394 | }; 395 | name = Debug; 396 | }; 397 | 4B0B05672BE5B450002BC7AF /* Release */ = { 398 | isa = XCBuildConfiguration; 399 | buildSettings = { 400 | ALWAYS_SEARCH_USER_PATHS = NO; 401 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 402 | CLANG_ANALYZER_NONNULL = YES; 403 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 404 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 405 | CLANG_ENABLE_MODULES = YES; 406 | CLANG_ENABLE_OBJC_ARC = YES; 407 | CLANG_ENABLE_OBJC_WEAK = YES; 408 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 409 | CLANG_WARN_BOOL_CONVERSION = YES; 410 | CLANG_WARN_COMMA = YES; 411 | CLANG_WARN_CONSTANT_CONVERSION = YES; 412 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 413 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 414 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 415 | CLANG_WARN_EMPTY_BODY = YES; 416 | CLANG_WARN_ENUM_CONVERSION = YES; 417 | CLANG_WARN_INFINITE_RECURSION = YES; 418 | CLANG_WARN_INT_CONVERSION = YES; 419 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 420 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 421 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 422 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 423 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 424 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 425 | CLANG_WARN_STRICT_PROTOTYPES = YES; 426 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 427 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 428 | CLANG_WARN_UNREACHABLE_CODE = YES; 429 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 430 | COPY_PHASE_STRIP = NO; 431 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 432 | ENABLE_NS_ASSERTIONS = NO; 433 | ENABLE_STRICT_OBJC_MSGSEND = YES; 434 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 435 | GCC_C_LANGUAGE_STANDARD = gnu17; 436 | GCC_NO_COMMON_BLOCKS = YES; 437 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 438 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 439 | GCC_WARN_UNDECLARED_SELECTOR = YES; 440 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 441 | GCC_WARN_UNUSED_FUNCTION = YES; 442 | GCC_WARN_UNUSED_VARIABLE = YES; 443 | IPHONEOS_DEPLOYMENT_TARGET = 17.2; 444 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 445 | MTL_ENABLE_DEBUG_INFO = NO; 446 | MTL_FAST_MATH = YES; 447 | SDKROOT = iphoneos; 448 | SWIFT_COMPILATION_MODE = wholemodule; 449 | VALIDATE_PRODUCT = YES; 450 | }; 451 | name = Release; 452 | }; 453 | 4B0B05692BE5B450002BC7AF /* Debug */ = { 454 | isa = XCBuildConfiguration; 455 | buildSettings = { 456 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 457 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 458 | CODE_SIGN_STYLE = Automatic; 459 | CURRENT_PROJECT_VERSION = 1; 460 | DEVELOPMENT_ASSET_PATHS = "\"TestApp-iOS/Preview Content\""; 461 | DEVELOPMENT_TEAM = 59Q22VRDBY; 462 | ENABLE_PREVIEWS = YES; 463 | GENERATE_INFOPLIST_FILE = YES; 464 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 465 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 466 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 467 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 468 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 469 | LD_RUNPATH_SEARCH_PATHS = ( 470 | "$(inherited)", 471 | "@executable_path/Frameworks", 472 | ); 473 | MARKETING_VERSION = 1.0; 474 | PRODUCT_BUNDLE_IDENTIFIER = test.tim.TestApp; 475 | PRODUCT_NAME = "$(TARGET_NAME)"; 476 | SWIFT_EMIT_LOC_STRINGS = YES; 477 | SWIFT_VERSION = 5.0; 478 | TARGETED_DEVICE_FAMILY = "1,2"; 479 | }; 480 | name = Debug; 481 | }; 482 | 4B0B056A2BE5B450002BC7AF /* Release */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 486 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 487 | CODE_SIGN_STYLE = Automatic; 488 | CURRENT_PROJECT_VERSION = 1; 489 | DEVELOPMENT_ASSET_PATHS = "\"TestApp-iOS/Preview Content\""; 490 | DEVELOPMENT_TEAM = 59Q22VRDBY; 491 | ENABLE_PREVIEWS = YES; 492 | GENERATE_INFOPLIST_FILE = YES; 493 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 494 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 495 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 496 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 497 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 498 | LD_RUNPATH_SEARCH_PATHS = ( 499 | "$(inherited)", 500 | "@executable_path/Frameworks", 501 | ); 502 | MARKETING_VERSION = 1.0; 503 | PRODUCT_BUNDLE_IDENTIFIER = test.tim.TestApp; 504 | PRODUCT_NAME = "$(TARGET_NAME)"; 505 | SWIFT_EMIT_LOC_STRINGS = YES; 506 | SWIFT_VERSION = 5.0; 507 | TARGETED_DEVICE_FAMILY = "1,2"; 508 | }; 509 | name = Release; 510 | }; 511 | 4B0B05842BE5C452002BC7AF /* Debug */ = { 512 | isa = XCBuildConfiguration; 513 | buildSettings = { 514 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 515 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 516 | CODE_SIGN_ENTITLEMENTS = "TestApp-Macos/TestApp_Macos.entitlements"; 517 | CODE_SIGN_STYLE = Automatic; 518 | COMBINE_HIDPI_IMAGES = YES; 519 | CURRENT_PROJECT_VERSION = 1; 520 | DEVELOPMENT_ASSET_PATHS = "\"TestApp-Macos/Preview Content\""; 521 | DEVELOPMENT_TEAM = 59Q22VRDBY; 522 | ENABLE_HARDENED_RUNTIME = YES; 523 | ENABLE_PREVIEWS = YES; 524 | GENERATE_INFOPLIST_FILE = YES; 525 | INFOPLIST_KEY_NSHumanReadableCopyright = ""; 526 | LD_RUNPATH_SEARCH_PATHS = ( 527 | "$(inherited)", 528 | "@executable_path/../Frameworks", 529 | ); 530 | MACOSX_DEPLOYMENT_TARGET = 14.2; 531 | MARKETING_VERSION = 1.0; 532 | PRODUCT_BUNDLE_IDENTIFIER = "test.tim.TestApp-Macos"; 533 | PRODUCT_NAME = "$(TARGET_NAME)"; 534 | SDKROOT = macosx; 535 | SWIFT_EMIT_LOC_STRINGS = YES; 536 | SWIFT_VERSION = 5.0; 537 | }; 538 | name = Debug; 539 | }; 540 | 4B0B05852BE5C452002BC7AF /* Release */ = { 541 | isa = XCBuildConfiguration; 542 | buildSettings = { 543 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 544 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 545 | CODE_SIGN_ENTITLEMENTS = "TestApp-Macos/TestApp_Macos.entitlements"; 546 | CODE_SIGN_STYLE = Automatic; 547 | COMBINE_HIDPI_IMAGES = YES; 548 | CURRENT_PROJECT_VERSION = 1; 549 | DEVELOPMENT_ASSET_PATHS = "\"TestApp-Macos/Preview Content\""; 550 | DEVELOPMENT_TEAM = 59Q22VRDBY; 551 | ENABLE_HARDENED_RUNTIME = YES; 552 | ENABLE_PREVIEWS = YES; 553 | GENERATE_INFOPLIST_FILE = YES; 554 | INFOPLIST_KEY_NSHumanReadableCopyright = ""; 555 | LD_RUNPATH_SEARCH_PATHS = ( 556 | "$(inherited)", 557 | "@executable_path/../Frameworks", 558 | ); 559 | MACOSX_DEPLOYMENT_TARGET = 14.2; 560 | MARKETING_VERSION = 1.0; 561 | PRODUCT_BUNDLE_IDENTIFIER = "test.tim.TestApp-Macos"; 562 | PRODUCT_NAME = "$(TARGET_NAME)"; 563 | SDKROOT = macosx; 564 | SWIFT_EMIT_LOC_STRINGS = YES; 565 | SWIFT_VERSION = 5.0; 566 | }; 567 | name = Release; 568 | }; 569 | 4BEE1DB72BE70024001CE949 /* Debug */ = { 570 | isa = XCBuildConfiguration; 571 | buildSettings = { 572 | CODE_SIGN_STYLE = Automatic; 573 | DEVELOPMENT_TEAM = 59Q22VRDBY; 574 | ENABLE_HARDENED_RUNTIME = YES; 575 | MACOSX_DEPLOYMENT_TARGET = 14.2; 576 | PRODUCT_NAME = "$(TARGET_NAME)"; 577 | SDKROOT = macosx; 578 | SWIFT_VERSION = 5.0; 579 | }; 580 | name = Debug; 581 | }; 582 | 4BEE1DB82BE70024001CE949 /* Release */ = { 583 | isa = XCBuildConfiguration; 584 | buildSettings = { 585 | CODE_SIGN_STYLE = Automatic; 586 | DEVELOPMENT_TEAM = 59Q22VRDBY; 587 | ENABLE_HARDENED_RUNTIME = YES; 588 | MACOSX_DEPLOYMENT_TARGET = 14.2; 589 | PRODUCT_NAME = "$(TARGET_NAME)"; 590 | SDKROOT = macosx; 591 | SWIFT_VERSION = 5.0; 592 | }; 593 | name = Release; 594 | }; 595 | /* End XCBuildConfiguration section */ 596 | 597 | /* Begin XCConfigurationList section */ 598 | 4B0B05552BE5B44E002BC7AF /* Build configuration list for PBXProject "TestApp" */ = { 599 | isa = XCConfigurationList; 600 | buildConfigurations = ( 601 | 4B0B05662BE5B450002BC7AF /* Debug */, 602 | 4B0B05672BE5B450002BC7AF /* Release */, 603 | ); 604 | defaultConfigurationIsVisible = 0; 605 | defaultConfigurationName = Release; 606 | }; 607 | 4B0B05682BE5B450002BC7AF /* Build configuration list for PBXNativeTarget "TestApp-iOS" */ = { 608 | isa = XCConfigurationList; 609 | buildConfigurations = ( 610 | 4B0B05692BE5B450002BC7AF /* Debug */, 611 | 4B0B056A2BE5B450002BC7AF /* Release */, 612 | ); 613 | defaultConfigurationIsVisible = 0; 614 | defaultConfigurationName = Release; 615 | }; 616 | 4B0B05832BE5C452002BC7AF /* Build configuration list for PBXNativeTarget "TestApp-Macos" */ = { 617 | isa = XCConfigurationList; 618 | buildConfigurations = ( 619 | 4B0B05842BE5C452002BC7AF /* Debug */, 620 | 4B0B05852BE5C452002BC7AF /* Release */, 621 | ); 622 | defaultConfigurationIsVisible = 0; 623 | defaultConfigurationName = Release; 624 | }; 625 | 4BEE1DB92BE70024001CE949 /* Build configuration list for PBXNativeTarget "swiftllama" */ = { 626 | isa = XCConfigurationList; 627 | buildConfigurations = ( 628 | 4BEE1DB72BE70024001CE949 /* Debug */, 629 | 4BEE1DB82BE70024001CE949 /* Release */, 630 | ); 631 | defaultConfigurationIsVisible = 0; 632 | defaultConfigurationName = Release; 633 | }; 634 | /* End XCConfigurationList section */ 635 | 636 | /* Begin XCLocalSwiftPackageReference section */ 637 | 4B1335012BE5C58A0020AB8E /* XCLocalSwiftPackageReference ".." */ = { 638 | isa = XCLocalSwiftPackageReference; 639 | relativePath = ..; 640 | }; 641 | /* End XCLocalSwiftPackageReference section */ 642 | 643 | /* Begin XCSwiftPackageProductDependency section */ 644 | 4BB1E3E02BE6464F00F1D21A /* SwiftLlama */ = { 645 | isa = XCSwiftPackageProductDependency; 646 | productName = SwiftLlama; 647 | }; 648 | 4BB1E3E22BE6466A00F1D21A /* SwiftLlama */ = { 649 | isa = XCSwiftPackageProductDependency; 650 | productName = SwiftLlama; 651 | }; 652 | 4BEE1DBA2BE7003E001CE949 /* SwiftLlama */ = { 653 | isa = XCSwiftPackageProductDependency; 654 | productName = SwiftLlama; 655 | }; 656 | /* End XCSwiftPackageProductDependency section */ 657 | }; 658 | rootObject = 4B0B05522BE5B44E002BC7AF /* Project object */; 659 | } 660 | -------------------------------------------------------------------------------- /TestProjects/TestApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TestProjects/TestApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "originHash" : "b2becbcc0254795d9a140b56614e328e9054fc0127630faeab494795dc5b48bf", 3 | "pins" : [ 4 | { 5 | "identity" : "llama.cpp", 6 | "kind" : "remoteSourceControl", 7 | "location" : "https://github.com/ggerganov/llama.cpp.git", 8 | "state" : { 9 | "branch" : "master", 10 | "revision" : "96b69121033d2b6b951d1b6b1b43f8b4f97dac99" 11 | } 12 | } 13 | ], 14 | "version" : 3 15 | } 16 | -------------------------------------------------------------------------------- /TestProjects/TestApp.xcodeproj/xcshareddata/xcschemes/TestApp-Commandline.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 43 | 45 | 51 | 52 | 53 | 54 | 57 | 58 | 59 | 60 | 66 | 68 | 74 | 75 | 76 | 77 | 79 | 80 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /TestProjects/TestApp.xcodeproj/xcshareddata/xcschemes/TestApp-iOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 42 | 44 | 50 | 51 | 52 | 53 | 59 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Tests/SwiftLlamaTests/SwiftLlamaTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import SwiftLlama 3 | 4 | final class SwiftLlamaTests: XCTestCase { 5 | 6 | } 7 | --------------------------------------------------------------------------------