LangChain – LLM Wrapper

What is LLM Wrapper?

The LLM Wrapper is a standardized interface that wraps around different LLM providers (OpenAI, Anthropic, Google, etc.). Instead of writing provider-specific code each time, you use one unified API. This makes switching between models easy.

LLM Wrapper is a layer that connects LangChain to an LLM (e.g., OpenAI API), so you can call the model using a unified interface.

What it does

  • Wraps OpenAI API
  • Standardizes model calling
  • Makes switching models easier

How to use

from langchain_openai import ChatOpenAI

#You are no longer calling OpenAI directly.
llm = ChatOpenAI(
    model="gpt-4o-mini"
)

response = llm.invoke("Explain RAG simply")
print(response.content)

or
llm = ChatOpenAI(
    model="gpt-4o-mini",
    temperature=0
)

Previously, we directly call OpenAI AI (client = OpenAI(api_key=”your_api_key”) ), now we are no longer calling OpenAI directly, instead of

llm = ChatOpenAI(
model=”gpt-4o-mini”
)

for reviewing

Directly call OpenAI AI (OpenAI SDK)LangChain LLM Wrapper
instantiateclient = OpenAI(api_key=”your_api_key”)llm = ChatOpenAI(
model=”gpt-4o-mini”
)
callclient.chat.completions.create(…)llm.invoke(…)