Course EN
← back to chapter

Plantilla de prompt

Pega una descripción de cambio cruda y a medio formar. Recibe de vuelta una

Showcase — Plantilla de prompt

Pega una descripción de cambio cruda y a medio formar. Recibe de vuelta una nota de release en las mismas tres secciones cada vez: Summary, Impact, Action. La plantilla está horneada dentro del prompt, así que la estructura es algo con lo que puedes contar en lugar de algo que esperas que el modelo recuerde.

Córrelo

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

Abre http://localhost:3000.

Para correrlo contra Gemini en su lugar:

PROVIDER=gemini docker compose up --build

Qué hay aquí

  • backend/ai_openai.py — el string TEMPLATE (la lección) + la llamada a OpenAI
  • backend/ai_gemini.py — la misma plantilla, llamada a Gemini
  • backend/main.py — loader de FastAPI idéntico; lee PROVIDER y despacha
  • frontend/app/page.tsx — textarea + resultado
  • docker-compose.yml — dos servicios, secrets montados desde ./secrets/

El input es la descripción de cambio cruda, pasada directo como el string único que el contrato def run(input: str) -> str espera.

Detenlo

docker compose down

Ejecútalo en tu máquina

Descarga el proyecto como ZIP y córrelo con Docker. Levanta un backend FastAPI y un frontend Next.js en localhost:3000.

Descargar prompt-template.zip

unzip prompt-template.zip
cd prompt-template
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

Escribe algo, elige un proveedor y ejecuta el mismo código de Código contra la API real. Requiere iniciar sesión.


  

Los mismos módulos que ejecuta el botón Run. El proyecto completo (frontend, Dockerfile, compose) está en el ZIP, pestaña README.

backend/ai_openai.py

"""Week 2 - Showcase 3 (OpenAI): a fixed template pins the output shape.

Drop a raw, messy change description in; get a release note back in the
same three sections every time. The template lives in the prompt, so the
structure is a property of the prompt, not something you hope the model
remembers. Plain def run(input: str) -> str — the input is the raw text.
"""
from openai import OpenAI

_client = OpenAI()

# The template is the lesson. The model fills the slots; it does not get to
# redesign the document. Same input shape in, same three headings out.
TEMPLATE = """\
Rewrite the change description below as a release note. Use exactly this
template, keep the three headings verbatim, and fill each with one line:

Summary: <what changed, in plain language>
Impact: <who is affected and how>
Action: <what the reader should do, or "None" if nothing>

Return only the filled template. Do not add sections or commentary.

Change description:
{text}"""


def run(text: str) -> str:
    prompt = TEMPLATE.format(text=text.strip())
    response = _client.responses.create(
        model="gpt-5.4-nano", input=prompt, max_output_tokens=300,
    )
    return response.output_text

backend/ai_gemini.py

"""Week 2 - Showcase 3 (Gemini): a fixed template pins the output shape."""
import os

from google import genai
from google.genai import types

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

TEMPLATE = """\
Rewrite the change description below as a release note. Use exactly this
template, keep the three headings verbatim, and fill each with one line:

Summary: <what changed, in plain language>
Impact: <who is affected and how>
Action: <what the reader should do, or "None" if nothing>

Return only the filled template. Do not add sections or commentary.

Change description:
{text}"""


def run(text: str) -> str:
    prompt = TEMPLATE.format(text=text.strip())
    response = _client.models.generate_content(
        model="gemini-3.1-flash-lite",
        contents=prompt,
        config=types.GenerateContentConfig(max_output_tokens=300),
    )
    return response.text

Archivos del proyecto

  • .gitignore
  • README.es.md
  • 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