Skip to content

Commit d5fe138

Browse files
authored
Merge pull request #3 from mmacy/examples-add
surface Examples section
2 parents 1718fb1 + 4203faa commit d5fe138

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

docs/examples/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Examples
2+
3+
The following examples are taken from the [`examples/`](https://github.com/openai/openai-python/tree/main/examples) directory in the root of the [openai/openai-python](https://github.com/openai/openai-python) repository.
4+
5+
- [assistant.py](./assistant.md)
6+
- [async_demo.py](./async_demo.md)
7+
- [audio.py](./audio.md)
8+
- [azure.py](./azure.md)
9+
- [azure_ad.py](./azure_ad.md)
10+
- [demo.py](./demo.md)
11+
- [module_client.py](./module_client.md)
12+
- [picture.py](./picture.md)
13+
- [streaming.py](./streaming.md)

docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Welcome to Marsh's totally unofficial and totally unsupported documentation for
44

55
<div class="grid cards" markdown>
66
- :material-clock-fast: [Get started with the library](./get_started.md)
7-
- :fontawesome-brands-python: [OpenAI Python library reference](reference/index.md)
7+
- :octicons-file-code-16: [Examples](./examples/index.md)
8+
- :simple-python: [OpenAI Python library reference](reference/index.md)
89
</div>
910

1011
## About these docs

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ nav:
119119
- Welcome:
120120
- index.md
121121
- Get started: get_started.md
122+
- Examples: examples/index.md
122123
- API reference: reference/index.md
123124
- Get started:
124125
- get_started.md
@@ -127,5 +128,5 @@ nav:
127128
- error-handling.md
128129
- debugging.md
129130
- advanced.md
130-
- Examples: examples/
131+
- Examples: examples/
131132
- API reference: reference/

scripts/gen_examples_md.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
import argparse
44
import os
55
import glob
6+
from typing import List
67

78
def main():
89
parser = argparse.ArgumentParser(description="Generate Markdown files for Python scripts.")
9-
parser.add_argument("--dir", "-d", default="./examples", help="Directory to search for Python files.")
10-
parser.add_argument("--out-dir", "-o", default="./docs/examples", help="Directory to output Markdown files.")
10+
parser.add_argument("--dir", "-d", default="examples", help="Directory to search for Python files.")
11+
parser.add_argument("--out-dir", "-o", default="docs/examples", help="Directory to output Markdown files.")
1112
args = parser.parse_args()
1213

1314
# Ensure output directory exists
1415
os.makedirs(args.out_dir, exist_ok=True)
1516

1617
# Get list of *.py files in the specified directory
1718
python_files = glob.glob(os.path.join(args.dir, "*.py"))
19+
py_file_name = ""
20+
md_file_links: List[str] = []
1821

1922
for py_file in python_files:
2023
py_file_name = os.path.basename(py_file)
@@ -26,5 +29,18 @@ def main():
2629
md_file.write(f"# {py_file_name}\n\n")
2730
md_file.write(f"```python\n--8<-- \"./examples/{py_file_name}\"\n```")
2831

32+
md_file_links.append(md_file_name)
33+
34+
# Create index.md file
35+
index_md_path = os.path.join(args.out_dir, "index.md")
36+
with open(index_md_path, 'w') as index_md_file:
37+
index_md_file.write("# Examples\n\n")
38+
index_md_file.write(
39+
"The following examples are taken from the [`examples/`](https://github.com/openai/openai-python/tree/main/examples) "
40+
"directory in the root of the [openai/openai-python](https://github.com/openai/openai-python) repository.\n\n"
41+
)
42+
for md_link in sorted(md_file_links):
43+
index_md_file.write(f"- [{md_link.replace('.md', '.py')}](./{md_link})\n")
44+
2945
if __name__ == "__main__":
3046
main()

0 commit comments

Comments
 (0)