forked from GoogleCloudPlatform/generative-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into inardini--batch-pipeline-rag
- Loading branch information
Showing
97 changed files
with
30,652 additions
and
21,361 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[MESSAGES CONTROL] | ||
disable=E0401 | ||
disable=E0401,C0301 |
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,25 @@ | ||
name: Links | ||
|
||
on: | ||
repository_dispatch: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "00 18 * * *" | ||
|
||
jobs: | ||
linkChecker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Link Checker | ||
id: lychee | ||
uses: lycheeverse/lychee-action@v1 | ||
|
||
- name: Create Issue From File | ||
if: env.lychee_exit_code != 0 | ||
uses: peter-evans/create-issue-from-file@v5 | ||
with: | ||
title: Link Checker Report | ||
content-filepath: ./lychee/out.md | ||
labels: report, automated issue |
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,16 @@ | ||
name: Check Links | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
check-links: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: lycheeverse/lychee-action@v1 | ||
- name: Comment Broken Links | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
path: lychee/out.md |
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,84 @@ | ||
"""Check links in notebooks for accuracy.""" | ||
|
||
import os | ||
import sys | ||
from typing import Tuple | ||
import urllib.parse | ||
|
||
import nbformat | ||
|
||
LINK_PREFIXES = { | ||
"colab_link": "https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/", | ||
"colab_enterprise_link": "https://console.cloud.google.com/vertex-ai/colab/import/", | ||
"github_link": "https://github.com/GoogleCloudPlatform/generative-ai/blob/main/", | ||
"workbench_link": "https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=", | ||
} | ||
|
||
RAW_URL_PREFIX = ( | ||
"https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/" | ||
) | ||
|
||
|
||
def fix_markdown_links( | ||
cell_source: str, relative_notebook_path: str | ||
) -> Tuple[str, bool]: | ||
"""Fixes links in a markdown cell and returns the updated source.""" | ||
new_lines = [] | ||
changes_made = False | ||
|
||
for line in cell_source.splitlines(): | ||
for key, prefix in LINK_PREFIXES.items(): | ||
if prefix not in line: | ||
continue | ||
|
||
start_index = line.find(prefix) + len(prefix) | ||
end_index = line.find(".ipynb", start_index) + len(".ipynb") | ||
correct_link = "" | ||
|
||
if key in {"colab_link", "github_link"}: | ||
correct_link = relative_notebook_path | ||
elif key == "colab_enterprise_link": | ||
correct_link = urllib.parse.quote( | ||
f"{RAW_URL_PREFIX}{relative_notebook_path}", | ||
safe=":", | ||
) | ||
elif key == "workbench_link": | ||
correct_link = f"{RAW_URL_PREFIX}{relative_notebook_path}" | ||
|
||
if correct_link not in line: | ||
print(f"Incorrect link in {relative_notebook_path}: {line}\n") | ||
print(f"Should be: {correct_link}\n") | ||
line = line.replace(line[start_index:end_index], correct_link) | ||
changes_made = True | ||
|
||
new_lines.append(line) | ||
|
||
return "\n".join(new_lines), changes_made | ||
|
||
|
||
def fix_links_in_notebook(notebook_path: str) -> int: | ||
"""Fixes specific types of links in a Jupyter notebook.""" | ||
with open(notebook_path, "r", encoding="utf-8") as f: | ||
notebook = nbformat.read(f, as_version=4) | ||
|
||
relative_notebook_path = os.path.relpath(notebook_path, start=os.getcwd()) | ||
|
||
for cell in notebook.cells: | ||
if cell.cell_type == "markdown" and "<table" in cell.source: | ||
updated_source, changes_made = fix_markdown_links( | ||
cell.source, relative_notebook_path | ||
) | ||
if changes_made: | ||
cell.source = updated_source | ||
with open(notebook_path, "w", encoding="utf-8") as f: | ||
nbformat.write(notebook, f) | ||
return 1 | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 2: | ||
print("Usage: python check_links.py <notebook_path>") | ||
sys.exit(1) | ||
|
||
fix_links_in_notebook(sys.argv[1]) |
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
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
Oops, something went wrong.