Thuta Learning
LangChain
IntermediateAIAdvanced

Chains (LLMChain)

LangChainLesson 6

Chains are a core concept in LangChain. They link components (e.g., a prompt template, a model, an output parser) together in sequence. LLMChain is the most basic chain of all.

python
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain

llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
prompt = PromptTemplate.from_template(
    "What is the best name for a company that makes {product}?"
)

# Create an LLMChain
chain = LLMChain(llm=llm, prompt=prompt)

# Run the chain
response = chain.invoke({"product": "colorful socks"})
print(response)
You should see
{'product': 'colorful socks', 'text': 'SoleMates'}

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Chains (LLMChain) | Thuta Learning