Model CI/CD Course: Webhooks

Weights & Biases · Intermediate ·🛡️ AI Safety & Ethics ·2y ago

Key Takeaways

This video covers the fundamentals of webhooks and how to build one from scratch using tools like FastAPI, GitHub, Zapier, Twilio, Stripe, and Weights & Biases, with a focus on Model CI/CD and ai safety.

Full Transcript

hello in this next section we'll be talking about web hooks but we're going to go over the fundamentals of web Hooks and what they are and build one from scratch to give you intuition about how they work and what they are so web hooks are very fundamental in software engineering they're everywhere if you Google web hook you'll see a lot of different references to web hooks um particularly you'll see web hooks used in many different Dev tools so you'll see things about GitHub integrating web hooks on GitHub zapier twio stripe srid so on and so forth web hooks are very common in a lot of developer tools and in a lot of infrastructure in other words web hooks are really common mechanisms that different infrastructure providers use to communicate with each other and it's like a flexible way for you to um package of communication between one tool like weights and biases and another tool so what is a web hook well if you Google it and try to read about it it can be kind of confusing so for example the Wikipedia page web hooks uh defines web hook as a web development it's a method of web development um basically where you have a web application with custom callbacks if you don't know what a callback is that's fine a callback is just a piece a function or some code that is going to be executed at a later time now even that I think is a little bit more complicated all of this terminology is more complicated than it needs to be for you to understand what a web Hook is and I think the best way to understand what web Hook is is to is to basically build one and we can do that with python and so that's what I'm going to we're going to do right now is let me open some code so we're going to so there's two components to web hook one is a web server that will receive the web hook and then the client that's going to send the web hook and so I have the code in this repo called WB modal web hook and let me go ahead and open uh the the code that I want to go over so the first thing we want to make is the web hook server and we're going to use fast API for this fast API is a very popular python library for creating web servers and basically what this is is um we do the usual fast API things is we set up the the server and this class is actually the data this is a pantic model is basically like a data class if you if you're not familiar with pantic um it's it's it's like a data class that just specifies what kind of inform information the the web server is going to receive from the client so it's going to receive some kind of uh package that has all of these fields an event type an event author an alias artifact version so on and so forth and I made um this particular kind of data for a very specific reason this is actually a mockup of what weights and biases sends to a web server we don't have to get into that now it doesn't really matter what this is to be honest with you this is just the data that this particular web server it expects and it's going to validate that it's in this in this schema this uh underscore this Dunder Str this is just customizing exactly how this information is printed out so if you don't know about Dunder Str Str this is just a special method you can override in Python that lets you control how something is printed out and in this cas we're just printing out all of these different variables in in a in a very particular way finally we have the web server the web server has different endpoints so this is the root endpoint here and this root endpoint is going to get two different is going to get the event which is this kind of this Json that has this schema and then it's going to get a token it's going to uh the token is is going to be pulled from the header and I'll show you that in a moment that's going to just the token is going to it's going to check that the token is the secret random token this is not secure by the way this is just me showing you um a very basic workflow and very basic web hook and then this is just a check to say hey if the token isn't correct just raise an exception and this is just you don't have to you know this is just a a little bit of a verbose exception but just want to set the stage for how you would do it properly and if the token is correct the web server is going to return this message that's all it's going to do and um so what what do we mean by call back so call back is just any function that you would execute um when receiving this event in this case we're just returning this string but you can imagine there could be another function like let's say pull model or something like that and then you would ex you could even you could execute that here that would be an example of a call back where this web server receives some information upon validating the information it decides to execute some code we don't have to get into we don't have to get into that cuz I don't want to confuse you I want to just show you the very basic of a web hook like what does it mean what does it what does it mean and so let's start this web application so I'm going to go ahead and open the terminal and I'm going to zoom in so you can see my screen this is a little bit of a spit split screen so hopefully you can see it let's just zoom in all the way make it really big let's make it really really big here okay let's make this side really really big as well well okay so the first thing we want to do is start that web server so I'm going to type in this command um let me just get back to it oops there you go so uorn is just the thing that runs web server and this is the name of this file is fast API server.py so this is fastapi server.py and then this is this is the app the name of the application is app that's that's why you have uicorn fast API server app and this starts the web server and you can see here on this side this is kind of serving this is the logs of the web server and what we want to do is we want to send a payload to the web server like some kind of request and so this file curl. sh has a minimal request basically what we can do is say uh we have this curl command let me just zoom in a little bit more so this curl command again this is en curl. sh um has the following headers headers has the authorization header you have to make sure that you put this be word in here otherwise it's not going to work um and then you want to have the content type is Json and we're going to send exactly that schema that we saw here in the EV the base model we have the event type the event author the Alias artifact version so on and so forth uh you can see that this is that's exactly the information that we're sending it that's that's what it expects and here is where it's going to check that this token is going to match the secret random token is actually is is going to match that's what it's checking okay and then um you don't have to mine this stuff up here this is just saying uh use Local Host unless I say otherwise and so if we go back here um we can just run that shell script and when I run that shell script you see message the event is processed successfully and you see these logs printed to these logs have been printed and these logs being printed in this way is just the result of this specific uh Dunder Str Str definition because this this this gets printed see where it says print event right here on this side um this print event is actually what's responsible for the event being printed like this and we'll come back to this this is how when we deploy this web server onto a more production grade application you're going to be looking for logs like this and this is actually uh this information is kind of the same things the same type of information that weights and biases will send you it doesn't make sense now like what this information means like what is it event type what's an alias what does that mean that will make sense I just wanted to ground you on like what a web server is and what you should do is like play with this you should say okay let me kind of uh what happens if I mess this up up like what if I take this out and then you know try to send a request like what happens and you get an error see like this unprocessable entity and it says hey you have a field required that you didn't send um something is wrong and we can we can put that back and try again and then you see now the now it's successful and now we have those logs printed again so this is key this is the basic kind of idea of what web hooks are just one application so on this side this is just me using curl sending some data to another application which in this case was this fast API server and what's going on is in production uh what you'll do is instead of using Curl we're going to be you we're going to use weights and biases to send this information to some application that could be GitHub that could be another machine learning uh uh infrastructure application we we're actually going to use something called modal just because modal is very lightweight and is accessible to everybody just to show you how you can wire up weights and biases to modal and kind of understand what is happening but this like a minimal example is really helpful for you to sort of understand what's going to what's happening when I show you web Hooks and weights and biases thank you

