In this post, we’ll dive into how to use LangChain to stream real-time responses from ChatGPT.
1. InstallationFirst, install langchain along with its OpenAI extension, langchain-openai.
pip install langchain langchain-openai The versions used in this post are as follows:
$ pip list | grep langchain langchain 0.2.12 langchain-core 0.2.29 langchain-openai 0.1.21 langchain-text-splitters 0.2.2 2. Setting Up Your API KeyNext, create a .openai file in your working directory and store your API key in it.
Continuing from last post, we’ll explore the implementation of ‘Text-to-SQL’, where you can query database information in natural language and get answers, based on LangChain’s Quickstart documentation.
In this post, we’ll look into the operation of an agent created using the create_sql_agent function.
In this article, we’re using LangChain version 0.2.0.
$ pip list|grep langchain langchain 0.2.0 langchain-community 0.2.0 langchain-core 0.2.0 langchain-openai 0.1.7 langchain-text-splitters 0.2.0 SetupPrepare the environment similarly to last post.
In this post, we’ll dive into how to set up Text-to-SQL with LangChain, guided by the Q&A over SQL+CSV Quickstart.
We’ll be using LangChain version 0.2.0.
$ pip list|grep langchain langchain 0.2.0 langchain-community 0.2.0 langchain-core 0.2.0 langchain-openai 0.1.7 langchain-text-splitters 0.2.0 1. Setup 1.1. Install LibrariesFirst, install the necessary libraries.
pip install --upgrade --quiet langchain langchain-community langchain-openai 1.2. Set Environment Variable OPENAI_API_KEYNext, set the environment variable OPENAI_API_KEY. Create a .openai file in your working directory containing your OpenAI API key, and run the following code.
In this series, we explore the mechanism behind the text summarization chain introduced in LangChain’s Summarization documentation.
In this post, we focus on the Refine summarization method (chain_type="refine").
This article uses LangChain version 0.1.17.
$ pip list|grep langchain langchain 0.1.17 langchain-community 0.0.37 langchain-core 0.1.52 langchain-openai 0.1.6 langchain-text-splitters 0.0.1 langchainhub 0.1.15 Option 3: RefineLet’s take a look at the code for the chain_type="refine" scenario. The summarization chain in this case is generated by the following code:
In this series, we’re diving into the mechanics of LangChain’s summarization chains as outlined in the LangChain documentation on Summarization.
This post focuses on the Map Reduce method (chain_type="map-reduce") for summarization.
This article uses LangChain version 0.1.17.
$ pip list|grep langchain langchain 0.1.17 langchain-community 0.0.37 langchain-core 0.1.52 langchain-openai 0.1.6 langchain-text-splitters 0.0.1 langchainhub 0.1.15 4. Option 2: Map-ReduceLet’s take a look at the code for chain_type="map-reduce". For the Map Reduce method, a summarization chain is created using the following code:
In this post, we’ll explore how the summarization chain in LangChain works, as outlined in the LangChain documentation on Summarization.
This article uses LangChain version 0.1.17.
$ pip list|grep langchain langchain 0.1.17 langchain-community 0.0.37 langchain-core 0.1.52 langchain-openai 0.1.6 langchain-text-splitters 0.0.1 langchainhub 0.1.15 1. Try SummarizationFirst, let’s take a look at the summarization code introduced in the Quickstart section of the documentation.
As we did in a series of previous posts, Exploring LangChain’s Quickstart, we’ll save the OpenAI API key in a .