-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix(documentai): refactor 'documentai_quickstart' sample for latest style guide #13256
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
fix(documentai): refactor 'documentai_quickstart' sample for latest style guide #13256
Conversation
…tyle guide - Move the sample inside the function so it's easier to read and run - Rewrite comments - Replace call to 'documentai' with 'documentai_v1', to make it easier to identify which version is being used - Add type hints - Replace checking stderr/out to assert returned objects
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.
Hello @eapl-gemugami, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request refactors the documentai_quickstart
sample to align with the latest style guide. The changes include moving the sample code inside a function, rewriting comments, replacing calls to documentai
with documentai_v1
for clarity, adding type hints, and replacing stderr/out checks with assertions on returned objects. The test file was also updated to reflect these changes.
Highlights
- Refactor: The sample code is now encapsulated within a function to improve readability and ease of execution.
- Version Specificity: Replaced generic
documentai
import withdocumentai_v1
to explicitly denote the version being used. - Type Hinting: Added type hints to the function signature and variables for better code clarity and maintainability.
- Test Improvement: Replaced stdout/stderr checks in tests with direct assertions on the returned objects for more robust testing.
Changelog
Click here to see the changelog
- documentai/snippets/quickstart_sample.py
- Moved the sample code inside the
quickstart
function. - Rewrote comments to improve clarity and provide better context.
- Replaced
documentai
withdocumentai_v1
to specify the Document AI version. - Added type hints to the function signature and variables.
- Updated the return value to return both the processor and the document.
- Updated the imports to use
documentai_v1
types.
- Moved the sample code inside the
- documentai/snippets/quickstart_sample_test.py
- Updated the test to assert the returned processor is not None.
- Updated the test to assert that the document text contains 'Invoice'.
- Updated the client initialization to use
documentai_v1
. - Removed the
capsys
fixture and stdout/stderr assertions. - Updated variable names to be uppercase constants.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A sample's plight, to be clear and bright,
Refactored now, a welcome sight.
With types defined and versions known,
Its purpose shines, distinctly shown.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request refactors the 'documentai_quickstart' sample to align with the latest style guide, improving readability and maintainability. The changes include moving the sample inside a function, rewriting comments, using 'documentai_v1' for clarity, adding type hints, and replacing stderr/out checks with object assertions. Overall, the changes are well-structured and enhance the sample's quality.
Summary of Findings
- Type Hinting: The
quickstart
function'sprocessor_display_name
parameter lacks a type hint, which should be added for clarity and to ensure type safety. - Variable Naming: The test file uses uppercase variable names (e.g.,
LOCATION
,PROJECT_ID
), which is generally reserved for constants. Consider using lowercase names for better readability and adherence to common Python conventions.
Merge Readiness
The pull request is well-structured and addresses the stated goals of refactoring the sample for better readability and style guide adherence. However, addressing the missing type hint and variable naming conventions would further improve the code quality. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.
Here is the summary of changes. You are about to add 1 region tag.
You are about to delete 1 region tag.
This comment is generated by snippet-bot.
|
8bd0da8
to
3965359
Compare
Description
Fixes Internal:
b/393632125
Checklist
nox -s py-3.9
(see Test Environment Setup)nox -s lint
(see Test Environment Setup)