AI Teaching Progress
This notebook will document my progress, learning, and problems I ran into while completing my final project for Data Structures 2.
Week 2 (05/22)
During this week, I have started building the project and experimenting with different types of files that I could add this program to. I ran into a few problems when trying to iterate through the _posts directory and adding the ChatGPT materials, because most of the files in the _posts directory were auto-generated .md files that were converted from Jupyter Notebooks for deployment.
for root, dirs, files in os.walk(post_dir):
for file in files:
# For this to work, the auto-generated files have to be in a different folder than the
if file.endswith(".md"):
md_file_path = os.path.join(root, file)
# Step 5: Parse Markdown or Jupyter Notebook content
with open(md_file_path, "r") as f:
content = f.read()
tags_start = content.find("tags:")
tags_end = content.find("\n", tags_start)
tags = content[tags_start + 5:tags_end].strip() if tags_start != -1 else ""
# Step 6: Invoke ChatGPT API
api_output = interact_with_api(tags)
# Step 7: Update Markdown or Jupyter Notebook content
# Modify the content as per your requirements
# For example, append the output as a new section
updated_content = f"{content}\n\n## ChatGPT API Output\n\n{api_output}"
# Step 8: Save modified file
with open(md_file_path, "w") as f:
f.write(updated_content)
def process_notebooks(notebook_dir):
for root, dirs, files in os.walk(notebook_dir):
for file in files:
if file.endswith(".ipynb"):
notebook_path = os.path.join(root, file)
notebook = nbformat.read(notebook_path, as_version=nbformat.NO_CONVERT)
# Step 5: Parse Markdown or Jupyter Notebook content
tags = notebook["metadata"].get("tags", [])
# Step 6: Invoke ChatGPT API
api_output = interact_with_api(tags)
# Step 7: Update Markdown or Jupyter Notebook content
# Modify the notebook as per your requirements
# For example, append the output as a markdown cell at the end
new_cell = nbformat.v4.new_markdown_cell(source=api_output)
notebook["cells"].append(new_cell)
# Step 8: Save modified file
nbformat.write(notebook, notebook_path)