LangChain : Augmenting Large Language Models Like GPT-3
Dennis Layton
A Senior IT architect, now considered retired. I remain a proponent for AI literacy and the safe and ethical adoption of AI. I write regularly on Linked In and Medium (Dennis Layton).
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.
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.
领英推荐
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.
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.