Module 1: Introduction & Setup
Lesson 1: Course overview & learning goals
Welcome to the course
In this course, you’ll build an AI-powered code documentation assistant using Python Flask and DeepSeek. This tool automates the process of generating and improving documentation for Python code, saving developers significant time and effort.
What you’ll build
- A Flask-based web application that integrates with DeepSeek AI.
- A tool that automatically generates and improves docstrings for Python code.
- A chatbot that answers natural language questions about code.
Why it’s valuable
- Automate tedious tasks: Eliminate the need for manually writing and updating documentation.
- Improve code quality: Well-documented code enhances readability, maintainability, and collaboration.
- Leverage AI: Use DeepSeek’s advanced language models to generate accurate and context-aware docstrings.
Learning Goals
By the end of this course, you will:
- Set up a development environment for building AI-powered tools.
- Extract and analyze code from GitHub repositories.
- Use DeepSeek to generate and improve docstrings.
- Build a Flask API for interactive documentation queries.
- Automate documentation updates and deploy your tool.
Lesson 2: Setting up the development environment
Step 1: Clone the Flask starter template
- Open Your Terminal: Launch your terminal or command prompt.
- Clone the repository: Run the following command to clone the Flask starter template:
git clone --branch release/flask-template-stater --single-branch https://github.com/henrymbuguak/ai-doc-assistant.git
Explanation
--branch release/flask-template-stater
→ Clones only the specified branch.--single-branch
→ Prevents downloading other branches, saving space and time.https://github.com/henrymbuguak/ai-doc-assistant.git
→ Repository URL.
- Navigate to the project directory:
cd ai-doc-assistant
Step 2: Explore the folder structure
After cloning the repository, you’ll see the following folder structure:
ai-doc-assistant/ ├── app/ │ ├── __init__.py │ ├── routes.py │ ├── utils/ │ │ ├── github_api.py │ │ ├── code_parser.py │ │ └── docstring_generator.py │ └── templates/ │ └── index.html ├── tests/ │ ├── test_routes.py │ └── test_utils.py ├── requirements.txt ├── config.py ├── .env ├── .gitignore ├── README.md └── run.py
Folder Structure Breakdown
1. app/
- Contains the core Flask application code.
__init__.py
: Initializes the Flask app and registers blueprints.routes.py
: Defines the routes for the API.utils/
: Includes utility functions for interacting with GitHub, parsing code, and generating docstrings.github_api.py
: Handles fetching code from GitHub repositories.code_parser.py
: Parses Python code using AST (Abstract Syntax Tree).docstring_generator.py
: Generates docstrings using DeepSeek LLM.
templates/
: Stores HTML templates for the Flask app.index.html
: A simple homepage for the app.
2. tests/
- Contains unit tests for the application.
test_routes.py
: Tests the Flask API endpoints.test_utils.py
: Tests the utility functions.
3. Root Files
requirements.txt
: Lists all Python dependencies for the project.config.py
: Stores configuration settings for the Flask app..env
: Stores environment variables like API keys..gitignore
: Specifies files and directories to ignore in Git.README.md
: Provides an overview of the project and setup instructions.run.py
: The entry point for running the Flask app.
Step 4: Install dependencies
- Install required libraries:
pip install -r requirements.txt
- Verify Installation: Confirm that Flask, DeepSeek, and other dependencies install correctly.
Step 5: Acquire and configure API keys
1. Acquire a DeepSeek API key
- Visit the DeepSeek API website.
- Sign up for an account if you don’t already have one.
- Navigate to the API Keys section in your account dashboard.
- Generate a new API key and copy it.
2. Acquire a GitHub access token
- Log in to your GitHub account.
- Go to Settings > Developer settings > Personal access tokens.
- Click Generate new token.
- Select the following permissions:
repo
(to access private repositories).read:org
(to read organization details).
- Generate the token and copy it.
3. Store API Keys in the .env
File
- Add the following content to the
.env
file:DEEPSEEK_API_KEY=your_deepseek_api_key GITHUB_ACCESS_TOKEN=your_github_access_token
- Replace
your_deepseek_api_key
andyour_github_access_token
with the keys you copied.
4. Follow security best practices
- Never share your API keys publicly.
- Add
.env
to your.gitignore
file to prevent accidental commits. - Use environment variables to load keys securely in your application.
Step 5: Run the Flask app
- Start the Flask app:
python run.py
- Verify the App is Running: Open a browser and navigate to
http://127.0.0.1:5000/
. You’ll see the message:Welcome to the AI-Powered Documentation Assistant!
Step 6: Explore the template
- Walk through the code:
app/__init__.py
: Initializes the Flask app.app/routes.py
: Defines the routes for the API.app/utils/docstring_generator.py
: Contains the logic for generating docstrings using DeepSeek.
- Test the
/generate-docstring
Endpoint: Usecurl
or Postman to send a sample request:curl -X POST http://127.0.0.1:5000/generate-docstring \ -H "Content-Type: application/json" \ -d '{"code": "def add(a, b): return a + b"}'
Expected Output:
{ "docstring": "Add two numbers.\n\nArgs:\n a (int): The first number.\n b (int): The second number.\n\nReturns:\n int: The sum of the two numbers." }
Step 7: Hands-on activity
- Task 1: Modify the
routes.py
file to add a new endpoint (e.g.,/greet
that returns a personalized greeting). - Task 2: Use the
docstring_generator.py
file to generate docstrings for a few sample functions. - Task 3: Share the results on the community forum or Discord channel for feedback.
Additional resources
Next Steps
- Experiment Further: Modify the template and add new features.
- Join the Community: Share progress, ask questions, and collaborate with other learners.
- Proceed to Module 2: Start extracting code from GitHub repositories in the next module.
Facebook Comments