Skip to content

Python Track in Details

Module 1: Core Python Fundamentals

Objective: Ensure learners can write clean, basic Python code, focusing on syntax, data types, and control flow—using text-based examples relevant to AI prompting.

Topics

Python Setup & Environment
Installing Python
Using venv and conda for isolated environments
Explore Package installation via pip
Emphasize environment management (will helps later with AI libraries like openai, langchain, etc.)
Basic Syntax & Language Constructs
Variables and data types (int, float, string, boolean)
Code blocks (indentation), expressions, statements
String manipulation, input/output (I/O)
Control Flow
If-else statements, for / while loops
Common patterns (counters, conditional logic)
Data Structures
Lists, dictionaries, sets
Basic operations (append, pop, slicing, iteration)
Functions & Scope
Defining/Calling functions
Return values and parameters
Local vs. global variables

Focused Exercises

Basic Prompt Preprocessing:
Write a Python script that takes user input (a “prompt”), converts it to lowercase, removes punctuation, and prints the cleaned output. This mirrors typical text-cleaning steps before sending a prompt to an LLM.
Simple Text Storage and Lookup:
Create a small dictionary-based lookup system where keys are “commands” (e.g., "greet") and values are short responses. A user enters a command, and the script outputs the mapped response. (Basic concept for building a minimal command-based “agent.”)
Write a script that prompts the user for a short text and stores it in a file—mimicking a “prompt creation” step.
Create a small dictionary-based menu where “A” triggers a mock “summarize” function and “B” triggers a mock “translate” function. This simulates the idea of an “agent” picking a tool based on user input.

Module 2: Intermediate Python & Essential Practices

Objective: Move beyond basics with OOP, modules, error handling, and testing—introducing concepts that can scale into multi-module AI projects.

Topics

Modules & Packages
Organizing/Splitting code into modules (e.g., question_manager.py, answer_generator.py)
Importing from external packages
Importing code within a project structure
Object-Oriented Programming
Classes, objects, methods
Constructors, instance vs. class variables
Simple inheritance examples
Encapsulations
Error Handling & Logging
try / except / finally
Raising custom exceptions
try / except blocks around external API calls
Using Python’s logging module (info vs. warning vs. error) – eg. for debugging or storing conversation logs
Basic Testing
Using unittest or pytest
Writing test cases
Example: test a function that “cleans” user input or checks its length
Type Hints & Code Quality
PEP 484 type hints (e.g., def process_query(query: str) -> str:)
Code linting (flake8, black)
Docstrings (Google/NumPy style)

Sample Exercises

Sample Exercise 1: Prompt Class:
Create a Prompt class with attributes like raw_text, cleaned_text, and a method to perform text cleaning or formatting.
Include a constructor and a method that logs the transformations (using logging).
Sample Exercise 2: Agent Skeleton:
Define a simple Agent class with methods like receive_prompt and produce_response (stub out responses).
Write unit tests to ensure each method behaves as expected.
Sample Exercise 3: Simple Chat Session Class
Create a ChatSession class with methods like:
add_user_query(query: str) -> None
get_all_queries() -> list
Log each time a query is added.
Write a short test (using pytest or unittest) to ensure add_user_query actually stores queries.
Sample Exercise 4: Mock “AI” Function with Error Handling
Create a mock_ai_response function that:
Takes a string input
Returns a fixed response (e.g., “I’m still learning!”)
Raises an exception if the input is empty
Surround the call in try/except to log an error if the input is blank.

Detailed ‘AI’ Focused Practicals

Sample Practical 1: OOP with a “ChatSession” Class

Focus: Understanding classes, objects, methods, and how OOP can structure AI-driven workflows.
Steps
Design a ChatSession Class
Attributes:
session_id (e.g., a UUID or simple integer)
history (list of messages)
Methods:
add_message(user_input: str, response: str) to store user queries and system responses as tuples (user_input, response).
get_history() -> list to return the entire conversation history.
Usage Example
In your main.py (or a test script), instantiate session = ChatSession().
Prompt the user for input, generate a mock response, then call session.add_message(user_input, mock_response).
AI Context
Real systems often keep a conversation history for context in advanced chatbots or agent-based apps.
Right now it’s just storing text; in future AI modules, we might feed these messages to an actual model.

Sample Practical 2: Error Handling & Logging for “AI Calls

Focus: Using try/except blocks, custom exceptions, and Python’s logging module in an AI-flavored scenario.
Steps
Create a Custom Exception
Define class EmptyPromptError(Exception): pass.
Add Error Handling
In your function generate_mock_response(prompt: str), raise EmptyPromptError if the prompt is empty or just whitespace.
Wrap the function call in a try/except block in main.py.
Log an error message if an exception occurs (logger.error("Prompt was empty!")).
Logging Setup
Configure Python logging (e.g., in ai_helper.py):
CopyEdit
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Log when the function is called, and log the generated response at INFO level.
AI Context
Emulate how real AI calls might fail (empty prompts, invalid inputs) and how logs help developers/debuggers see what happened.

