Skip to content

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

Conversation

eapl-gemugami
Copy link
Contributor

Description

Fixes Internal:
b/393632125

  • 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

Checklist

…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
@product-auto-label product-auto-label bot added api: documentai Issues related to the Document AI API. samples Issues that are directly related to samples. labels Mar 25, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 with documentai_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 with documentai_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.
  • 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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's processor_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.

@eapl-gemugami eapl-gemugami added the snippet-bot:force-run Force snippet-bot runs its logic label Mar 25, 2025
@snippet-bot snippet-bot bot removed the snippet-bot:force-run Force snippet-bot runs its logic label Mar 25, 2025
Copy link

snippet-bot bot commented Mar 25, 2025

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.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@eapl-gemugami eapl-gemugami marked this pull request as ready for review March 25, 2025 19:49
@eapl-gemugami eapl-gemugami requested review from a team as code owners March 25, 2025 19:49
@eapl-gemugami eapl-gemugami marked this pull request as draft March 25, 2025 19:51
@eapl-gemugami eapl-gemugami force-pushed the paradalicea/fix/documentai/quickstart-sample/b-393632125 branch from 8bd0da8 to 3965359 Compare March 25, 2025 19:53
@eapl-gemugami eapl-gemugami marked this pull request as ready for review March 25, 2025 20:11
@eapl-gemugami eapl-gemugami merged commit 0eb06ae into GoogleCloudPlatform:main Mar 25, 2025
11 checks passed
@eapl-gemugami eapl-gemugami deleted the paradalicea/fix/documentai/quickstart-sample/b-393632125 branch March 25, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: documentai Issues related to the Document AI API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants