This post provides super-easy end-to-end example to build ChatGPT-like web app to provide responses based context your PDF documents.
To load PDF into Azure Cognitive Vector Search you can refer to previous post Langchain + OpenAI + Azure Search (cloudmatter.io)
Complete code for this post is in in GitHub . And walkthrough is provided below.
Chainlit is an open-source Python package that makes it incredibly fast to build Chat GPT like applications with your own business logic and data. Overview - Chainlit
first install chainlit
pip install chainlit
Then create python file and add code below
on_chat_start - Chainlit hook is called when user starts session. We will initialize environment and prepare embedding function (chailnlit kindly loads environment from .env file).
now add code to initialize Azure Search and prompt template
Still within start_chat() function add a chain and store it with user session. (We use LangChain Expression Language (LCEL) | 🦜️🔗 Langchain )
assuming you have placed code in app.py file run below to start chainlit
chainlit run app.py -w
Screenshot below shows the result
User asked question
Step to retrieve related data using Azure Search vector index
Step to finalize response using Azure Open AI ChatGPT model
Response provided to user