-
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
Conversation
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.
Please write unit tests to make sure the new package and your patch work
Dockerfile.tmpl
Outdated
@@ -647,6 +651,10 @@ ADD patches/sitecustomize.py /root/.local/lib/python3.10/site-packages/sitecusto | |||
# Override default imagemagick policies | |||
ADD patches/imagemagick-policy.xml /etc/ImageMagick-6/policy.xml | |||
|
|||
# Add generativeai Python patch | |||
ADD patches/generativeaipatch.py /root/.local/lib/python3.10/site-packages/generativeaipatch.py | |||
CMD ["python", "/root/.local/lib/python3.10/site-packages/generativeaipatch.py"] |
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
if not hasattr(sys, 'frozen'): | |
sys.meta_path.insert(0, GcpModuleFinder()) |
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.
Add a test that calls a fake HTTP client and assert that the headers are set properly.
Example test with a test HTTP server: https://github.com/Kaggle/kagglehub/blob/66f2121adccae70f05c72594113a7e463fa6ddce/tests/test_http_model_download.py#L19
@@ -73,3 +75,27 @@ def exec_module(self, module): | |||
|
|||
if not hasattr(sys, 'frozen'): | |||
sys.meta_path.insert(0, GcpModuleFinder()) | |||
|
|||
@wrapt.when_imported('google.generativeai') |
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.
Is this called only the first time this module is imported or again every time?
To confirm, you can simply add a print statement and test in a notebook by running "import 'google.generativeai" a few times.
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.
It's only called the first time it seems.
Before merging, make sure to also test in the kernels editor using the |
patches/sitecustomize.py
Outdated
default_metadata = kwargs['default_metadata'] | ||
else: | ||
default_metadata = [] | ||
kwargs['transport'] = 'rest' # Only support REST requests for now |
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.
Because this is hard coded here, how are you going to enable grpc when it's ready? All the users using this image will have this code forever.
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.
I see, I'll set an environment variable then.
patches/sitecustomize.py
Outdated
client_options = kwargs['client_options'] | ||
else: | ||
client_options = {} | ||
client_options['api_endpoint'] = os.environ['KAGGLE_DATA_PROXY_URL'] + '/palmapi' |
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.
Same: hard coding this endpoint here means you will never be able to change it without breaking all the users using this image
Please also confirm that installing another version of the package doesn't break your import patch:
|
I'm guessing you were able to test this image and it worked as expected? |
@psbang I'm merging this PR for you to get ready for a release tomorrow morning. |
A patch for the generativeai Python package that makes sure all requests are directed through our data proxy and configurations are set accordingly.
http://b/308644984