AIlab 10
AIlab 10
We'll start by
downloading the official Indian Penal Code document, and
then we'll create a chatbot that can interact with it. Users will
be able to ask questions about the Indian Penal Code and
have a conversation with it.
!pip install --upgrade cohere
!pip install pdfplumber cohere faiss-cpu langchain
!pip install -U langchain-community
!pip install -U pdfplumber cohere faiss-cpu langchain langchain-core
langchain-community langchain-text-splitters
from google.colab import drive
drive.mount('/content/drive')
import pdfplumber
import cohere
import faiss
import numpy as np
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import FAISS
from langchain.embeddings.base import Embeddings
# Try a different model that is likely available for your API key
response = co.generate(
model="command-xlarge", # Replace with a model available for
your API key
prompt=docs[0].page_content + "\n\n" + query,
max_tokens=100 # Limit the response length
)
return response.generations[0].text.strip()
if __name__ == "__main__":
main()