Skip to content

Commit b8f2f74

Browse files
committed
fix: correct stream completion detection in OpenAI response
The stream was not properly detecting completion state in chat responses. Changed the done condition to check for finish_reason presence instead of relying on content parsing. This fixes premature stream termination and ensures all response chunks are properly processed.
1 parent 1281aa0 commit b8f2f74

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Core/Sources/CodeCompletionService/API/OpenAIService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ extension OpenAIService {
170170
ChatCompletionsStreamDataChunk.self,
171171
from: text.data(using: .utf8) ?? Data()
172172
)
173-
return .init(chunk: chunk, done: chunk.choices?.first?.delta?.content != nil)
173+
return .init(chunk: chunk, done: chunk.choices?.first?.finish_reason != nil)
174174
} catch {
175175
print(error)
176176
throw error

0 commit comments

Comments
 (0)