liveBook · Manning

Chapter 5: Using Blackbox AI to generate base code

What you will learn in chapter 5 of Coding with AI

The chapter introduces AI-assisted application development as a collaboration in which AI speeds up coding while the developer supplies judgment and direction.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces AI-assisted application development as a collaboration in which AI speeds up coding while the developer supplies judgment and direction.

Key terms: scaffolding, boilerplate code, separation of concerns, human judgment

5.1 Application development with generative AI tools

The section frames an experiment in generating most of a beta application's initial code with Blackbox AI while keeping the developer responsible for reviewing it.

Key terms: Blackbox AI, lead programmer, smart assistant, initial code, suggestions, final reviewer, IDE, GitHub Copilot, Tabnine

5.2 Setting up the development environment

The section identifies the author's development setup and explains why readers can follow along on Windows, Linux, or Mac.

Key terms: Visual Studio Code, Python, DB Browser for SQLite, GitHub Copilot Extension, Blackbox.AI Extension, Tabnine Pro Extension, cross-platform, SQLite browser, Windows 11, Linux

5.3 Developing core features

This section introduces the question dataset that will supply the HAM radio practice test app.

Key terms: HAM radio test, technician exam, database of questions

5.3.1 Creating the database

This subsection shows how to create a SQLite questions database from a CSV file and make each question ID a unique primary key.

Key terms: DB Browser for SQLite, CSV, questions, Write changes, ID, PK, U, primary key

5.3.2 Connecting to our database

The section uses Blackbox AI to turn a stubbed database-connection method into a more suitable suggestion by adding context and refining the request in chat.

Key terms: Blackbox, comment, prompt, SQLite, data/questions.db, Blackbox AI chat, SQLAlchemy, sqlite3, Questions class, connect_to_database

5.3.3 Calling our database from the frontend

This section uses Blackbox AI suggestions to display database records on a Flask page, resolves two integration errors, and explains why the database method should later be narrowed to one responsibility.

Key terms: questions, connect_to_database(), Flask, Jinja2, template, Blackbox AI, get_data(), render_template, Jinja, templates

5.3.4 Refactoring our Questions class

The section refactors AI-generated code for an MVP by narrowing the Questions class’s responsibilities and moving reusable SQLite connection handling into a context manager.

Key terms: minimum viable product (MVP), Questions class, fetch_questions(), Blackbox chat, Include Code in Active File, cursor object, separation of concerns, DatabaseConnection, context manager, with statement

5.3.5 Modifying our entry point (App.py)

This section updates the Flask entry point to fetch questions through the refactored database classes and display them at the application’s root page.

Key terms: index(), DatabaseConnection, cursor, Questions class, fetch_data, data, App.py, Flask, @app.route(), root path

5.3.6 Pulling a set of questions

The section uses Blackbox AI to select 35 unique, roughly randomized question IDs, then narrows the database query to return only the IDs the application needs.

Key terms: question_set, set, question ids, get_question_set, IDs, full record, get_all_questions(), get_question_set(), SELECT *, AI-generated SQL

5.3.7 Creating a test session in the database

This section defines the database structure needed to track a practice-test session and shows how to create its new tables in DB Browser for SQLite.

Key terms: test session, state, 35 questions, correct answer, sessions, question_sets, questions, session_id, question_id, main question pool

5.3.8 Creating code for the test session

The section uses Blackbox AI to draft session-creation code, adapt it to the application’s database connection, and call it from APP.py while noting that a session also needs a question set.

Key terms: session_id, questions_correct, questions_incorrect, Session class, DatabaseConnection, session.py, APP.py, question set, session

5.3.9 Generating a question set

The section uses Blackbox AI to generate a session-linked question set, then refactors and checks the generated code.

Key terms: create_session(), create_question_set, get_question_set(), question_sets, session_id, Questions, Session, database pathname, self.cursor, DatabaseConnection

5.3.10 Verifying our test session was created

The section checks database records to confirm that a first test session and its question set were created, while noting that the application is not yet complete.

Key terms: sessions table, question_sets table, session_id, 35 questions

5.3.11 Conclusion

This conclusion recaps the application foundation built with Blackbox AI and explains why human judgment remained essential.

Key terms: Blackbox AI, human judgment, maintainability, separation of concerns, database schema, test sessions, random question sets, test state

5.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 4: Coding the first version of our application Chapter 6: Generating a software backend with Tabnine →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.