Sample Practical 3: Basic Testing With pytest or unittest

Focus: Introducing automated tests to ensure your functions and classes work correctly.
Steps
Test Setup
Install pytest (or use built-in unittest).
Create a folder tests/ with a file like test_ai.py.
Write Tests
Test generate_mock_response:
Ensure it returns the expected string given a sample prompt.
Check that EmptyPromptError is raised when the input is blank.
Test ChatSession:
Create a ChatSession instance, add a message, and verify get_history() returns what’s expected.
Run Tests
pytest tests/ (if using pytest)
Evaluate pass/fail results and fix code if necessary.
AI Context
Testing is critical in AI-driven pipelines, especially for data validation or ensuring the system can handle edge cases (like empty user input).

Sample Practical 4: Final Combined Exercise

You could create a mini-project that ties all these concepts together:
Project Structure
my_ai_app/
__init__.py
ai_helper.py (mock response function + logging)
chat_session.py (the ChatSession class)
exceptions.py (custom exception classes)
main.py (entry point)
tests/ (folder with test files)
What Happens at Runtime?
User runs python main.py.
They enter a prompt.
main.py calls generate_mock_response(prompt) in ai_helper.py. If prompt is empty, EmptyPromptError is raised, and logs an error. Otherwise, it logs a success message.
The response is added to the ChatSession instance’s history.
The conversation is displayed or stored in a text file.
Testing
Make sure everything is tested in tests/test_ai.py with pytest.

Module 3: Data Handling & Manipulation (NumPy & pandas)

Objective: Give learners enough familiarity with data manipulation to handle typical text or structured data used in Gen AI tasks—like retrieving context or prepping embeddings.

Topics

NumPy Basics
Array creation, reshaping arrays (to represent “vectors,” even though we won’t do real embedding yet)
Slicing, indexing, broadcasting
Basic math functions (mean, sum, etc.)
pandas Essentials
Series & DataFrames
Loading data from CSV/JSON (e.g., knowledge base or text corpus)
Data selection (loc, iloc)
Basic cleaning: removing duplicates, handling missing values
Combining/merging datasets
Practical Data Workflow
Simple text preprocessing with pandas (e.g., removing stopwords in a DataFrame column—optional if comfortable with more advanced text processing libraries)
Using NumPy for numerical transformations

Sample Practical

Exercise 1: Storing Text for “RAG-like” Scenarios

Context
Goal: Show learners how to collect and structure text documents so they’re easily retrievable when they eventually learn about LLMs.
No LLM Required: You’ll simulate the idea of a retrieval-augmented pipeline by focusing on how to store the documents and implement simple lookups. Actual queries to an LLM can come later in the main Gen AI training.
Steps
Create or Acquire a Small Document Set
Provide a handful of short text passages (e.g., paragraphs about different animals, short facts, or any relevant domain).
These can be placed in a CSV file, each row containing a “title” and a “content” column.
Load into pandas
Use pandas to read the CSV (e.g., documents.csv).
Clean the data if needed (trim whitespace, remove any null entries).
Store Documents in a Searchable Structure
Option A (DataFrame-based): Keep them in the pandas DataFrame, with each row representing a document.
Option B (Dictionary-based): Convert the DataFrame into a dictionary, keyed by a title or an ID, with the body text as the value.
Implement a Simple Retrieval Method
Let’s say you create a function retrieve_docs(keyword: str) that:
Searches each document’s text for the presence of that keyword (case-insensitive).
Returns a list of documents that contain the keyword.
This is a very naive approach to retrieval but illustrates the concept of “finding relevant documents” to pass on to some future AI step.
Demonstrate Retrieval
Prompt the user (or read from a text file) for a search term.
Call retrieve_docs(search_term) and print out all matching passages.
Show how they might store the results in a separate file or list for hypothetical “further processing” (which, later, would be passing them to an LLM).
(Optional) Add Some Data Wrangling
If you want to highlight more pandas usage, you could do:
Token counting (just count words in each doc).
Basic text cleanup (remove punctuation, lower-case) before storing.
Demonstrate how you could add columns (e.g., “doc_length”) to help with filtering.
What This Accomplishes
Introduces a RAG-like workflow:
Learners grasp that we can store multiple text passages in a data structure for retrieval based on some relevance criteria.
They don’t need to know about embeddings or advanced vector databases yet.
Reinforces Python & pandas:
Reading/writing CSVs.
Cleaning and manipulating text columns.
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.