diff --git a/Sources/OllamaKit/Utils/OKHTTPClient.swift b/Sources/OllamaKit/Utils/OKHTTPClient.swift index 85c702d..34644c8 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() } } @@ -131,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)) @@ -146,9 +149,6 @@ private extension OKHTTPClient { switch character { case "{": nestingDepth += 1 - if nestingDepth == 1 { - objectStartIndex = index - } case "}": nestingDepth -= 1 if nestingDepth == 0 {