[Firebase AI] Add URLContext tool #15221
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Added support for the
URLContexttool which allows developers to provide additional context to the models in the form of URLs.TODO: A subsequent PR(or CL) should update the changelog with a link to the docs.
Summary of Changes
This pull request integrates the
URLContexttool into the Firebase AI SDK, enabling Gemini models to utilize external web content from provided URLs to enrich their responses. This feature enhances the model's ability to understand and generate content based on real-world information, making it more versatile for various applications. The changes involve adding new data models for URL context, updating response structures to include this metadata, and ensuring robust error handling and logging for URL retrieval processes.Highlights
URLContexttool, allowing developers to provide public web URLs as additional context to Gemini models for more informed responses.URLContext,URLContextMetadata, andURLMetadatastructs to handle URL-based context information within the API.GenerateContentResponseandCandidatestructs now includeurlContextMetadataand new token count properties (toolUsePromptTokenCount,toolUsePromptTokensDetails) for better usage tracking.AILog.MessageCode(urlMetadataUnrecognizedURLRetrievalStatus) has been added for improved logging related to URL retrieval status.URLContexttool across different scenarios, including successful retrievals, mixed validity, and streaming responses.Changelog
urlMetadataUnrecognizedURLRetrievalStatustoAILog.MessageCode.toolUsePromptTokenCountandtoolUsePromptTokensDetailstoUsageMetadata.urlContextMetadatatoCandidateand its initializer.Decodableconformance forUsageMetadataandCandidateto handle new fields.urlContextproperty toToolstruct.Tool.urlContext()to create aURLContexttool.URLContextstruct.URLContextMetadatastruct and itsDecodableconformance.URLMetadatastruct,URLRetrievalStatusenum, and itsDecodableconformance.generateContent_withURLContext_succeedsto verify the functionality.generateContent_success_urlContext,generateContent_success_urlContext_mixedValidity, andtestGenerateContentStream_success_urlContext.generateContent_success_urlContext,generateContent_success_urlContext_mixedValidity,testGenerateContent_success_urlContext_retrievedURLPresentOnErrorStatus, andtestGenerateContentStream_success_urlContext.requestHandlerguard statement for clarity.CandidatewithurlContextMetadata.Activity
/gemini summarizecommand.