Skip to content

Add google-genai to docker image #1455

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

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kaggle_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ google-cloud-automl==1.0.1
google-cloud-translate==3.12.1
google-cloud-videointelligence
google-cloud-vision
google-genai
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any meaningful tests we could write for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added some tests

gpxpy
h2o
haversine
Expand Down
55 changes: 55 additions & 0 deletions tests/test_google_genai_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import json
import unittest
import threading

from test.support.os_helper import EnvironmentVarGuard
from urllib.parse import urlparse

from http.server import BaseHTTPRequestHandler, HTTPServer

class HTTPHandler(BaseHTTPRequestHandler):
called = False
path = None
headers = {}

def do_HEAD(self):
self.send_response(200)

def do_POST(self):
HTTPHandler.path = self.path
HTTPHandler.headers = self.headers
HTTPHandler.called = True
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()

class TestGoogleGenAiPatch(unittest.TestCase):
endpoint = "http://127.0.0.1:80"

def test_proxy_enabled(self):
env = EnvironmentVarGuard()
secrets_token = "secrets_token"
proxy_token = "proxy_token"
env.set("KAGGLE_USER_SECRETS_TOKEN", secrets_token)
env.set("KAGGLE_DATA_PROXY_TOKEN", proxy_token)
env.set("KAGGLE_DATA_PROXY_URL", self.endpoint)
server_address = urlparse(self.endpoint)
with env:
with HTTPServer((server_address.hostname, server_address.port), HTTPHandler) as httpd:
threading.Thread(target=httpd.serve_forever).start()
from google import genai
api_key = "NotARealAPIKey"
client = genai.Client(api_key = api_key)
try:
client.models.generate_content(
model="gemini-2.0-flash-exp",
contents="What's the largest planet in our solar system?"
)
except:
pass
httpd.shutdown()
self.assertTrue(HTTPHandler.called)
self.assertIn("/palmapi", HTTPHandler.path)
self.assertEqual(proxy_token, HTTPHandler.headers["x-kaggle-proxy-data"])
self.assertEqual("Bearer {}".format(secrets_token), HTTPHandler.headers["x-kaggle-authorization"])
self.assertEqual(api_key, HTTPHandler.headers["x-goog-api-key"])
Loading