-
Notifications
You must be signed in to change notification settings - Fork 82
Add progress for OpenAI transcription request #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add progress for OpenAI transcription request #171
Conversation
|
@bilqisium this is cool! I think we can make this a nonbreaking change. You keep exactly what you have now, except you add a proto extension to That should make existing callers happy. Also, please add a check to the |
|
|
||
| private var progressCallback: ((Double) -> Void)? | ||
|
|
||
| public func setProgressCallback(_ callback: @escaping (Double) -> Void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any advantage to keeping these accessors versus changing the ACL to public on:
public var progressCallback: ((Double) -> Void)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No advantage indeed, it's much better to expose it indeed. 7982355
Thank you @lzell, I've made the requested changes respectively in a030d78 and edb0f14. |
|
Available in 0.106.0: https://github.com/lzell/AIProxySwift/releases/tag/0.106.0 Thank you @bilqisium ! |
| _ progressCallback: ((Double) -> Void)? = nil | ||
| ) async throws -> (Data, HTTPURLResponse) { | ||
| if let progressCallback { | ||
| (session.delegate as? AIProxyCertificatePinningDelegate)?.setProgressCallback(progressCallback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, we can now ditch these accessors and use (session.delegate as? AIProxyCertificatePinningDelegate)?.progressCallback = progressCallback since we exposed the member. I'll touch that up on main
This PR add progress report for OpenAI's transcription request, at least for the file uploading part.
I reused the
AIProxyCertificatePinningDelegateto hook into the delegate method reporting progress.Unfortunately, since Swift doesn't allow optional parameters in protocols, the
progressCallbackparameter is required at call site (but we can passnil). This can be seen as a breaking change.Also, it properly works only for
OpenAIProxiedService, since theOpenAIDirectServicearchitecture for having its URLSession doesn't allow injecting a delegate without significantly changing the internals.This means that
OpenAIDirectServicenever updates this callback, but it has to have it because of its conformance tothe
OpenAIServiceprotocol.The transcription part wasn't unit tested, so I didn't add any tests either.
I tried to adhere to the style of the library.
If you have ideas on how to improve this PR or want some fixes, I'll happily implement them.