Building Web Chatbots with LLM: Chapter 19

Weights & Biases · Intermediate ·🧠 Large Language Models ·2y ago

Key Takeaways

Building a web chatbot with LLM using Weights & Biases, Gradio, and Longchain, with a conversational QA chain and Vector store.

Full Transcript

[Music] we should be ready now to build our simple web application which will allow weights andb users to ask questions from our bot let's get started in the config P we Define our configuration including the weights and biases project the job type if you work in a team then we set the team which becomes the weights and bies entity and we also Define where do we pull our Vector store from and where do we pull our prom template from and in this case we are using weight Andis artifacts that we created in the previous video we can also set the model that we want to use uh to run our application we will be also using several functions defined in the chain. pi file specifically we want to load our Vector store and again we will pull the vector store from weight Andes artifacts where we uploaded it after um ingesting documents we also want to load our chain and here specifically we will use the conversational QA chain from longchain uh we will be using the chat open AI model and we can choose between 3.5 turbo and GPT 4 uh in this case we Define in the settings GP uh chat GPT uh which is a 3.5 turbo model and we Define the parameters which again we pull from the config file and then we return this conversational retrieval chain which is a utility defined in L chain and we will pass it on to our application so that uh so that we can respond to user questions by calling this chain and finally we have the get answer function which uses our chain along with the user question to provide back a response so let's go back to our application in this case we are using a simple gradio user interface uh which we will expose as a web application we Define this chat class which will become our interface H that persists our Vector store and our chain in between user calls here we need the configuration and we need the weight run which uh is used to pull our artifacts including the vector store and the chain what we call this uh chat interface uh what happens in the background is in case um the vector store or the chain are not loaded we load them uh we save them in that uh chat object and then we use the get answer function to create a response and append it to the history then we use gradio blocks to Define our user interface specifically we have a text box for the user question we have another text box to specify open AI API key if we want to our if we want to expose it to our users and we don't want to share our open AI API key in this case I have set this as an environment variable so I don't need to provide it but in case you want to expose uh your application on the web and you don't necessarily want to sponsor um the open AI API calls then you can request the users to provide their own key uh we're also storing the state uh we have uh our uh chatbot object and then whenever a user submits a question we call our chat object um along with the default configuration and we pass the question along with a state and receive back the answer that we can uh expose in our user interface so let's run this application now and see how it looks um in our browser again we're using weights and biases to pull our Vector store and our documents and the application is running on the local uh URL so let's uh click this link and we can see our Q&A B uh exposed um via our browser uh we can deploy this uh we can deploy deploy our application for example or on hugging face spaces or on replit there are multiple ways we will not go into the details of deployment in this course but I encourage you to check out the additional links we provide uh below this video to see the different deployment options that you may use let's add try to ask our uh chatbot query just to verify that it's working properly and now we can see the answer uh we can see that to share a report with team members there's a list of steps we can follow including saving the report clicking the share button and so on uh it could be correct but this looks in fact a bit different from what we've seen in the previous um videos when we uh when we explored a similar query and we implemented our retrieval chain and maybe it would be interesting to see what happened behind the scenes and how this uh chain was actually run what was fed uh what was retrieved from our Vector store which documents were fed into the prompt and to do that we can use a weights and biases Tracer so let's take a look there all right so when we go into weights and biases uh remember we set our environment variable L chain W be tracing to true and that means that all of the queries and responses are streamed into weights and bies and we can analyze it there and see what went well or what might have potentially gone wrong in this case we can see the question that we asked in our web interface how do I share a report with my team members and there is also the answer that we also saw in the user interface and we can also see the trace timeline the sequence of um of function calls that uh ultimately resulted in our generation we can see the conversational retrieval chain that we Define in L chain which in turn calls the stuff document chains with a bunch of input documents uh from L chain and then if we go drill down into the llm chain and ultimately the open AI uh we can see uh the prompt here which includes all of the documents that were stuffed into this um into the template and if we scroll through this list of documents we can see um first like the system part of the template uh we uh should be able to see uh different documents which were retrieved from the vector store um and if we scroll through uh through this we can uh hopefully find a document that talks about about collaboration and sharing qu and bies reports and it tells us that once you have saved the report you can select the share button to collaborate draft copy of the report is created when you select the edit button draft reports out to save and we can see like this is actually what influenced um the answer uh of our llm chain so by using weight invis Tracer you can debug you can understand what happened behind the scenes what is the sequence of API calls uh that was done to produce the answer and in this case we found in the prompt the document that was used to generate this output uh this way you can uh do error analysis if some of the responses are potentially flued as unhelpful by your users you can see and drill down what happened maybe uh the correct document was not retrieved for a given query and we need to improve something on the document search and retrieval site maybe the model didn't perform so well and didn't find the right answer within the prompt and maybe we can steer that for example by better prompt engineering or changing to a more powerful model maybe we should switch from GPT 3.5 to GPT 4 or anthropy clo or a coher command model there are many options available and by doing this experimentation we can improve our application and this will be the topic of the next module where we will uh develop a deliberate process of experimenting improving our application and evaluating our results see you then

