Artificial Intelligence in Plain English

New AI, ML and Data Science articles every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Member-only story

Maximize Your Potential with Langchain: The 3 Tools You Absolutely Need to Know

Lilmod
Artificial Intelligence in Plain English
5 min readJul 30, 2024

--

LLMs have revolutionized the way we interact with natural language processing (NLP) technologies. Thanks to these advances, innovative tools have emerged, facilitating complex tasks and allowing more fluid and intuitive interaction with systems. This article is aimed at Langchain beginners , no knowledge required :)

If you’re interested in practical tips to increase your productivity and your skill in Machine Learning, feel free to subscribe to our LinkedIn page. Every day we share exciting news in the field and every week a new article.

In this article, we will present three use cases that we consider powerful through simplistic examples:

1. Q\A Agent LLM

When dealing with long documents, such as reports or research articles, the task of finding precise information can be long and tedious. What do you think of an LLM that can answer any type of question about a given corpus of text?

Let’s take as an example a letter written by the President of the French Republic Emmanuel Macron addressing his fellow citizens. Suppose you want to search for a specific information in this report, using a Q\A would save a lot of time!

Let’s move on to the implementation on Python: (For the proper functioning of the use case, do not forget to import the necessary libraries and install them if necessary )

You can download the letter :

https://www.elysee.fr/admin/upload/default/0001/03/0090173c1bc9aaa87f21995ae3b88a55f1fda3d0.pdf

Before you start, don’t forget to get your openAI key, available at the following link :

https://openai.com/index/openai-api/

import os
from langchain import OpenAI
from langchain.vectorstores import FAISS
from langchain.chains import RetrievalQA
from langchain.document_loaders import TextLoader
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter

# import your_openai_key
llm = OpenAI(temperature=0, openai_api_key = your_openai_api_key)

file_path = os.path.join(your_parent_directory, 'MacronLetter.txt')

if os.path.exists(file_path):
loader =…

--

--

Published in Artificial Intelligence in Plain English

New AI, ML and Data Science articles every day. Follow to join our 3.5M+ monthly readers.

Written by Lilmod

3 Data Scientist brothers share their daily lives and experiences in the field of Machine Learning and GenAI. Follow their journey ! 🤖

No responses yet