From b8befeb1b3bc9dc7133f0fccc4336316c22decf9 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 21 Mar 2025 10:16:27 +0100 Subject: [PATCH 1/3] Do not adjust start index, to ensure we consume the whitespaces/newlines too. --- Sources/OllamaKit/Utils/OKHTTPClient.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sources/OllamaKit/Utils/OKHTTPClient.swift b/Sources/OllamaKit/Utils/OKHTTPClient.swift index 85c702d..9ed3ffc 100644 --- a/Sources/OllamaKit/Utils/OKHTTPClient.swift +++ b/Sources/OllamaKit/Utils/OKHTTPClient.swift @@ -146,9 +146,6 @@ private extension OKHTTPClient { switch character { case "{": nestingDepth += 1 - if nestingDepth == 1 { - objectStartIndex = index - } case "}": nestingDepth -= 1 if nestingDepth == 0 { From 4bcccb264d6d3a48ecf5c0c995c80bdf36d60cc9 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 21 Mar 2025 10:24:17 +0100 Subject: [PATCH 2/3] Make sure cancelation of Combine stream triggers cancellation of URLSessionDataTask --- Sources/OllamaKit/Utils/OKHTTPClient.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/OllamaKit/Utils/OKHTTPClient.swift b/Sources/OllamaKit/Utils/OKHTTPClient.swift index 9ed3ffc..62bfbb8 100644 --- a/Sources/OllamaKit/Utils/OKHTTPClient.swift +++ b/Sources/OllamaKit/Utils/OKHTTPClient.swift @@ -116,6 +116,9 @@ internal extension OKHTTPClient { .setFailureType(to: Error.self) .eraseToAnyPublisher() } + .handleEvents(receiveCancel: { + task.cancel() + }) .eraseToAnyPublisher() } } From ebdbc9871ca1fb4e244d982f08f843e0a27adf34 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 21 Mar 2025 12:57:07 +0100 Subject: [PATCH 3/3] Fix warning --- Sources/OllamaKit/Utils/OKHTTPClient.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/OllamaKit/Utils/OKHTTPClient.swift b/Sources/OllamaKit/Utils/OKHTTPClient.swift index 62bfbb8..34644c8 100644 --- a/Sources/OllamaKit/Utils/OKHTTPClient.swift +++ b/Sources/OllamaKit/Utils/OKHTTPClient.swift @@ -134,8 +134,8 @@ private extension OKHTTPClient { var isEscaped = false var isWithinString = false var nestingDepth = 0 - var objectStartIndex = buffer.startIndex - + let objectStartIndex = buffer.startIndex + for (index, byte) in buffer.enumerated() { let character = Character(UnicodeScalar(byte))