Your First Chat Model Call
Time to talk to a model for real.
You will pick a model, send it text, and read what comes back.
Pick a model
init_chat_model is the friendly front door.
You give it a model name and a provider. It returns a model object you can call.
You can also build the model class directly. Both give the same object.
invoke: ask once, get one answer
invoke sends your text and waits for the full reply.
The reply is not a plain string. It is an AIMessage.
The words live in .content. Extra details live next to it.
Looking inside the reply
usage_metadata tells you how many tokens you used. That is what you pay for.
Temperature: careful or creative
Temperature 0 gives the same careful answer every time. Good for facts and code.
Temperature 1 gives varied, playful answers. Good for stories and brainstorming.
batch: many questions at once
batch takes a list of prompts and returns a list of answers.
It runs them in parallel, so it is faster than a loop.
The three ways to call a model
invoke(input): one input, one full answer
batch([inputs]): many inputs, many answers, in parallel
stream(input): one input, the answer arrives piece by piece (next lessons)
Every LangChain building block understands these same three calls. Learn them once, use them everywhere.
A tiny helper function
Remember: invoke returns an AIMessage. Use .content to get the words.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.