[Python] what is the difference between llm and llm chain in langchain?

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    this is llm:

    question=st.text_input("your question")
    llm=OpenAI(temperature=0.9)
    if prompt:
    response=llm(prompt)
    st.write(response)


    then if we need to execute a prompt we have to crate llm chain:

    from langchain.prompts import PromptTemplate
    from langchain.chains import LLMChain

    question=st.text_input("your question")
    llm=OpenAI(temperature=0.9)

    template="Write me something about {topic}"
    topic_template=PromptTemplate(input_variables=['topic'],template=template)

    topic_chain=LLMChain(llm=llm,prompt=topic_template)

    if prompt:
    response=topic_chain.run(question)
    st.write(response)


    I am confused because we used llm(prompt) in the first example, but we created LLMChain(llm=llm,prompt=topic_template) in the second example. Could you please explain the difference between these two approaches and when it's appropriate to use one over the other?

    Continue reading...

Compartilhe esta Página