Skip to content

Commit

Permalink
feat(docbot)📝: Add a new Jupyter notebook for the docbot functionality
Browse files Browse the repository at this point in the history
- Create a new Jupyter notebook to integrate various documentation tools.
- Set up autoreload for dynamic updates during development.
- Implement code cells for handling documentation checks and updates.
  • Loading branch information
ericmjl committed Aug 29, 2024
1 parent bf9f8b6 commit 38e081b
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions scratch_notebooks/docbot.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from llamabot import SimpleBot, StructuredBot\n",
"import frontmatter\n",
"from pyprojroot import here\n",
"from llamabot.cli.docs import UnifiedDiff, MarkdownSourceFile, documentation_information, ood_checker_sysprompt, DocumentationIssues"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Open up the docs/devcontainer.md file and read YAML header\n",
"markdown_source_path = here() / \"docs\" / \"devcontainer.md\"\n",
"\n",
"src_file = MarkdownSourceFile(markdown_source_path)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"doc_checker = StructuredBot(system_prompt=ood_checker_sysprompt(), pydantic_model=DocumentationIssues)\n",
"response = doc_checker(documentation_information(src_file, line_numbers=False, issues={}))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"response"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# For each issue in the response, generate a diff hunk against the text file\n",
"from llamabot.cli.docs import docwriter_sysprompt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"docwriter = SimpleBot(system_prompt=docwriter_sysprompt())\n",
"response = docwriter(documentation_information(src_file, line_numbers=False, issues=response.model_dump()))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import yaml\n",
"\n",
"with open(markdown_source_path, \"w+\") as f:\n",
" f.write(\"---\\n\")\n",
" # Write the intents to docs\n",
" f.write(yaml.dump(src_file.post.metadata))\n",
" f.write(\"---\\n\")\n",
" f.write(response.content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "llamabot",
"language": "python",
"name": "llamabot"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 38e081b

Please sign in to comment.