### Calling SwiftLlama without Streaming Source: https://github.com/shenghaiwang/swiftllama/blob/main/README.md This snippet illustrates a synchronous (non-streaming) call to the `start` method of `SwiftLlama`. It awaits the full response as a single string for a given prompt, suitable for scenarios where the entire output is needed at once. ```Swift let response: String = try await swiftLlama.start(for: prompt) ``` -------------------------------- ### Installing SwiftLlama using Swift Package Manager Source: https://github.com/shenghaiwang/swiftllama/blob/main/README.md This snippet shows how to add SwiftLlama as a dependency to your Swift project using Swift Package Manager. It specifies the Git repository URL and the minimum version required for integration. ```Swift .package(url: "https://github.com/ShenghaiWang/SwiftLlama.git", from: "0.3.0") ``` -------------------------------- ### Streaming Responses with AsyncStream in SwiftLlama Source: https://github.com/shenghaiwang/swiftllama/blob/main/README.md This example shows how to consume streaming responses from SwiftLlama using Swift's `AsyncStream`. It iterates over chunks of the response as they become available, appending them to a `result` variable, which is ideal for real-time output display. ```Swift for try await value in await swiftLlama.start(for: prompt) { result += value } ``` -------------------------------- ### Streaming Responses with Combine Publisher in SwiftLlama Source: https://github.com/shenghaiwang/swiftllama/blob/main/README.md This snippet demonstrates how to handle streaming responses from SwiftLlama using Apple's Combine framework. It subscribes to the publisher returned by `start`, appending received values to a `result` property and managing the subscription with a `cancellable` set, fitting into reactive programming patterns. ```Swift await swiftLlama.start(for: prompt) .sink { _ in } receiveValue: {[weak self] value in self?.result += value }.store(in: &cancallable) ``` -------------------------------- ### Initializing SwiftLlama with a Model Path Source: https://github.com/shenghaiwang/swiftllama/blob/main/README.md This code demonstrates how to create an instance of `SwiftLlama` by providing the file path to a compatible large language model. This is the essential first step before making any model inference calls. ```Swift let swiftLlama = try SwiftLlama(modelPath: path)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.