-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Streamable HTTPCallable functions #14290
base: main
Are you sure you want to change the base?
Conversation
Add initial support for Streamable functions.
Change call to AsyncThrowingStream<HTTPSCallableResult, Error>
Remove old test function.
Remove old test
Add a full working test for stremableFunction. Refactor.
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Add Json capabilities to parse an HTTP result back and forth. Updating Unit tests.
Cleanup
Add doc for processResponseDataForStreamableContent.
Update func to have a callback. Update UnitTests
Remove test.
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.
Thanks for the PR. We'll need an approved API review before doing a detailed code review. However, in the meantime, it would be helpful to make this PR a clean diff to main
that can run CI.
@paulb777 Thanks Paul, Done. |
Fetch Main branch.
…/firebase-ios-sdk into iOS-Stremable-Functions
Updated to renamed code. From callableResultFromResponse to callableResult
Run style.sh
Fix concurrency " mutation of captured var 'response' in concurrently-executing code" and typos.
This file is not needed.
This file is not needed.
Add throws Remove DO - CATCH
…/firebase-ios-sdk into iOS-Stremable-Functions
Accept suggestion. Thanks. Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
Remove optionals.
…/firebase-ios-sdk into iOS-Stremable-Functions
Revert func to non DISPACTCH. Will work on a fix with @ncooke3
For the You can use it a few ways, but I like to either pass it a list of files:
Or periodically style all of the files I touched in my branch:
Then git add and commit the result. If the script fails, it's likely due to missing packages, you'll need:
|
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.
nit: make result
a constant since it doesn't need to change past initialization
Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
Accepted suggestion. Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
let rawData = try await fetcher.beginFetch() | ||
return try callableResultFromResponseAsync(data: rawData, error: nil) |
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.
I just came across one subtle issue is that GTMSessionFetcher is returning the entire data result at once rather than chunks of the stream. It doesn't look like GTMSessionFetcher supports receiving streams so we may have to change this up and use the standard library's URLSession and URLSession.AsyncBytes
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.
Sure, I'll get to it. I was trying to keep it as closest as possible to HTTPCallable. It is subtle but quite important.
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.
I'd recommend following what the Vertex SDK does. Here is the method that loads the request stream: https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseVertexAI/Sources/GenerativeAIService.swift#L82-L176
I'm thinking the implementation here won't be as complex.
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.
SGTM.
@@ -358,4 +358,73 @@ class FunctionsTests: XCTestCase { | |||
} | |||
waitForExpectations(timeout: 1.5) | |||
} | |||
|
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.
I think another good test case would be to test when an error is thrown.
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.
I think we would have (genStream, genStreamError, genStreamNoReturn)
So I will add genStreamError and genStreamNoReturn cases as well.
SG??
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.
SGTM.
Mark it as public. Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
"chunk this", | ||
"chunk is", | ||
"chunk cool", | ||
"hello world this is cool", |
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.
I suspect this final concatenation was a result of GTMSessionFetcher handling the streamed results. I don't expect it with URLSession and AsyncBytes
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.
With #14357 merged, we should be able to get these passing in CI now. This can be done by moving these new tests to the integration test file and use the emulatorURL
helper method for the stream
API's at URL: URL
property. https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseFunctions/Tests/Integration/IntegrationTests.swift
Hey there! So you want to contribute to a Firebase SDK?
Before you file this pull request, please read these guidelines:
Discussion
If not, go file an issue about this before creating a pull request to discuss.
Testing
API Changes
us make Firebase APIs better, please propose your change in a feature request so that we
can discuss it together.