LangChain : Augmenting Large Language Models Like GPT-3
LangChain a solutions framework for LLMs

LangChain : Augmenting Large Language Models Like GPT-3


What if there was a way of integrating what Large Language Models (LLM) like GPT-3 do best with other tools such as search engines, databases, and computational tools. What if this was done as a solutions framework ? You could take the output of one tool and use it as the input to another, either as a utility or under the direction of an agent.

In the near future, there are going to be alternatives to GPT-3 as more LLMs emerge. It would be ideal, then, if the framework abstracted the LLM API (Application Programming Interface), so that one LLM could be interchanged with another.

All of this is what the open-source initiative called LangChain is doing, and more. At the time of writing this article, LangChain has just released at version 0.0.107, so it's early days for this framework.

Scope of LangChain

Some of what LangChain can do is shown by taking a look at it from a top down perspective starting with its modules. Currently, LangChain is comprised of the following modules.

  • Prompts:This includes prompt management, prompt optimization, and prompt serialization.
  • LLMs: This includes a generic interface for all LLMs, and common utilities for working with LLMs.
  • Document Loaders: This includes a standard interface for loading documents, as well as specific integrations to all types of text data sources.
  • Utils: Language models are often more powerful when interacting with other sources of knowledge or computation. This can include Python REPLs (Read-Eval-Print Loop) , embeddings, search engines, and more.
  • Chains: Chains are sequences of calls whether it's to an LLM or a different utility. LangChain provides a standard interface for chains, lots of integrations with other tools, and end-to-end chains for common applications.
  • Indexes: Language models are often more powerful when combined with your own text data - this module covers best practices for doing exactly that.
  • Agents: Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end to end agents.
  • Memory: Memory is the concept of persisting state between calls of a chain/agent. LangChain provides a standard interface for memory, a collection of memory implementations, and examples of chains/agents that use memory.
  • Chat: Chat models are a variation that expose a different LLM API. Rather than working with raw text, they work with messages. LangChain provides a standard interface for working with them and doing all the same things as above.

The diagram below shows the breadth of this framework's capabilities and it's growing rapidly. In fact ,as I am writing this based on version, 0.0.107 there is already a version 0.0.108.


No alt text provided for this image
LangChain At a Glance

A Simple Example

Here is a simple example of what can be done with LangChain. In the program below, you can see a program that uses Google search to get the current population of Canada and provides the answer in French.

What makes this interesting is that LLM's are trained in data that is in the past. This means that GPT-3 for example has no means to provide an answer that states the population of Canada as of 2023, because it was trained on data that was up to 2021 but no later.

No alt text provided for this image


Without going into the detail, let's look at the output shown at the bottom of the screenshot above. First, an Agent created in the program determines that in order to get the answer to the question being asked it needs to do an internet search. In the program we have provided a tool to the Agent to search the internet using SerpAPI.

After performing the search, the Agent confirms that the result returned was the answer it was looking for and the LLM then generates the response in French. In this case we used OpenAI's LLM, GPT-3, but in future we could use any LLM that LangChain supports that is capable of generating the response we needed.

As you can see in the example above, there is support for a template approach to prompts. Both the question being asked; "What is the population of Canada as of 2023" and the language of the response are parameters to the creation of the LLM prompt.

Beyond this, what LangChain does well is to augment the capabilities that a LLM provides with functionality provided through existing APIs. It abstracts the use of an LLM, so that in the future when there are alternatives to GPT-3 as a LLM you can change the program by changing a few parameters.

Finally, Agents can be used or not. In this case a LangChain Agent determines the step by step approach to answering the question.

LangChain is a means to building new kinds of solutions which leverage the non-deterministic capabilities of LLMs with deterministic capabilities of existing tools and it does all this as a solution framework which provides a level of reuse that can't be achieved in any other way today.

要查看或添加评论,请登录

Dennis Layton的更多文章

社区洞察

其他会员也浏览了