avatarLaxfed Paulacy

Summary

LangChain Expression Language (LCEL) is a new syntax for creating complex, composable chains for language model applications, featuring batch, async, and streaming capabilities and seamless integration with LangSmith.

Abstract

LangChain Expression Language (LCEL) is a novel syntax designed to simplify the construction of chains in language model applications, enabling developers to chain multiple calls, construct inputs, and utilize outputs more efficiently. It supports batch, asynchronous, and streaming operations inherently and is intended to improve the development of complex applications. LCEL's integration with LangSmith facilitates customization and promotes the creation of sophisticated, adaptable language processing tools. A "LangChain Teacher" application has been introduced to assist users in learning the basics of the expression language.

Opinions

  • The expression language is seen as beneficial for living under the philosophy of software once you begin using it, as it aligns with Richard Stallman's software world view.
  • The use of LCEL is predicted to shape the future of social media content filtering by enabling the creation of smarter filters, resonating with Alan Kay's quote about inventing the future.
  • The creation of complex chains is simplified with LCEL, making it a significant tool for developers working with language models.
  • The design of LCEL, which emphasizes ease of use and extensive functionality, reflects a commitment to continuous improvement and responsiveness to user feedback.
  • The integration of LCEL with LangSmith suggests a cohesive ecosystem that prioritizes ease of use and customization for end-users.

LANGCHAIN — What Is Langchain Expression Language?

In the software world, the moment you start using someone else’s software, you are living in their world, under their philosophy. — Richard Stallman

LangChain Expression Language (LCEL) is a new syntax that allows the creation of chains with composition. LCEL supports batch, async, and streaming out of the box and is designed to make it easier to construct complex chains. The LCEL syntax is aimed at improving the construction of language model applications by making it easier to perform tasks such as chaining multiple LLM calls, constructing the input to LLMs, and using the output of LLMs.

To illustrate the usage of LangChain Expression Language, let’s take a look at a common way of using it:

from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate

model = ChatOpenAI()
prompt = ChatPromptTemplate.from_template("tell me a joke about {foo}")
chain = prompt | model

chain.invoke({"foo": "bears"})

In this example, a standard ChatOpenAI model and a prompt template are chained together using the | operator, and then invoked with chain.invoke. Additionally, LCEL supports batch, stream, and async operations:

Batch

chain.batch([{"foo": "bears"}, {"foo": "cats"}])

Stream

for s in chain.stream({"foo": "bears"}):
    print(s.content, end="")

Async

await chain.ainvoke({"foo": "bears"})

By using LangChain Expression Language, complex chains can be created that integrate seamlessly with LangSmith. This allows for easier customization of the chain components and makes the prompts more prominent and easily swappable. LangChain has also introduced a “LangChain Teacher” application to help users learn the basics of getting started with LangChain Expression Language.

In conclusion, LangChain Expression Language provides a declarative and composable way to create chains, making it easier to work with language models and create complex, customizable applications. The new syntax supports batch, async, and streaming operations out of the box, and integrates seamlessly with LangSmith.

It’s important to note that LangChain Expression Language is constantly evolving with more examples and functionality, so users are encouraged to provide feedback and suggestions for further improvements.

ChatGPT
Langchain
Expression
Recommended from ReadMedium