-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add Project IDX support #318
base: main
Are you sure you want to change the base?
Changes from all commits
cf165d6
77cca61
392ab3d
be12f78
6895060
768280e
7d0e50a
df2a409
1b66440
36f5d3d
1606e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# To learn more about how to use Nix to configure your environment | ||
# see: https://developers.google.com/idx/guides/customize-idx-env | ||
{ pkgs, ... }: { | ||
# Which nixpkgs channel to use. | ||
channel = "stable-23.11"; # or "unstable" | ||
# Use https://search.nixos.org/packages to find packages | ||
packages = [ | ||
pkgs.python311 | ||
pkgs.python311Packages.pip | ||
]; | ||
# Sets environment variables in the workspace | ||
env = { | ||
GOOGLE_API_KEY="TODO"; | ||
}; | ||
idx = { | ||
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" | ||
extensions = [ | ||
"ms-toolsai.jupyter" | ||
"ms-python.python" | ||
"eamodio.gitlens" | ||
]; | ||
workspace = { | ||
# Runs when a workspace is first created with this `dev.nix` file | ||
onCreate = { | ||
create-venv = '' | ||
python -m venv .venv | ||
source .venv/bin/activate | ||
pip install -r requirements.txt | ||
python scripts/api-key.py | ||
''; | ||
# Open editors for the following files by default, if they exist: | ||
default.openFiles = [ "main.ipynb" ]; | ||
}; | ||
# To run something each time the workspace is (re)started, use the `onStart` hook | ||
}; | ||
# Enable previews and customize configuration | ||
previews = {}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"gemini_api": {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "Gemini API Cookbook", | ||
"description": "A collection of guides and examples for the Gemini API", | ||
"categories": ["AI & ML"], | ||
"icon": "https://www.gstatic.com/monospace/231128/logo_gemini_512.png", | ||
"publisher": "Google LLC" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ pkgs, ... }: { | ||
packages = []; | ||
bootstrap = '' | ||
mkdir "$out" | ||
cp -rf ${./.}/* "$out" | ||
mkdir "$out/.idx" | ||
cp -rf ${./.}/.idx "$out" | ||
rm "$out/idx-template.nix" | ||
rm "$out/idx-template.json" | ||
chmod -R u+w "$out" | ||
''; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would there be a way to move those files out of the main folder? Ideally I would prefer to have it as clean as possible and not risk a for a beginning user to run the requirements for nothing. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Dev environment | ||
pip | ||
autopep8 | ||
|
||
# App | ||
google-generativeai # Client library for the Gemini API | ||
Pillow # PIL image-loading library | ||
ipywidgets # Jupyter Widgets |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
|
||
def update_ipynb_files(directory): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you will also need to update all the internal links, otherwise the links in the "what's next" sections of each notebook will open the github instead of the corresponding notebook in IDX, breaking the learning path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe that point will not be a problem as I'm trying to replace all the absolute links by relative ones. |
||
""" | ||
Updates all .ipynb files in the given directory and its subdirectories recursively, | ||
replacing the specified text. | ||
|
||
Args: | ||
directory: The root directory to start the search. | ||
""" | ||
for root, _, files in os.walk(directory): | ||
for filename in files: | ||
if filename.endswith(".ipynb"): | ||
filepath = os.path.join(root, filename) | ||
with open(filepath, 'r') as f: | ||
content = f.read() | ||
|
||
old1_text = "from google.colab import userdata" | ||
old2_text = "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')" | ||
old3_text = r'userdata.get(\"GOOGLE_API_KEY\")' | ||
old4_text = "userdata.get('GOOGLE_API_KEY')" | ||
new1_text = "import os" | ||
new2_text = "GOOGLE_API_KEY=os.environ['GOOGLE_API_KEY']" | ||
new3_text = "os.environ['GOOGLE_API_KEY']" | ||
updated_content = content.replace(old1_text, new1_text) | ||
updated_content = updated_content.replace(old2_text, new2_text) | ||
updated_content = updated_content.replace(old3_text, new3_text) | ||
updated_content = updated_content.replace(old4_text, new3_text) | ||
|
||
with open(filepath, 'w') as f: | ||
f.write(updated_content) | ||
|
||
if __name__ == "__main__": | ||
directory = "." | ||
update_ipynb_files(directory) |
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 guess you want to track how many keys were created through IDX but I would prefer if we do not use different urls for the same website on the same page so I'd use https://aistudio.google.com/app/apikey