Course ES
← back to chapter

Draft a README

Paste a one-paragraph description of a project. Get back a README skeleton

Showcase — Draft a README

Paste a one-paragraph description of a project. Get back a README skeleton in Markdown with sections What, Install, Usage, License. One API call, one useful artefact you can drop into a new repo.

Run

bash bootstrap-secrets.sh              # reads ../../../../.env, writes secrets/
docker compose up --build              # default: PROVIDER=openai

Open http://localhost:3000.

To run against Gemini instead:

PROVIDER=gemini docker compose up --build

What's where

  • backend/ai_openai.py — the OpenAI call
  • backend/ai_gemini.py — the Gemini call
  • backend/main.py — identical FastAPI loader
  • frontend/app/page.tsx — textarea + result <pre> for Markdown
  • docker-compose.yml — two services, secrets mounted from ./secrets/

Stop

docker compose down

Run locally

Download the project as a ZIP and run it with Docker. Brings up a FastAPI backend + Next.js frontend on localhost:3000.

Download draft-readme.zip

unzip draft-readme.zip
cd draft-readme
bash bootstrap-secrets.sh   # one-time: pulls API keys into ./secrets
docker compose up --build   # default provider: openai
# or:  PROVIDER=gemini docker compose up --build

Type some input, pick a provider, and run the same code shown in Source against the live API. Sign-in required.


  

The same modules the Run button hits. The whole project (frontend, Dockerfile, compose) is in the ZIP under README.

backend/ai_openai.py

"""Week 1 - Showcase 3 (OpenAI): draft a README skeleton.

Reader pastes a one-paragraph project description; gets back a README in
Markdown with sections What, Install, Usage, License. One API call.
"""
from openai import OpenAI

_client = OpenAI()


def run(description: str) -> str:
    prompt = (
        "Given the project description below, write a concise README in Markdown "
        "with these exact top-level sections (in this order): What, Install, "
        "Usage, License. Use sensible placeholder commands when specifics are "
        "missing. Return only the Markdown body; do not wrap it in fences."
        f"\n\n---\n{description}\n---"
    )
    # Cap the response so the model can't run away on us. 2048 tokens
    # is roughly 6k characters — enough for a tight four-section README.
    response = _client.responses.create(
        model="gpt-5.4-nano", input=prompt, max_output_tokens=2048,
    )
    return response.output_text

backend/ai_gemini.py

"""Week 1 - Showcase 3 (Gemini): draft a README skeleton."""
import os

from google import genai
from google.genai import types

_client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])


def run(description: str) -> str:
    prompt = (
        "Given the project description below, write a concise README in Markdown "
        "with these exact top-level sections (in this order): What, Install, "
        "Usage, License. Use sensible placeholder commands when specifics are "
        "missing. Return only the Markdown body; do not wrap it in fences."
        f"\n\n---\n{description}\n---"
    )
    # Cap the response so the model can't run away on us. 2048 tokens
    # is roughly 6k characters — enough for a tight four-section README.
    response = _client.models.generate_content(
        model="gemini-3.1-flash-lite", contents=prompt,
        config=types.GenerateContentConfig(max_output_tokens=2048),
    )
    return response.text

Project files

  • .gitignore
  • README.md
  • backend/Dockerfile
  • backend/ai_gemini.py
  • backend/ai_openai.py
  • backend/main.py
  • backend/requirements.txt
  • bootstrap-secrets.sh
  • docker-compose.yml
  • frontend/Dockerfile
  • frontend/app/layout.tsx
  • frontend/app/page.tsx
  • frontend/next.config.ts
  • frontend/package.json
  • frontend/tsconfig.json