Introduction to Langchain

 Langchain is a framework for developing AI powered applications using language models . There are many modules available in langchain which helps us to build a AI powered application which can be deployed in production too with less code change.

Image Taken from Link


Langchain offers many modules to build an AI application which helps you to store your own data  vector store by embedding them and query them and pass it to an LLM to generate or answer your query . we will see all the modules one by one .


Some of the modules are 

  1. Model I/O
  2. Retrieval 
  3. Chains
  4. Agents
  5. Memory 
  6. Callbacks

With the help of Langchain framework , we can able to build applications such as 
  • Chatbots
  • Answering question from your own data 
  • Analyzing the data and give insights 
  • many more are there 
<pre><code>
    pip install langchain
</code></pre>

Let's see how to install the package 

It is so easy  to install via python pip package manager and the below command will install all the bare minimum requirements of Langchain 

 pip install langchain

 To install all the modules related to langchain , use the below command

pip install langchain[all]



We will see a simple example to see how to use an openai api to generate a text  , to start using openai api , we need to install the openai package from pypi .To do so 

pip install openai


There are two ways we can utilize the generated api key ,

  • Setting up the API key as an environment variable 
  • Pass API key as a parameter to OPENAI LLM class 
Method -1 

To use openai , we need to an api key you can get it here . after generating the key you have to set it at as environment variable  by 

export OPENAI_API_KEY="your_key"


 Method - 2

    pass the generated key as "openai_api_key" as a named parameter

            from langchain.llms import OpenAI 

Post a Comment

Previous Post Next Post