dylanshine / openai-kit

A community Swift package used to interact with the OpenAI API
https://platform.openai.com/docs/api-reference
MIT License
712 stars 113 forks source link

Crash in RequestHandler stream(request:) #43

Closed JSky74 closed 1 year ago

JSky74 commented 1 year ago

After cancelling a Task, this preconditionFailure is triggered:

preconditionFailure( "Tried to use a second iterator on response body stream. Multiple iterators are not supported.", file: file, line: line )

Workaround is to only call continuation.finish(throwing: error) in the catch block of stream(request:) in RequestHandler and remove this: let data = try? await response.body.reduce(into: Data()) { $0.append(.init(buffer: $1)) }

dylanshine commented 1 year ago

@JSky74 Do you want to make a PR with that change? I can here in a little in not

JSky74 commented 1 year ago

@dylanshine Opened a PR.