Skip to content

Commit 6cb47ca

Browse files
Merge branch 'main' into patch-1
2 parents bc34d66 + 22a8c6c commit 6cb47ca

17 files changed

+1569
-178
lines changed

.github/scripts/check_notebooks.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import subprocess
2+
import sys
3+
from pathlib import Path
4+
5+
import nbformat
6+
7+
8+
def get_changed_notebooks(base_ref: str = "origin/main") -> list[Path]:
9+
"""
10+
Returns a list of changed notebook paths in the current git branch
11+
compared to the specified base reference.
12+
"""
13+
result = subprocess.run(
14+
["git", "diff", "--name-only", base_ref, "--", "*.ipynb"],
15+
capture_output=True,
16+
text=True,
17+
check=True,
18+
)
19+
return [Path(line.strip()) for line in result.stdout.splitlines() if line.strip()]
20+
21+
22+
def is_valid_notebook(path: Path) -> bool:
23+
"""
24+
Checks if the notebook at the given path is valid by attempting to read it
25+
with nbformat.
26+
"""
27+
try:
28+
with open(path, "r", encoding="utf-8") as f:
29+
nbformat.read(f, as_version=4)
30+
return True
31+
except Exception as e:
32+
print(f"{path}: INVALID - {e}")
33+
return False
34+
35+
36+
def main() -> None:
37+
"""
38+
Main function to validate the format of changed notebooks.
39+
"""
40+
changed_notebooks = get_changed_notebooks()
41+
if not changed_notebooks:
42+
print("No changed .ipynb files to validate.")
43+
sys.exit(0)
44+
45+
print(f"Validating {len(changed_notebooks)} notebook(s)...")
46+
errors = 0
47+
for path in changed_notebooks:
48+
if not path.exists():
49+
continue # skip deleted files
50+
if not is_valid_notebook(path):
51+
errors += 1
52+
53+
if errors:
54+
print(f"{errors} invalid notebook(s) found.")
55+
sys.exit(1)
56+
else:
57+
print("All changed notebooks are valid.")
58+
59+
60+
if __name__ == "__main__":
61+
main()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Validate Changed Notebooks
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
validate-notebooks:
7+
name: Validate Notebooks
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0 # needed for git diff to work
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.12'
20+
21+
- name: Install dependencies
22+
run: pip install nbformat
23+
24+
- name: Validate changed .ipynb files
25+
run: python .github/scripts/check_notebooks.py

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,6 @@ examples/fine-tuned_qa/local_cache/*
140140

141141
# PyCharm files
142142
.idea/
143+
144+
# VS Code files
145+
.vscode/

authors.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,19 @@ nm-openai:
286286
julian-openai:
287287
name: "Julian Lee"
288288
website: "https://x.com/julianl093"
289-
avatar: "https://avatars.githubusercontent.com/u/199828632"
289+
avatar: "https://avatars.githubusercontent.com/u/199828632"
290+
291+
rzhao-openai:
292+
name: "Randy Zhao"
293+
website: "https://www.linkedin.com/in/randy-zhao-27433616b"
294+
avatar: "https://avatars.githubusercontent.com/u/208724779?v=4"
295+
296+
brandonbaker-openai:
297+
name: "Brandon Baker"
298+
website: "https://www.linkedin.com/in/brandonbaker18"
299+
avatar: "https://avatars.githubusercontent.com/u/208719822"
300+
301+
tompakeman-oai:
302+
name: "Tom Pakeman"
303+
website: "https://www.linkedin.com/in/tom-pakeman/"
304+
avatar: "https://avatars.githubusercontent.com/u/204937754"

examples/Embedding_Wikipedia_articles_for_search.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@
571571
"\n",
572572
"Now that we've split our library into shorter self-contained strings, we can compute embeddings for each.\n",
573573
"\n",
574-
"(For large embedding jobs, use a script like [api_request_parallel_processor.py](api_request_parallel_processor.py) to parallelize requests while throttling to stay under rate limits.)"
574+
"(For large embedding jobs, use a script like [api_request_parallel_processor.py](https://github.com/openai/openai-cookbook/blob/main/examples/api_request_parallel_processor.py) to parallelize requests while throttling to stay under rate limits.)"
575575
]
576576
},
577577
{

examples/GPT_with_vision_for_video_understanding.ipynb

Lines changed: 82 additions & 74 deletions
Large diffs are not rendered by default.

examples/Generate_Images_With_GPT_Image.ipynb

Lines changed: 673 additions & 0 deletions
Large diffs are not rendered by default.
17.7 KB
Loading

examples/imgs/cat_with_hat.jpg

17 KB
Loading

examples/imgs/glorptak.jpg

56 KB
Loading

0 commit comments

Comments
 (0)