"""simple_sequential_chains_demo.py — each step only needs the previous output
Run with venv active:  python simple_sequential_chains_demo.py
"""
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

load_dotenv()

model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
parser = StrOutputParser()

# Step 1: feature → tag name (outputs a plain string)
pick_prompt = ChatPromptTemplate.from_template(
    "Name one HTML tag used for {feature}. Reply with only the tag name, no brackets."
)
pick_chain = pick_prompt | model | parser

# Step 2: tag name → explanation (only receives step 1's string output)
explain_prompt = ChatPromptTemplate.from_template(
    "What does the HTML <{tag}> tag do? One short sentence."
)

# Simple sequential: step 1 output flows straight into step 2
chain = pick_chain | explain_prompt | model | parser

features = ["links", "images"]

for feature in features:
    explanation = chain.invoke({"feature": feature})
    print(f"Feature: {feature}")
    print(f"Explanation: {explanation}\n")