Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Example/LocalLLMClientExample/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct ChatBubbleView: View {
}
}

#if DEBUG
#Preview("Text") {
@Previewable @State var ai: AI = {
let ai = AI()
Expand All @@ -128,6 +129,7 @@ struct ChatBubbleView: View {
}
.environment(ai)
}
#endif

extension LLMAttachment {
static let imagePreview = try! Self.image(LLMInputImage(data: .init(contentsOf: URL(string: "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/cats.jpeg")!))!)
Expand Down
9 changes: 6 additions & 3 deletions Sources/LocalLLMClientLlama/stb_image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import Accelerate
import CoreImage

@used
Comment thread
iborusik marked this conversation as resolved.
Outdated
@_silgen_name("stbi_load_from_memory")
func stbi_load_from_memory(_ buffer: UnsafePointer<UInt8>, _ len: UInt64, _ x: UnsafeMutablePointer<Int32>, _ y: UnsafeMutablePointer<Int32>, _ comp: UnsafeMutablePointer<Int32>, _ req_comp: Int32) -> UnsafeMutableRawPointer? {
public func stbi_load_from_memory(_ buffer: UnsafePointer<UInt8>, _ len: UInt64, _ x: UnsafeMutablePointer<Int32>, _ y: UnsafeMutablePointer<Int32>, _ comp: UnsafeMutablePointer<Int32>, _ req_comp: Int32) -> UnsafeMutableRawPointer? {
assert(req_comp == 3, "Only RGB format is supported")

let data = Data(bytes: buffer, count: Int(len))
Expand All @@ -19,8 +20,9 @@ func stbi_load_from_memory(_ buffer: UnsafePointer<UInt8>, _ len: UInt64, _ x:
return rgbBytes
}

@used
Comment thread
iborusik marked this conversation as resolved.
Outdated
@_silgen_name("stbi_load")
func stbi_load(_ filename: UnsafePointer<CChar>, _ x: UnsafeMutablePointer<Int32>, _ y: UnsafeMutablePointer<Int32>, _ comp: UnsafeMutablePointer<Int32>, _ req_comp: Int32) -> UnsafeMutableRawPointer? {
public func stbi_load(_ filename: UnsafePointer<CChar>, _ x: UnsafeMutablePointer<Int32>, _ y: UnsafeMutablePointer<Int32>, _ comp: UnsafeMutablePointer<Int32>, _ req_comp: Int32) -> UnsafeMutableRawPointer? {
assert(req_comp == 3, "Only RGB format is supported")

guard let url = URL(string: String(cString: filename)),
Expand All @@ -36,8 +38,9 @@ func stbi_load(_ filename: UnsafePointer<CChar>, _ x: UnsafeMutablePointer<Int32
return rgbBytes
}

@used
Comment thread
iborusik marked this conversation as resolved.
Outdated
@_silgen_name("stbi_image_free")
func stbi_image_free(_ buffer: UnsafeMutableRawPointer) {
public func stbi_image_free(_ buffer: UnsafeMutableRawPointer) {
buffer.assumingMemoryBound(to: UInt8.self).deallocate()
}

Expand Down