"""Original offline teaching example, not the instructor's source code.

Run: python first_chain.py (requires langchain-core==1.5.2).
The fake model returns a preset reply; it does not summarize or call an API.
"""

from langchain_core.language_models.fake_chat_models import FakeListChatModel
from langchain_core.prompts import PromptTemplate
from langsmith import tracing_context

INFORMATION = "Mina teaches Python. She built a robot in 2024."
REPLY = "Mina teaches Python and built a robot in 2024."


def make_chain():
    prompt = PromptTemplate.from_template(
        "Summarize only the supplied information in one sentence.\n"
        "Information: {information}"
    )
    model = FakeListChatModel(responses=[REPLY])
    return prompt, prompt | model


def main():
    prompt, chain = make_chain()
    inputs = {"information": INFORMATION}
    prompt_value = prompt.invoke(inputs)
    print("Prompt type:", type(prompt_value).__name__)
    print("Formatted prompt:", prompt_value.to_string())
    print("Chain type:", type(chain).__name__)
    result = chain.invoke(inputs)
    print("Response type:", type(result).__name__)
    print("Response:", result.content)
    print("This reply was preset; no real model or API was called.")


if __name__ == "__main__":
    with tracing_context(enabled=False):
        main()