Original Description

🤖 Explore web chatbots with LLM - Join Darek Kleczek in creating a user-friendly LLM-powered chatbot web application. 🧑🏾‍🎓 Full course with certification and class materials available free at http://wandb.me/building-llm-powered-apps 🏆 Daily swag draw and grand prize Airpods draw from Dec 1 and 31, 2023. Details at http://wandb.me/llm-apps-contest 🗣️ Join the course conversation on our Discord channel at http://wandb.me/course-discord *Episode Description* In this chapter of “Building LLM-Powered Apps”, the free course from Weights & Biases, we step into the world of web application development. Led by Darek Kleczek, Machine Learning Engineer at W&B, this session focuses on creating a simple, user-friendly web application that enables users to interact with an LLM-powered chatbot. 🌟 Chapter Highlights -Creating a User Interface: Learn how to build a simple and intuitive user interface for your LLM-powered chatbot using the Gradio library. -Configuring the Application: Explore the essential components of the configuration file, including project settings and model selection. -Loading Vector Store and Chains: Understand the process of loading vector stores and conversational QA chains from Weights & Biases artifacts into your application. -Implementing Chat Functionality: Dive into the technicalities of -implementing a chat interface that responds to user queries using the LLM. -Interactive Web Application Demo: Follow along as we demonstrate the application's capabilities live in a browser environment. 🎓 Enroll for Free: Join us on this educational journey to master the art of building LLM-powered applications. Enroll at http://wandb.me/building-llm-powered-apps. 👉 Next Chapter Sneak Peek: Stay tuned for our upcoming chapter, where we focus on enhancing and optimizing LLM applications.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Weights & Biases · Weights & Biases · 0 of 60

