-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Introduce Gemini Model Handler #35036
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
|
Assigning reviewers: R: @liferoad for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
| """ A sample pipeline using the RunInference API to classify text using an LLM. | ||
| This pipeline creates a set of prompts and sends it to a Gemini service then | ||
| returns the predictions from the classifier model. This example uses the | ||
| gemini-2.0-flash-001 model. |
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.
probably need to update sdks/python/apache_beam/examples/inference/README.md with a new remote handler section.
| """ | ||
| if not isinstance(exception, errors.APIError): | ||
| return False | ||
| return exception.code == 429 or exception.code >= 500 |
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.
Shall we log these to make this more explicit to users?
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.
exceptions get logged by the RemoteModelHandler, no need to log them here (
| except Exception as e: |
| Args: | ||
| batch: a sequence of any values to be passed to the Gemini service. | ||
| Should be a list of strings. |
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.
Sequence[Any]: I assume we plan to support other types soon. So we use Any here, right?
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.
Ah yeah that was a missed line, I originally wrote this as string-only but decided it was better in the long-term to go ahead and make it more general. Let me update that docstring
Introduces a basic Gemini Model Handler along with an example and tests. Currently provides a function for text prompts and responses, but is written to be extensible by allowing for custom request functions. The Gemini SDK contains a large amount of options, so this allows for the most general model handler possible (although post-processing to pull the responses out of the nested return type will still be necessary.)
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.