Repository navigation
feat(firebase_ai): expose Live API usage metadata - #18962
jamesblasco wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for parsing and exporting usageMetadata within LiveServerResponse, along with comprehensive unit tests. The review feedback highlights opportunities to align with the repository's style guide by making the LiveServerResponse constructor const for immutability and refactoring the tests to avoid using the ! operator for null safety.
SelaseKay
left a comment
There was a problem hiding this comment.
Hi @jamesblasco, thanks for the PR. Analyze step needs resolving in ci.
da7327c to
b7c5a74
Compare
|
Thanks @jamesblasco for putting this together—and great catch on exporting Because adding In the meantime, one implementation detail we caught while testing the Live API wire format across both backends:
Because final candidatesTokenCount = switch (jsonObject) {
{'candidatesTokenCount': final int count} ||
{'responseTokenCount': final int count} =>
count,
_ => null,
}; final candidatesTokensDetails = switch (jsonObject) {
{'candidatesTokensDetails': final List<Object?> details} ||
{'responseTokensDetails': final List<Object?> details} =>
details.map(_parseModalityTokenCount).toList(),
_ => null,
};Could you also add a unit test in |
|
@cynthiajoan thanks for the review. Solved the problem you mentioned. Let's see what is the resolution about making the usageMetadata a public api |
Description
Live API responses currently discard top-level
usageMetadata. Add an optionalLiveServerResponse.usageMetadatafield and populate it with the existing usage metadata parser so callers can inspect token usage, including modality breakdowns. ExportContentModalityandModalityTokenCountthrough the public package API.Metadata remains available for metadata-only responses and unrecognized messages. Responses without metadata retain a null value. This is an additive, non-breaking change.
Validation
flutter test --no-pub --reporter expanded: 400 passed, 9 skipped.flutter analyze --no-pub lib test: no issues found.git diff --check: passed.example/lib/firebase_options.dartin the example integration tests (four existing configuration errors).Tests cover token counts and modality details, absent and null metadata, metadata-only responses, unknown messages, constructor compatibility, and public type exports.
Related Issues
None linked.