Original Description

This is lesson 7 of 22 in the Model CI/CD course, where we cover the fundamentals of webhooks and how to build one from scratch. *Full course with certification* and class materials available free at http://wandb.me/course_emm. *Episode Description* In this chapter of the Model CI/CD course from Weights & Biases, we delve into the basics of webhooks, explaining their significance in software engineering and how they facilitate communication between different tools. By building a webhook from scratch, you will gain a practical understanding of how webhooks work and how to implement them using Python. *Chapter Highlights* - Understanding Webhooks: Learn what webhooks are, their role in software engineering, and why they are widely used in developer tools and infrastructure. - Building a Webhook: Follow a step-by-step guide to create a webhook server using FastAPI and a client to send data to this server. - Webhook Components: Explore the key components of a webhook, including the server, client, and data schema. - Practical Example: See a hands-on example of setting up a webhook server, sending a payload, and handling requests. - Debugging and Testing: Learn how to test and debug your webhook to ensure it functions correctly in a production environment. *Enroll in the full course free:* http://wandb.me/course_emm *Next Chapter:* Hosting a Webhook Server
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 the fundamentals of webhooks and how to build one from scratch using FastAPI and other tools, with a focus on Model CI/CD and ai safety. It covers topics such as web development, callbacks, and infrastructure communication. By the end of this video, viewers will be able to build a web hook server and implement callbacks.

Key Takeaways
  1. Build a web hook server using FastAPI
  2. Create a data class to specify the information the web server will receive from the client
  3. Set up the server and endpoints to receive the web hook and token
  4. Validate the information received from the client
  5. Start the web server with Uvicorn
  6. Send a payload to the web server with a JSON schema
  7. Check the secret random token for authentication
  8. Execute a callback function upon receiving an event
  9. Print logs to the console when an event is processed
💡 Webhooks are a flexible way for different infrastructure providers to communicate with each other, and can be used to package communication between one tool and another.

Related Reads

📰
Nigeria becomes Africa’s highest-ranked country for Responsible AI
Nigeria leads Africa in Responsible AI, learn how governance frameworks impact AI development
TechCabal
📰
Enterprise AI Governance: Building a Framework That Works
Learn to build an effective Enterprise AI Governance framework with six pillars and a maturity model to ensure responsible AI adoption
Medium · AI
📰
Enterprise AI Governance: Building a Framework That Works
Learn to build an effective enterprise AI governance framework using six pillars and a maturity model to ensure responsible AI adoption
Medium · Machine Learning
📰
Your AI Training Data Is Being Poisoned Right Now - Here Is How Crypto Fixes It
Learn how crypto can fix poisoned AI training data and why it matters for secure AI development
Dev.to · noxlie
Up next
Nicky Leijtens - AI Is Not Neutral: The Gender Gap Nobody Talks About
Legal AI Lab
Watch →