Skip to content

Commit bda026e

Browse files
authored
Fix for truncated response because of AsyncStream issue in ChatGPTAPI
1 parent e5000a9 commit bda026e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Shared/ChatGPTAPI.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ class ChatGPTAPI: LLMClient, @unchecked Sendable {
102102
var responseText = ""
103103
let streams: AsyncThrowingStream<String, Error> = AsyncThrowingStream { continuation in
104104
Task {
105-
for try await line in result.lines {
106-
try Task.checkCancellation()
107-
continuation.yield(line)
105+
do {
106+
for try await line in result.lines {
107+
try Task.checkCancellation()
108+
continuation.yield(line)
109+
}
110+
continuation.finish()
111+
} catch {
112+
continuation.finish(throwing: error)
108113
}
109-
continuation.finish()
110114
}
111115
}
112116

0 commit comments

Comments
 (0)