Concepts
Chat Model
Wraps any LangChain-compatible chat model. Supports plain string prompts and full message-list conversations (needed for multi-turn tool calling). Optionally accepts tools=[...] to enable tool calling.
Why it exists
Gives every provider (OpenAI, Groq, Gemini, Anthropic) the same invoke()/stream()/ainvoke() interface, so swapping providers never changes the rest of your chain.
from educhain.prompts import PromptTemplate
from educhain.models import ChatModel
from educhain.output_parsers import StringOutputParser
model = ChatModel() # defaults to ChatOpenAI under the hood
prompt = PromptTemplate(
template="Explain {topic} in simple words.",
input_variables=["topic"]
)
parser = StringOutputParser()
chain = prompt | model | parser
response = chain.invoke({"topic": "Artificial Intelligence"})
print(response)Execution Styles
ChatModel supports three ways to run: invoke() for a single synchronous call, stream() for token-by-token output, and ainvoke() for async execution — all implemented directly on ChatModel itself.
educhain.py
# Synchronous
response = model.invoke("Explain AI in simple words.")
# Streaming
for chunk in model.stream("Explain AI in simple words."):
print(chunk, end="")
# Async
response = await model.ainvoke("Explain AI in simple words.")