← Previous Next →
1 0. What is machine learning?
0. What is machine learning?
Weights & Biases
2 1. Build Your First Machine Learning Model
1. Build Your First Machine Learning Model
Weights & Biases
3 Intro to ML: Course Overview
Intro to ML: Course Overview
Weights & Biases
4 2. Multi-Layer Perceptrons
2. Multi-Layer Perceptrons
Weights & Biases
5 3. Convolutional Neural Networks
3. Convolutional Neural Networks
Weights & Biases
6 Weights & Biases at OpenAI
Weights & Biases at OpenAI
Weights & Biases
7 Why Experiment Tracking is Crucial to OpenAI
Why Experiment Tracking is Crucial to OpenAI
Weights & Biases
8 4. Autoencoders
4. Autoencoders
Weights & Biases
9 5. Sentiment Analysis
5. Sentiment Analysis
Weights & Biases
10 6. Recurrent Neural Networks [RNNs]
6. Recurrent Neural Networks [RNNs]
Weights & Biases
11 7. Text Generation using LSTMs and GRUs
7. Text Generation using LSTMs and GRUs
Weights & Biases
12 8. Text Classification Using Convolutional Neural Networks
8. Text Classification Using Convolutional Neural Networks
Weights & Biases
13 9. Hybrid LSTMs [Long Short-Term Memory]
9. Hybrid LSTMs [Long Short-Term Memory]
Weights & Biases
14 Toyota Research Institute on Experiment Tracking with Weights & Biases
Toyota Research Institute on Experiment Tracking with Weights & Biases
Weights & Biases
15 Weights and Biases - Developer Tools for Deep Learning
Weights and Biases - Developer Tools for Deep Learning
Weights & Biases
16 Introducing Weights & Biases
Introducing Weights & Biases
Weights & Biases
17 10. Seq2Seq Models
10. Seq2Seq Models
Weights & Biases
18 11. Transfer Learning for Domain-Specific Image Classification with Small Datasets
11. Transfer Learning for Domain-Specific Image Classification with Small Datasets
Weights & Biases
19 12. One-shot learning for teaching neural networks to classify objects never seen before
12. One-shot learning for teaching neural networks to classify objects never seen before
Weights & Biases
20 13. Speech Recognition with Convolutional Neural Networks in Keras/TensorFlow
13. Speech Recognition with Convolutional Neural Networks in Keras/TensorFlow
Weights & Biases
21 14. Data Augmentation | Keras
14. Data Augmentation | Keras
Weights & Biases
22 15. Batch Size and Learning Rate in CNNs
15. Batch Size and Learning Rate in CNNs
Weights & Biases
23 Applied Deep Learning Fellowship Overview and Project Selection with Josh Tobin (2019)
Applied Deep Learning Fellowship Overview and Project Selection with Josh Tobin (2019)
Weights & Biases
24 Grading Rubric for AI Applications with Sergey Karayev  (2019)
Grading Rubric for AI Applications with Sergey Karayev (2019)
Weights & Biases
25 16. Video Frame Prediction using CNNs and LSTMs (2019)
16. Video Frame Prediction using CNNs and LSTMs (2019)
Weights & Biases
26 Image to LaTeX - Applied Deep Learning Fellowship (2019)
Image to LaTeX - Applied Deep Learning Fellowship (2019)
Weights & Biases
27 17.  Build and Deploy an Emotion Classifier (2019)
17. Build and Deploy an Emotion Classifier (2019)
Weights & Biases
28 Applied Deep Learning - Data Management with Josh Tobin (2019)
Applied Deep Learning - Data Management with Josh Tobin (2019)
Weights & Biases
29 Snorkel: Programming Training Data with Paroma Varma of Stanford University (2019)
Snorkel: Programming Training Data with Paroma Varma of Stanford University (2019)
Weights & Biases
30 Applied Deep Learning - Troubleshooting and Debugging with Josh Tobin (2019)
Applied Deep Learning - Troubleshooting and Debugging with Josh Tobin (2019)
Weights & Biases
31 Troubleshooting and Iterating ML Models with Lee Redden (2019)
Troubleshooting and Iterating ML Models with Lee Redden (2019)
Weights & Biases
32 Designing a Machine Learning Project with Neal Khosla (2019)
Designing a Machine Learning Project with Neal Khosla (2019)
Weights & Biases
33 Lukas Beiwald on ML Tools and Experiment Management (2019)
Lukas Beiwald on ML Tools and Experiment Management (2019)
Weights & Biases
34 Building Machine Learning Teams with Josh Tobin (2019)
Building Machine Learning Teams with Josh Tobin (2019)
Weights & Biases
35 Pieter Abeel on Potential Deep Learning Research Directions  (2019)
Pieter Abeel on Potential Deep Learning Research Directions (2019)
Weights & Biases
36 Testing and Deployment of Deep Learning Models with Josh Tobin (2019)
Testing and Deployment of Deep Learning Models with Josh Tobin (2019)
Weights & Biases
37 Five Lessons for Team-Oriented Research with Peter Welder (2019)
Five Lessons for Team-Oriented Research with Peter Welder (2019)
Weights & Biases
38 Applied Deep Learning - Rosanne Liu on AI Research (2019)
Applied Deep Learning - Rosanne Liu on AI Research (2019)
Weights & Biases
39 Making the Mid-career Leap from Urban Design to Deep Learning/Data Science
Making the Mid-career Leap from Urban Design to Deep Learning/Data Science
Weights & Biases
40 Organizing ML projects — W&B walkthrough (2020)
Organizing ML projects — W&B walkthrough (2020)
Weights & Biases
41 Brandon Rohrer — Machine Learning in Production for Robots
Brandon Rohrer — Machine Learning in Production for Robots
Weights & Biases
42 Nicolas Koumchatzky — Machine Learning in Production for Self-Driving Cars
Nicolas Koumchatzky — Machine Learning in Production for Self-Driving Cars
Weights & Biases
43 My experiments with Reinforcement Learning with Jariullah Safi
My experiments with Reinforcement Learning with Jariullah Safi
Weights & Biases
44 Applications of Machine Learning to COVID-19 Research with Isaac Godfried
Applications of Machine Learning to COVID-19 Research with Isaac Godfried
Weights & Biases
45 Testing Machine Learning Models with Eric Schles
Testing Machine Learning Models with Eric Schles
Weights & Biases
46 How Linear Algebra is not like Algebra with Charles Frye
How Linear Algebra is not like Algebra with Charles Frye
Weights & Biases
47 Predicting Protein Structures using Deep Learning with Jonathan King
Predicting Protein Structures using Deep Learning with Jonathan King
Weights & Biases
48 Rachael Tatman — Conversational AI and Linguistics
Rachael Tatman — Conversational AI and Linguistics
Weights & Biases
49 Reformer by Han Lee
Reformer by Han Lee
Weights & Biases
50 Sequence Models with Pujaa Rajan
Sequence Models with Pujaa Rajan
Weights & Biases
51 GitHub Actions & Machine Learning Workflows with Hamel Husain
GitHub Actions & Machine Learning Workflows with Hamel Husain
Weights & Biases
52 Look Mom, No Indices! Vector Calculus with the Fréchet Derivative by Charles Frye
Look Mom, No Indices! Vector Calculus with the Fréchet Derivative by Charles Frye
Weights & Biases
53 Jack Clark — Building Trustworthy AI Systems
Jack Clark — Building Trustworthy AI Systems
Weights & Biases
54 Surprising Utility of Surprise: Why ML Uses Negative Log Probabilities - Charles Frye
Surprising Utility of Surprise: Why ML Uses Negative Log Probabilities - Charles Frye
Weights & Biases
55 Track your machine learning experiments locally, with W&B Local - Chris Van Pelt
Track your machine learning experiments locally, with W&B Local - Chris Van Pelt
Weights & Biases
56 Antipatterns in open source research code with Jariullah Safi
Antipatterns in open source research code with Jariullah Safi
Weights & Biases
57 Attention for time series forecasting & COVID predictions - Isaac Godfried
Attention for time series forecasting & COVID predictions - Isaac Godfried
Weights & Biases
58 Made with ML - Goku Mohandas
Made with ML - Goku Mohandas
Weights & Biases
59 Angela & Danielle — Designing ML Models for Millions of Consumer Robots
Angela & Danielle — Designing ML Models for Millions of Consumer Robots
Weights & Biases
60 Deep Learning Salon by Weights & Biases
Deep Learning Salon by Weights & Biases
Weights & Biases

This video teaches how to build a web chatbot with LLM using Weights & Biases, Gradio, and Longchain, with a focus on conversational QA and Vector store. The chatbot can be deployed on various platforms and improved through experimentation and evaluation.

Key Takeaways
  1. Define the configuration for the chatbot
  2. Load the Vector store and chain
  3. Create a Gradio user interface
  4. Implement the conversational QA chain
  5. Test and deploy the chatbot
  6. Use Weights & Biases Tracer for debugging and error analysis
💡 Using Weights & Biases Tracer can help debug and improve the chatbot by analyzing the sequence of API calls and identifying potential issues with document retrieval or model performance.

Related Reads

Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →