-
Notifications
You must be signed in to change notification settings - Fork 972
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
Patching for generativeai Python package #1329
Merged
Merged
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bb9b855
Patching for Python package
psbang 6508445
Typo fix
psbang 684dc6a
Run python script instead of just adding it to docker image
psbang a49c250
Try using ADD and CMD
psbang de9912c
Add logic to sitecustomize
psbang 3477d4d
Escape path
psbang a3c4b16
Address comments
psbang f301127
Merge branch 'main' into psbang-genaipatch
psbang 4c4240a
Check for another env variable
psbang 5e53b3d
Merge branch 'main' into psbang-genaipatch
psbang 5a1504a
Address comments
psbang 4c5f7cd
Build fix hopefully
psbang 7d4f55d
Add unit test for headers
psbang a06ec16
bug fix
psbang 0f7eaa5
Fix import issue and test
psbang f1559e0
small modification
psbang f89b6a2
add a test for disabled proxy for generativeai api
Philmod a9d45f9
remove print
Philmod f7b69ea
change name of test
Philmod dfb9145
remove disabled test to check if that's the reason it's broken on ci
Philmod ff335d6
readd disabled test
Philmod 10b9a81
readd disabled test
Philmod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import wrapt | ||
import os | ||
|
||
@wrapt.when_imported('google.generativeai') | ||
def post_import_logic(module): | ||
old_configure = module.configure | ||
Philmod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def new_configure(*args, **kwargs): | ||
if ('default_metadata' in kwargs): | ||
default_metadata = kwargs['default_metadata'] | ||
else: | ||
default_metadata = [] | ||
kwargs['transport'] = 'rest' # Only support REST requests for now | ||
default_metadata.append(("x-kaggle-proxy-data", os.environ['KAGGLE_DATA_PROXY_TOKEN'])) | ||
Philmod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default_metadata.append(('x-kaggle-authorization', f'Bearer {os.environ['KAGGLE_USER_SECRETS_TOKEN']}')) | ||
kwargs['default_metadata'] = default_metadata | ||
if ('client_options' in kwargs): | ||
client_options = kwargs['client_options'] | ||
else: | ||
client_options = {} | ||
client_options['api_endpoint'] = os.environ['KAGGLE_DATA_PROXY_URL'] + '/palmapi' | ||
Philmod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kwargs['client_options'] = client_options | ||
old_configure(*args, **kwargs) | ||
module.configure = new_configure | ||
module.configure() # generativeai can use GOOGLE_API_KEY env variable, so make sure we have the other configs set |
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.
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.
CMD is the Dockerfile instruction to update the command that is run when you start a container with the image. Do not update the CMD.
You can add logic that needs to be called to sitecustomize.py which gets call when a notebook session starts up.
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.
e.g.
docker-python/patches/sitecustomize.py
Lines 74 to 75 in 823af9a