<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Santhosh Vijayabaskar</title>
    <description>The latest articles on DEV Community by Santhosh Vijayabaskar (@santhoshvijayabaskar).</description>
    <link>https://dev.to/santhoshvijayabaskar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2164609%2Fa10c1563-b355-49b1-9246-fa533982239d.png</url>
      <title>DEV Community: Santhosh Vijayabaskar</title>
      <link>https://dev.to/santhoshvijayabaskar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/santhoshvijayabaskar"/>
    <language>en</language>
    <item>
      <title>🔥 10 AI-driven packages for RPA and Intelligent Automation 🤖 🧠</title>
      <dc:creator>Santhosh Vijayabaskar</dc:creator>
      <pubDate>Wed, 30 Oct 2024 23:00:00 +0000</pubDate>
      <link>https://dev.to/santhoshvijayabaskar/10-ai-driven-packages-for-rpa-and-intelligent-automation-1l14</link>
      <guid>https://dev.to/santhoshvijayabaskar/10-ai-driven-packages-for-rpa-and-intelligent-automation-1l14</guid>
      <description>&lt;p&gt;Robotic Process Automation (RPA) is getting a big boost, thanks to AI 🤖. We’re way past just automating repetitive tasks—now, automation’s smart enough to handle complex stuff, make decisions, and even feel almost human in its interactions.&lt;/p&gt;

&lt;p&gt;In this article, I’m running through 10 AI-driven tools that take RPA up a notch. From NLP to computer vision to machine learning, these tools are all about helping you build systems that aren’t just faster but also way more adaptable. Whether you’re looking to streamline document processing or enable predictive decision-making 📊, these tools have you covered.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. spaCy – Powerful NLP for Automation
&lt;/h3&gt;

&lt;p&gt;spaCy is a natural language processing library designed for speed and efficiency, making it ideal for text-based automation in RPA.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spot Key Details: spaCy makes it easy to pick out important names, places, or other entities in text automatically.&lt;/li&gt;
&lt;li&gt;Fast and Efficient: Great for quickly processing large chunks of text without slowing down.&lt;/li&gt;
&lt;li&gt;Pre-trained Models: Comes ready-to-go with models in multiple languages, so you don’t have to start from scratch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Automating customer support by extracting key data from emails, such as complaint types, locations, or customer names, then categorizing the requests for the right department.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Install spaCy with pip install spacy, and access their documentation for model downloads and tutorials here.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. PaddleOCR – Advanced OCR for Complex Documents
&lt;/h3&gt;

&lt;p&gt;PaddleOCR is a deep-learning-based optical character recognition (OCR) tool that provides high accuracy across languages and complex document structures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multilingual Support: Reads text in many languages, which is super handy for global documents.&lt;/li&gt;
&lt;li&gt;Handles Tables and Forms: Doesn’t just read words; it understands structured layouts like tables and forms.&lt;/li&gt;
&lt;li&gt;Ready to Use: Comes pre-trained, so it’s easy to set up and start automating document-heavy tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Automating invoice processing by extracting line items, amounts, and dates from scanned invoices, feeding the data into financial systems, and reducing manual data entry.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Install PaddleOCR with pip install paddleocr, and follow its GitHub documentation for setup and usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. OpenCV with YOLO – Vision-Based Automation
&lt;/h3&gt;

&lt;p&gt;OpenCV is a computer vision library that, when combined with YOLO (You Only Look Once), enables object detection for interactive automation workflows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-Time Object Detection: Detects and identifies things on the screen or in videos instantly.&lt;/li&gt;
&lt;li&gt;Adaptable for Video and GUI: Great for dynamic interactions, like recognizing buttons or specific items in videos.&lt;/li&gt;
&lt;li&gt;High Accuracy: YOLO’s model training means it’s good at knowing exactly what it’s looking at.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Enabling bots to interact visually with applications, such as locating and clicking buttons in an application or recognizing visual patterns to trigger specific workflows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Install OpenCV with pip install opencv-python and download YOLO models. OpenCV’s documentation is available here, while YOLO resources can be found on the YOLO website.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Hugging Face Transformers – High-Power NLP Models
&lt;/h3&gt;

&lt;p&gt;Hugging Face Transformers is a library of pre-trained NLP models that cover a variety of text-based tasks, from summarization to translation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wide Range of Skills: Models for everything from summarizing content to translating languages and understanding tone.&lt;/li&gt;
&lt;li&gt;Super Adaptable: You can fine-tune these models for your specific needs.&lt;/li&gt;
&lt;li&gt;Community Favorites: Access popular models like GPT-2, BERT, and more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Automating customer interactions by using NLP models to analyze sentiment, categorize inquiries, and generate automated responses in a conversational style.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Install Hugging Face Transformers with pip install transformers, and check their extensive documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Google Cloud Vision – Comprehensive Image Recognition
&lt;/h3&gt;

&lt;p&gt;Google Cloud Vision provides powerful image and document recognition capabilities, integrating seamlessly with RPA workflows for intelligent document handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Smart Image Reading: It doesn’t just see text; it recognizes faces, objects, and more.&lt;/li&gt;
&lt;li&gt;Reads Complex Layouts: Good for reading documents with complicated layouts or multiple sections.&lt;/li&gt;
&lt;li&gt;Supports Many Languages: Ideal if you work with documents in multiple languages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Digitizing and categorizing physical documents, such as scanned forms or IDs, by reading and extracting key information to populate digital records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Sign up for &lt;a href="https://cloud.google.com/" rel="noopener noreferrer"&gt;Google Cloud&lt;/a&gt; and activate the Vision API. Their documentation provides setup details and usage examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. OpenAI API (GPT models) – Generative Text and Decision Support
&lt;/h3&gt;

&lt;p&gt;The OpenAI API provides access to the powerful GPT language models, which can generate human-like text and offer conversational abilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Human-Like Responses: Can chat or write as if a real person is responding.&lt;/li&gt;
&lt;li&gt;Multi-Tasking: Does everything from answering questions to summarizing content and translating.&lt;/li&gt;
&lt;li&gt;Flexible Integration: Easy to plug into your automation setup for all sorts of text-based tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Enabling interactive customer support bots that can provide answers, assist with inquiries, and escalate issues to human agents when needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Access the &lt;a href="https://platform.openai.com/" rel="noopener noreferrer"&gt;OpenAI API&lt;/a&gt; by signing up at OpenAI’s website.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Microsoft Azure Cognitive Services – Versatile AI Models for Automation
&lt;/h3&gt;

&lt;p&gt;Azure Cognitive Services offers a suite of AI tools covering vision, speech, language, and decision-making, helping drive intelligent automation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full Spectrum of Abilities: From translating speech to recognizing text and images, it’s an all-in-one package.&lt;/li&gt;
&lt;li&gt;Ready-Made Models: Pre-trained models make it easy to get started.&lt;/li&gt;
&lt;li&gt;Scalable for Big Projects: Works well for small tasks and massive projects alike.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Automating call center operations by transcribing calls in real-time, analyzing sentiment, and providing actionable insights for agents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Sign up on &lt;a href="https://azure.microsoft.com/en-us/products/ai-services" rel="noopener noreferrer"&gt;Azure Cognitive Services&lt;/a&gt; and start using their pre-trained AI models.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Scikit-Learn – Foundational Machine Learning
&lt;/h3&gt;

&lt;p&gt;Scikit-Learn is a machine learning library that provides algorithms for tasks like classification, regression, and clustering, essential for building predictive RPA workflows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lots of Algorithms: Offers tools for everything from predicting trends to clustering similar items.&lt;/li&gt;
&lt;li&gt;Simple to Learn: Its straightforward syntax makes it accessible for beginners and pros alike.&lt;/li&gt;
&lt;li&gt;Works with Python Libraries: Easily integrates with other Python tools for more powerful workflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Enabling predictive maintenance by analyzing historical data to forecast equipment failures and schedule proactive repairs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Install Scikit-Learn with pip install scikit-learn, and explore their extensive documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Amazon Textract – Intelligent OCR for Document Automation
&lt;/h3&gt;

&lt;p&gt;Amazon Textract is a machine-learning-based OCR that goes beyond simple text extraction by understanding the structure and hierarchy within documents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reads Complex Docs: Extracts data from tables, forms, and even understands multi-page layouts.&lt;/li&gt;
&lt;li&gt;Good with Handwriting: Can read both printed and handwritten text, so it’s versatile.&lt;/li&gt;
&lt;li&gt;AWS-Friendly: Built to work seamlessly with other AWS tools, making scaling easy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Automating loan application processing by extracting and organizing information from scanned documents, reducing the manual effort needed for data entry.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Set up &lt;a href="https://docs.aws.amazon.com/textract/latest/dg/setting-up.html" rel="noopener noreferrer"&gt;Textract via the AWS console&lt;/a&gt;. Detailed documentation is available on AWS Textract.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. DataRobot – AutoML for Predictive Analytics in RPA
&lt;/h3&gt;

&lt;p&gt;DataRobot is an AutoML platform that automates the process of building, training, and deploying machine learning models, ideal for adding predictive capabilities to RPA workflows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automated Model Building: No need to be a data scientist; it helps pick the right model and trains it for you.&lt;/li&gt;
&lt;li&gt;High Accuracy: Helps you find the best model quickly, which means more accurate predictions.&lt;/li&gt;
&lt;li&gt;Real-Time Predictions: Can handle large datasets and make real-time predictions as your data changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; Building predictive models to optimize customer churn management, helping businesses proactively engage customers at risk of leaving.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started:&lt;/strong&gt; Explore &lt;a href="https://www.datarobot.com/platform/" rel="noopener noreferrer"&gt;DataRobot’s platform and resources&lt;/a&gt; to see how AutoML can integrate with RPA.&lt;/p&gt;




&lt;p&gt;So there you have it—10 powerful AI tools that can seriously level up your RPA game. Gone are the days of simple, rule-based automation; now, with these packages, you’re working with systems that can analyze, predict, and make your workflows smarter and way more adaptable.&lt;/p&gt;

&lt;p&gt;Whether you’re knee-deep in automation as a developer, architect, or just someone looking to explore what AI can bring to the table, these tools are worth a try. Start experimenting, have some fun with it, and see how these packages can transform your workflows.&lt;/p&gt;

&lt;p&gt;Happy automating! 🚀&lt;/p&gt;

&lt;p&gt;🌐 You can also learn more about my work and projects at &lt;a href="https://santhoshvijayabaskar.com" rel="noopener noreferrer"&gt;https://santhoshvijayabaskar.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credits: Photo by &lt;a href="https://www.pexels.com/photo/bionic-hand-and-human-hand-finger-pointing-6153354/" rel="noopener noreferrer"&gt;cottonbro studio&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rpa</category>
      <category>ai</category>
      <category>tutorial</category>
      <category>automation</category>
    </item>
    <item>
      <title>🔥 Build Your Own AI-Powered Chrome Extension 🧩</title>
      <dc:creator>Santhosh Vijayabaskar</dc:creator>
      <pubDate>Wed, 30 Oct 2024 03:00:08 +0000</pubDate>
      <link>https://dev.to/santhoshvijayabaskar/build-your-own-ai-powered-chrome-extension-18ii</link>
      <guid>https://dev.to/santhoshvijayabaskar/build-your-own-ai-powered-chrome-extension-18ii</guid>
      <description>&lt;p&gt;Ever find yourself scrolling through endless articles and news pages, just hoping to get the main points and move on? Yeah, me too. It’s exhausting, right? 😩 Well, here’s a little shortcut we’re going to build together! 💪&lt;/p&gt;

&lt;p&gt;We’re going to make a Chrome extension that scrapes content from any webpage 🌐, whips up a quick summary with a bit of AI magic 🪄, and—here’s the fun part—reads it out loud for you 🔊. Super convenient, don’t you think?&lt;/p&gt;

&lt;p&gt;By the end, you’ll have something that not only saves you time ⏱️ but also gives you that little boost of, ‘Hey, I built this!’ 😎&lt;/p&gt;

&lt;p&gt;Here’s what we’re working with:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cheerio&lt;/strong&gt;: Think of Cheerio as the friend that helps us skim through HTML and grab the important stuff. It’ll make sure we’re only pulling what we need from each page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hugging Face Transformers&lt;/strong&gt;: These AI models do the heavy lifting with summarization. We’ll use them to shrink long pages down to the essentials—no unnecessary fluff.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ResponsiveVoice.js:&lt;/strong&gt; This adds the final touch by reading out the summary. It’s surprisingly simple to use, and there are lots of voices and languages to pick from.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By the end, you’ll have built an AI-powered Chrome extension, and along the way, you’ll pick up some solid skills in JavaScript, web scraping, and using AI models. Don’t worry if you’re new to this—I’ll guide you through it, and by the end, you’ll have something genuinely cool and useful to show off. Let’s get started! 🚀&lt;/p&gt;




&lt;h3&gt;
  
  
  🪄 Step 1: Setting Up Your Chrome Extension
&lt;/h3&gt;

&lt;p&gt;First, let’s get the basic Chrome extension structure in place. We’ll create three files for this setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
manifest.json - Configures our Chrome extension.&lt;/li&gt;
&lt;li&gt;
popup.html - The user interface for the extension.&lt;/li&gt;
&lt;li&gt;
popup.js - Contains JavaScript code to interact with the content and run summarization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Create the Project Structure
&lt;/h4&gt;

&lt;p&gt;Set up your project folder with the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;summarize&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tool&lt;/span&gt;
&lt;span class="err"&gt;|&lt;/span&gt;&lt;span class="c1"&gt;-- manifest.json&lt;/span&gt;
&lt;span class="err"&gt;|&lt;/span&gt;&lt;span class="c1"&gt;-- popup.html&lt;/span&gt;
&lt;span class="err"&gt;|&lt;/span&gt;&lt;span class="c1"&gt;-- popup.js&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1.1 manifest.json: The Blueprint of Your Extension&lt;/strong&gt;&lt;br&gt;
The manifest file is what Chrome reads to know how to run and interact with our extension. Here’s what it should look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"manifest_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Summarize Tool"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"A Chrome extension that scrapes and summarizes content from any webpage."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"scripting"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tabs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"activeTab"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"background"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"service_worker"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"background.js"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"default_popup"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"popup.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"default_icon"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"16"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"icons/icon16.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"48"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"icons/icon48.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"128"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"icons/icon128.png"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"host_permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;all_urls&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This setup tells Chrome what the extension does, which files are in use, and what permissions it needs (like accessing the current webpage’s content).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.2 popup.html: Creating the Extension Interface&lt;/strong&gt;&lt;br&gt;
Now let’s add some basic HTML to give users a button to trigger the summarization and text-to-voice features.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Summarize Tool&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Summarize This Page&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"summarize-btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Summarize&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"summary"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"margin-top: 15px; font-size: 14px;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"read-summary"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"margin-top: 15px;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Read Out Loud&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"popup.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This simple layout gives us two buttons: one for summarizing the page and another for reading the summary out loud.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔍 Step 2: Extracting Content with DOMParser
&lt;/h3&gt;

&lt;p&gt;Now that our extension is set up, let’s dive into getting the content we want from any webpage. We’ll use DOMParser to retrieve and parse HTML directly in the Chrome extension environment.&lt;/p&gt;

&lt;p&gt;🤔 Why DOMParser?&lt;br&gt;
DOMParser allows us to extract the main text from a webpage without needing external libraries, making it efficient and compatible with Chrome extensions.&lt;/p&gt;

&lt;p&gt;Here’s what we’ll do:&lt;/p&gt;

&lt;p&gt;When the "Summarize" button is clicked, the DOMParser will grab the main content on the page.&lt;br&gt;
This content will then be passed along to Hugging Face for summarization.&lt;br&gt;
Here’s the code for popup.js to extract the content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;summarize-btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;tab&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;chrome&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tabs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;currentWindow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nx"&gt;chrome&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scripting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;executeScript&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;tabId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;tab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;func&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;getPageContent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;htmlContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nf"&gt;parseAndSummarizeContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;htmlContent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Function to retrieve the page’s HTML content&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getPageContent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;outerHTML&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Function to parse the HTML content and extract the main text&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parseAndSummarizeContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;htmlContent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DOMParser&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parseFromString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;htmlContent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text/html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Extract specific elements or paragraphs&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;paragraphs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;bodyText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;paragraphs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Limit to 500 characters for API to prevent server errors&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;bodyText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bodyText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Send the trimmed text for summarization&lt;/span&gt;
    &lt;span class="nf"&gt;summarizeContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, whenever the button is clicked, this function will grab the main content of the page, trimmed to avoid API overload.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 Step 3: Summarizing Content with Hugging Face Transformers
&lt;/h3&gt;

&lt;p&gt;Next up, let’s condense that content with Hugging Face Transformers!&lt;/p&gt;

&lt;p&gt;🤔 Why Hugging Face?&lt;br&gt;
Hugging Face provides AI models that can do heavy-duty tasks, like turning a long article into a short summary. We’ll use their summarizer model to cut down the text into the key points.&lt;/p&gt;

&lt;p&gt;To do this, you’ll need an API key from Hugging Face. Once you have that, here’s how to set up the API call in popup.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;summarizeContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;retries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;API_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api-inference.huggingface.co/models/sshleifer/distilbart-cnn-12-6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YOUR_HUGGING_FACE_API_KEY&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sending content to summarize:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Log the content being sent&lt;/span&gt;

    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;retries&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;attempt&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_KEY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;summaryData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;summaryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]?.&lt;/span&gt;&lt;span class="nx"&gt;summary_text&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Summary not available.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;summary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Attempt &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: Server unavailable (503). Retrying in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;ms...`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
                &lt;span class="nx"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Exponential backoff&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error in response:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;summary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: Unable to fetch summary.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;summary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: Unable to fetch summary.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;summary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error: Unable to fetch summary after multiple attempts.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code sends the content to Hugging Face, and the response will be a short summary that gets displayed in our popup. Now you’ve got the power of AI summarization with retry logic!&lt;/p&gt;

&lt;h3&gt;
  
  
  🔊 Step 4: Adding Text-to-Voice with Web Speech API
&lt;/h3&gt;

&lt;p&gt;Let’s add the finishing touch by allowing users to hear the summary! The Web Speech API provides a simple way to convert text to speech directly in the browser.&lt;/p&gt;

&lt;p&gt;In popup.js, add the functionality to read out the summary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;read-summary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;summaryText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;summary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;summaryText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;utterance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SpeechSynthesisUtterance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;summaryText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en-US&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Adjust language as needed&lt;/span&gt;
        &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speechSynthesis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No summary available to read.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when you click “Read Out Loud,” the summary will be spoken, giving you a hands-free experience!&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Testing the Extension 🚀
&lt;/h3&gt;

&lt;p&gt;Time to see it in action! &lt;/p&gt;

&lt;p&gt;Head over to &lt;strong&gt;chrome://extensions/&lt;/strong&gt;, enable Developer Mode, and click Load unpacked to load your extension. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpzlm5x86i1vp3cna7i6c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpzlm5x86i1vp3cna7i6c.png" alt="Image description" width="800" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, open a webpage, click the extension icon, and test the summarization and voice features. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vhv7kkm2z0kk11f77lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vhv7kkm2z0kk11f77lg.png" alt="Image description" width="800" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s a good idea to test on different pages to make sure it’s working smoothly.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✨ Step 6: Fine-Tuning and Enhancements
&lt;/h3&gt;

&lt;p&gt;Here are a few ideas to make this extension even better:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Experiment with Summarization Models:&lt;/strong&gt; Hugging Face has different models, so try others to see if one works better for your needs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Add a Language Selector:&lt;/strong&gt; ResponsiveVoice supports multiple languages, so why not add a selector for users who prefer a different language?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Adjust Summary Length:&lt;/strong&gt; Give users the option to choose between short, medium, and long summaries for more customization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that’s it! 🎉 You’ve built a powerful, time-saving Chrome extension that combines scraping, summarizing, and text-to-speech. Not only does it save time, but it’s also a tool you can genuinely use every day. Enjoy showing off your creation!&lt;/p&gt;

&lt;p&gt;P.S.: I ran into a few NPM errors specific to my setup—if you hit any snags, feel free to reach out for help!&lt;/p&gt;

&lt;p&gt;🌐 You can also learn more about my work and projects at &lt;a href="https://santhoshvijayabaskar.com" rel="noopener noreferrer"&gt;https://santhoshvijayabaskar.com&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Credits: &lt;br&gt;
Photo by &lt;a href="https://unsplash.com/@firmbee?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Firmbee.com&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/person-using-black-laptop-computer-eMemmpUojlw?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>extensions</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🤖 AI in DevOps: Tools 🧰 and Trends 🔥 You Need to Know</title>
      <dc:creator>Santhosh Vijayabaskar</dc:creator>
      <pubDate>Sun, 27 Oct 2024 20:42:13 +0000</pubDate>
      <link>https://dev.to/santhoshvijayabaskar/ai-in-devops-tools-and-trends-you-need-to-know-k93</link>
      <guid>https://dev.to/santhoshvijayabaskar/ai-in-devops-tools-and-trends-you-need-to-know-k93</guid>
      <description>&lt;p&gt;Hey Devs! 👋 In the AI Hands-On Series, we’ve been digging into how AI is making a difference across all sorts of tech spaces—from automating routine tasks to making smarter predictions. So far, we’ve looked at ways AI tools help us tackle challenges that were once just part of the grind, giving us back more time to innovate.&lt;/p&gt;

&lt;p&gt;Today, we’re zooming in on DevOps and how AI is reshaping DevOps, adding intelligence to everything from code deployment to monitoring, and making life a whole lot easier for us. &lt;/p&gt;

&lt;p&gt;With AI in the mix, some teams are reporting up to 30% faster release cycles and seeing 40% fewer errors in deployment. 🚀&lt;/p&gt;

&lt;p&gt;Imagine using tools that learn from past data to predict issues before they even happen or automating tedious tasks that are used to slow down releases. Let’s look at the key tools and packages driving these changes and explore how they’re transforming the way we build, deploy, and manage applications!&lt;/p&gt;

&lt;p&gt;Ready? Let’s dive in!&lt;/p&gt;

&lt;h3&gt;
  
  
  What is DevOps?
&lt;/h3&gt;

&lt;p&gt;If you’re new to DevOps, think of it as the ultimate team-up between development and operations, aimed at delivering software faster and smoother. It’s not just about tools or processes—it’s a whole approach that gets Dev and Ops working side-by-side to keep code flowing seamlessly from a developer’s laptop to live production. &lt;/p&gt;

&lt;p&gt;DevOps makes releasing, monitoring, and improving software a continuous, more efficient cycle—so instead of just pushing out updates, you’re building a culture that adapts and scales with the pace of modern development."&lt;/p&gt;

&lt;h3&gt;
  
  
  AI in DevOps
&lt;/h3&gt;

&lt;p&gt;AI in DevOps isn't about replacing DevOps engineers with robots. It's about making the software deployment and monitoring pipelines smarter and more predictive  - so that we can move beyond manual configurations and guesswork and let the tools anticipate, diagnose, and rectify issues with minimal human intervention &lt;/p&gt;

&lt;h3&gt;
  
  
  Key Benefits of AI in DevOps
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Proactive Monitoring&lt;/strong&gt;: AI can identify issues before they cause problems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster Development&lt;/strong&gt;: AI tools like Copilot assist with coding and reviewing, making development smoother.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smarter CI/CD Pipelines&lt;/strong&gt;: Predictive analysis lets teams anticipate deployment success, making releases more stable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  AI Trends in DevOps: What You Need to Know?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. AI-Driven Monitoring: Spotting Issues Before They Happen
&lt;/h3&gt;

&lt;p&gt;One of the most valuable applications of AI in DevOps is in monitoring and alerting. Let’s be honest: manually going through logs or responding to every alert can get overwhelmingly fast. This is where AI steps in to make things easier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
AI-powered monitoring tools learn what “normal” behavior looks like over time and alert you when something’s off. Think of it as having a watchful eye on your system 24/7, catching issues before they impact users. AI helps sift through the noise, focusing on anomalies so you can act before problems escalate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools to Try&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://prometheus.io/" rel="noopener noreferrer"&gt;Prometheus&lt;/a&gt; + &lt;a href="https://grafana.com/" rel="noopener noreferrer"&gt;Grafana&lt;/a&gt; with Machine Learning: Prometheus is widely used for monitoring, and you can extend its capabilities with ML models in Grafana to predict anomalies in metrics.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.elastic.co/kibana" rel="noopener noreferrer"&gt;Elasticsearch and Kibana&lt;/a&gt;: These tools help visualize data from logs, and with some configuration, you can set up basic anomaly detection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to get started:&lt;/strong&gt;&lt;br&gt;
Start by setting up anomaly detection on your logs or metrics and adjusting alerts to focus on priority events. This small step helps you prioritize real issues without drowning in notifications. Even basic anomaly detection can save hours of sifting through logs!&lt;/p&gt;

&lt;h3&gt;
  
  
  2. AI-Assisted Code Completion and Review
&lt;/h3&gt;

&lt;p&gt;Imagine you’re writing code, and an AI tool suggests improvements or even completes certain lines for you. This is a game-changer for both new and seasoned DevOps engineers, as it reduces coding errors, saves time, and keeps quality high.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
These tools use machine learning models trained on tons of code to make suggestions based on context. So, instead of writing everything from scratch, you get smart recommendations that match your coding style and DevOps practices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools to Try&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/features/copilot" rel="noopener noreferrer"&gt;GitHub Copilot&lt;/a&gt;: Integrated into most editors, Copilot provides real-time code suggestions. It’s especially handy for infrastructure as code.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.tabnine.com/" rel="noopener noreferrer"&gt;Tabnine&lt;/a&gt;: Works with various languages and environments, assisting with code suggestions tailored to your context.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to get started:&lt;/strong&gt;&lt;br&gt;
Experiment with AI code assistance for repetitive tasks in your CI/CD scripts or infrastructure code. These tools can highlight best practices and catch mistakes, helping you avoid common pitfalls and reducing the time you spend on code reviews.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. CI/CD Optimization with Predictive Analysis
&lt;/h3&gt;

&lt;p&gt;Continuous integration and deployment (CI/CD) pipelines are the heartbeat of DevOps, but they’re also where things can break down if not managed properly. This is where AI shines by helping to identify patterns in failed builds and flagging code that might need extra testing before deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
AI analyzes historical data from previous builds to identify patterns that predict failures. Based on these patterns, it can make recommendations for your pipeline configurations, or even suggest code areas that may need closer testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools to Try&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://plugins.jenkins.io/machine-learning/" rel="noopener noreferrer"&gt;Jenkins with ML Plugins&lt;/a&gt;: Jenkins supports plugins for ML analysis, which can analyze build data to forecast issues.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://spinnaker.io/docs/guides/user/canary/" rel="noopener noreferrer"&gt;Spinnaker with Canary Analysis&lt;/a&gt;: Spinnaker, a multi-cloud continuous delivery platform, integrates AI for “canary analysis,” where it tests new releases on a small subset of users and rolls back if issues are detected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to get started:&lt;/strong&gt;&lt;br&gt;
Add predictive analysis to your CI/CD pipelines. You can start small by reviewing failure trends or implementing basic canary analysis to test deployments incrementally. This lets you catch issues early and deliver smoother, more reliable deployments.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Smart Incident Management and Response
&lt;/h3&gt;

&lt;p&gt;When issues do arise, AI can also help with incident management by prioritizing alerts based on their urgency and impact. Rather than a flood of alerts hitting the team, AI-powered incident management tools create “incident clusters,” grouping related alerts so you can respond efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
Incident management tools with AI analyze data from logs, metrics, and alerts to prioritize and group issues. They help you address high-impact incidents first, while also managing related events in one place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools to Try&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.moogsoft.com/" rel="noopener noreferrer"&gt;Moogsoft&lt;/a&gt;: Uses AI to cluster alerts and provides a prioritized list of incidents, saving you from alert fatigue.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.pagerduty.com/" rel="noopener noreferrer"&gt;PagerDuty &lt;/a&gt;with Machine Learning: Integrates AI to handle incident response, learning from past incidents to recommend steps in response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to get started:&lt;/strong&gt;&lt;br&gt;
If you’re in a high-alert environment, using AI to manage incident responses can be a big relief. By clustering related alerts and focusing on critical issues first, these tools allow teams to respond faster and reduce burnout.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. AI-Enhanced Testing: Faster and More Reliable
&lt;/h4&gt;

&lt;p&gt;Testing is a huge part of DevOps, and it can be tedious if done manually. AI-driven testing tools help you automate test creation, identify missing tests, and optimize test cases for better coverage and reliability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
AI-enhanced testing tools analyze your codebase and automatically create test cases, often focusing on areas prone to bugs. They can also prioritize tests based on their impact, so you’re always testing what matters most.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools to Try&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.testim.io/" rel="noopener noreferrer"&gt;Testim&lt;/a&gt;: Generates automated test cases based on user flows, helping you catch issues faster.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://applitools.com/" rel="noopener noreferrer"&gt;Applitools&lt;/a&gt;: Uses visual AI to detect visual bugs in web applications, which can be tricky to catch with traditional testing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to get started:&lt;/strong&gt;&lt;br&gt;
Automating parts of your testing process, especially repetitive or high-importance tests, can help you catch issues faster and ensure each release is stable. This is especially useful if your team pushes frequent updates.&lt;/p&gt;




&lt;p&gt;With these tools doing some of the heavy lifting, we’re freeing up more time to focus on the things that really matter.&lt;/p&gt;

&lt;p&gt;If you’re using any other AI tools or have interesting projects that are supercharging your DevOps, drop them in the comments! Let’s keep the conversation going and share tips for building even better pipelines. Thanks for tuning in—here’s to working smarter and building faster!&lt;/p&gt;

&lt;p&gt;PS: Don't forget to check out my other articles on AIHandsOn Series for more interesting projects on AI! 🚀&lt;/p&gt;

&lt;p&gt;🌐 You can also learn more about my work and projects at &lt;a href="https://santhoshvijayabaskar.com" rel="noopener noreferrer"&gt;https://santhoshvijayabaskar.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>ai</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>🤖 Building a Financial AI Chatbot with Rasa: A Hands-On Guide 🌱</title>
      <dc:creator>Santhosh Vijayabaskar</dc:creator>
      <pubDate>Sun, 27 Oct 2024 01:38:36 +0000</pubDate>
      <link>https://dev.to/santhoshvijayabaskar/building-a-financial-ai-chatbot-with-rasa-a-hands-on-guide-57do</link>
      <guid>https://dev.to/santhoshvijayabaskar/building-a-financial-ai-chatbot-with-rasa-a-hands-on-guide-57do</guid>
      <description>&lt;p&gt;The Chatbots and intelligent virtual assistants market is projected to grow at a CAGR of 22% between 2020 and 2025, potentially reaching nearly $14 billion by 2025.📈&lt;/p&gt;

&lt;p&gt;When it comes to the world of chatbots 🤖, not all the bots are the same. Think of the simplest chatbots, those that stick to set scripts and respond to exact phrases—like an FAQ section come to life. These are &lt;strong&gt;rule-based bots&lt;/strong&gt; and can be helpful but often feel a bit, well, robotic.&lt;/p&gt;

&lt;p&gt;Then there are &lt;strong&gt;retrieval-based bots&lt;/strong&gt; that look for the best match from pre-existing responses, leveraging machine learning to be more flexible with language. These are good but still limited, especially if you’re looking for real interaction and multi-turn conversations.&lt;/p&gt;

&lt;p&gt;Finally, we have &lt;strong&gt;conversational AI bots&lt;/strong&gt;—the real stars of the chatbot world 🌟. They go beyond just answering questions; they’re context-aware, meaning they can remember details, adapt based on the conversation, and feel more like a human chat. And this is where Rasa comes in. With Rasa, you can build a bot that’s genuinely smart, customizable, and responsive to individual users.&lt;/p&gt;

&lt;h2&gt;
  
  
  🤖 What is Rasa?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://rasa.community/" rel="noopener noreferrer"&gt;&lt;strong&gt;Rasa&lt;/strong&gt;&lt;/a&gt; is an open-source framework for building chat and voice-based AI assistants. Rasa lets us control every step of the chatbot's workflow. &lt;/p&gt;

&lt;h3&gt;
  
  
  Behind the Scenes: How Rasa’s Conversational AI Works
&lt;/h3&gt;

&lt;p&gt;Here’s a glimpse of what’s happening under the hood with Rasa:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Intent Recognition&lt;/strong&gt;: The bot uses machine learning to identify user intent (e.g., “check balance”) based on trained examples, allowing it to interpret even varied phrasings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Entity Extraction&lt;/strong&gt;: Rasa recognizes specific details, or entities (like “account balance” or “loan eligibility”), from the user’s input to respond accurately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dialogue Management&lt;/strong&gt;: Rasa’s dialogue policies and stories control the conversation flow, remembering previous interactions and guiding the bot to respond contextually.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What You’ll Build in This Tutorial&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll bring these elements together to create a financial AI chatbot capable of assisting with common banking inquiries. By the end, you’ll have the skills to expand this bot further, adapt it to specific use cases, and understand the core of conversational AI.&lt;/p&gt;

&lt;p&gt;✨Let’s get started!🚀&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Set Up Your Project
&lt;/h3&gt;

&lt;p&gt;Let’s start by creating a new Rasa project. Open your terminal and from your project directory, type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rasa init &lt;span class="nt"&gt;--no-prompt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command sets up the files we’ll be working with, like nlu.yml for defining intents and stories.yml for conversation flows.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Defining Intents
&lt;/h3&gt;

&lt;p&gt;Think of an “intent” as what the user wants to do. For example, when someone says “Hey!” they want to greet the bot. Let’s add a few intents to teach Rasa how to recognize them:&lt;/p&gt;

&lt;p&gt;Open data/nlu.yml and add some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;intent&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;greet&lt;/span&gt;
  &lt;span class="na"&gt;examples&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;- hello&lt;/span&gt;
    &lt;span class="s"&gt;- hi there&lt;/span&gt;
    &lt;span class="s"&gt;- hey&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great job! Now, let’s train the model so Rasa can understand these intents. In your terminal, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rasa train
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Creating Conversation Flows
&lt;/h3&gt;

&lt;p&gt;Next, we’ll map out conversation flows. Think of it as scripting a conversation—what should the bot say when someone greets it?&lt;/p&gt;

&lt;p&gt;a. Open data/stories.yml and add this story&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;story&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;greet path&lt;/span&gt;
  &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;intent&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;greet&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;utter_greet&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, the bot will respond with “utter_greet” whenever someone says hello!&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Defining Responses
&lt;/h3&gt;

&lt;p&gt;Let’s make the bot sound friendly! In domain.yml, define what “utter_greet” should say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;responses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;utter_greet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello!&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;How&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;can&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;assist&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;you&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;today?"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Feel free to get creative with responses—this is your chatbot, after all!&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-World Case Study: Finance Chatbot
&lt;/h3&gt;

&lt;p&gt;Let’s take this up a notch. Imagine a bank chatbot that can answer questions about account balances and loan eligibility.&lt;/p&gt;

&lt;p&gt;a. Add a check_balance intent in nlu.yml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;intent&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;check_balance&lt;/span&gt;
  &lt;span class="na"&gt;examples&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;- What is my account balance?&lt;/span&gt;
    &lt;span class="s"&gt;- Show my balance&lt;/span&gt;

&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;intent&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;loan_eligibility&lt;/span&gt;
  &lt;span class="na"&gt;examples&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;- Am I eligible for a loan?&lt;/span&gt;
    &lt;span class="s"&gt;- Can I get a loan?&lt;/span&gt;
    &lt;span class="s"&gt;- What’s my loan eligibility?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In nlu.yml, we’re teaching the bot to recognize user intents: if they ask about balance, it’s check_balance; for loans, it’s loan_eligibility. This setup helps the bot understand and respond accurately&lt;/p&gt;

&lt;p&gt;b. Define a Custom Action in actions/actions.py to handle balance requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rasa_sdk&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Action&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ActionCheckBalance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;action_check_balance&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dispatcher&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tracker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Example logic for retrieving balance
&lt;/span&gt;        &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;$10,000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="n"&gt;dispatcher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utter_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Your balance is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ActionCheckLoanEligibility&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;action_check_loan_eligibility&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dispatcher&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tracker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Placeholder logic for loan eligibility
&lt;/span&gt;        &lt;span class="n"&gt;eligibility_status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;re eligible for a loan up to $50,000!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="n"&gt;dispatcher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utter_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;eligibility_status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we set up a custom action called ActionCheckBalance for the bot. When a user asks about their balance, this action responds with a set balance of "$10,000." Think of it as a placeholder—later, you can link it to actual account data for live results!&lt;/p&gt;

&lt;p&gt;For eligibility status, I have set to respond with "You're eligible for a loan up to $50,000!" as a placeholder. Similar to account balance action, you can also replace it with actual calculations or criteria.&lt;/p&gt;

&lt;p&gt;c. In stories.yml, add this flow for the balance check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;story&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;check balance path&lt;/span&gt;
  &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;intent&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;check_balance&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;action_check_balance&lt;/span&gt;

&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;story&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;check loan eligibility path&lt;/span&gt;
  &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;intent&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;loan_eligibility&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;action_check_loan_eligibility&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above stories.yml, we're mapping user paths: if they ask for a balance, the bot triggers action_check_balance; for loans, it triggers action_check_loan_eligibility. This guides the bot’s responses based on user intent!&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Testing and Fine-Tuning
&lt;/h3&gt;

&lt;p&gt;Time to test it! In your terminal, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rasa interactive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This lets you simulate real conversations and adjust responses on the go.&lt;/p&gt;

&lt;p&gt;🎉 Congratulations! Your chatbot can now handle basic finance queries.&lt;/p&gt;

&lt;p&gt;Remember, the world of conversational AI is constantly evolving, and every tweak you make to your bot brings it closer to a more natural, human-like interaction. So, keep experimenting, stay curious, and don’t be afraid to explore new possibilities with Rasa and conversational AI. Who knows? This might just be the start of your very own AI-driven customer experience journey 🌱.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scaling Up: Going Beyond Basics
&lt;/h3&gt;

&lt;p&gt;For those ready to dive deeper:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Deploy to Multiple Platforms: Consider integrating with Slack/MS Teams or a custom API for a broader reach.&lt;/li&gt;
&lt;li&gt;Advanced Response Customization: Add Rasa custom pipelines or integrate with external databases.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;More Recommended Reading on this topic&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://rasa.com/docs/" rel="noopener noreferrer"&gt;Rasa Documentation&lt;/a&gt; for in-depth guidance.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developers.google.com/assistant/conversation-design/welcome" rel="noopener noreferrer"&gt;Conversational Design Best Practices&lt;/a&gt; for user-centric tips.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy building!🏆 Don't forget to check out my other articles on AIHandsOn Series for more interesting projects on AI! 🚀&lt;/p&gt;

&lt;p&gt;🌐 You can also learn more about my work and projects at &lt;a href="https://santhoshvijayabaskar.com" rel="noopener noreferrer"&gt;https://santhoshvijayabaskar.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>ai</category>
      <category>rasa</category>
      <category>conversationalai</category>
    </item>
    <item>
      <title>Building Your First AI Agent with LangChain and Open APIs</title>
      <dc:creator>Santhosh Vijayabaskar</dc:creator>
      <pubDate>Thu, 24 Oct 2024 12:04:46 +0000</pubDate>
      <link>https://dev.to/santhoshvijayabaskar/building-your-first-ai-agent-with-langchain-and-open-apis-g06</link>
      <guid>https://dev.to/santhoshvijayabaskar/building-your-first-ai-agent-with-langchain-and-open-apis-g06</guid>
      <description>&lt;p&gt;I am sure we all have been hearing about AI agents and are not sure where to begin 🤔; no worries—you're in the right place! In this article, I am going to introduce you to the world of AI Agents and walk you through step-by-step how to build your first AI agent with LangChain. &lt;/p&gt;

&lt;p&gt;LangChain is an incredibly useful tool for connecting AI models to various outbound APIs. In this guided tutorial, we will build our first Agent and connect it to Open API Weather data 🌦️ to make it more interactive and practical. &lt;/p&gt;

&lt;p&gt;By the time we're done, you will have your own AI agent 🤖, which can chat, pull in live data, and do so much more! &lt;/p&gt;




&lt;p&gt;🤖 &lt;strong&gt;What is an AI Agent? Let’s Break it Down&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI Agents are like a supercharged virtual assistant that’s always ready to help. Whether it’s answering your questions, doing small tasks for you, or even making decisions, this AI agent is like having a digital helper at your disposal. It can do everything from fetching data to creating content or even having a conversation with you. Pretty cool, right?😎&lt;/p&gt;

&lt;p&gt;AI agents aren’t just static—they’re smart, dynamic, and capable of working on their own, thanks to the power of large language models (LLMs) like GPT-3 or GPT-4.&lt;/p&gt;

&lt;p&gt;🧩 &lt;strong&gt;What is LangChain? A Developer-Friendly Powerhouse&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.langchain.com/" rel="noopener noreferrer"&gt;LangChain&lt;/a&gt; is a developer-friendly framework that connects AI models (like GPT-3 or GPT-4) with external tools and data. It helps create structured workflows where the AI agent can talk to APIs or databases to fetch information.&lt;/p&gt;

&lt;p&gt;Why LangChain?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Easy to use&lt;/strong&gt;: It simplifies integrating large language models with other tools (Jira, Salesforce, Calendars, Database, etc).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalable&lt;/strong&gt;: You can build anything from a basic chatbot to a complex multi-agent system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community-driven&lt;/strong&gt;: With a large, active community, LangChain provides a wealth of documentation, examples, and support.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;In our case, we’re building a simple agent that can answer questions, and to make things cooler, it’ll retrieve real-time data like weather information. Let's dive in!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Setting Up Your Environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this section, let's set up our development environment. &lt;/p&gt;

&lt;p&gt;1.1 Install Python (if you haven’t already)&lt;/p&gt;

&lt;p&gt;Make sure you have Python installed. You can download it from &lt;a href="https://www.python.org" rel="noopener noreferrer"&gt;python.org&lt;/a&gt;. Once installed, verify it by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1.2 Install LangChain&lt;br&gt;
Now let’s install LangChain via pip. For those who are new to Python, PIP is a package manager for Python packages. Open your terminal and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;langchain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1.3 Install OpenAI&lt;br&gt;
We’ll also be using the OpenAI API to interact with GPT-3, so you’ll need to install the OpenAI Python client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;openai
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1.4 Set Up a Virtual Environment (Optional)&lt;br&gt;
It’s a good practice to work in a virtual environment to keep your project dependencies separate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv langchain-env
&lt;span class="nb"&gt;source &lt;/span&gt;langchain-env/bin/activate   &lt;span class="c"&gt;# For Mac/Linux&lt;/span&gt;

&lt;span class="c"&gt;# or for Windows&lt;/span&gt;
langchain-env&lt;span class="se"&gt;\S&lt;/span&gt;cripts&lt;span class="se"&gt;\a&lt;/span&gt;ctivate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Building Your First AI Agent&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now comes the fun part—let’s build our first AI agent! In this step, we’ll create an agent that can have a simple conversation using OpenAI’s language model. For this, you’ll need an API key from OpenAI, which you can get by signing up at &lt;a href="https://platform.openai.com/docs/quickstart" rel="noopener noreferrer"&gt;OpenAI&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a small snippet to create your first agent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.llms&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the model
&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your-openai-api-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Define a prompt for the agent
&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is the weather like in New York today?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;# Get the response from the AI agent
&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we’re setting up a very basic agent that takes a prompt (a question about the weather) and returns a response from GPT-3. At this point, the agent doesn’t actually retrieve live weather data—it’s just generating a response based on the language model’s knowledge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Connecting to an Open API (Weather API)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let’s step things up by integrating real-time data into our agent. We’re going to connect it to a weather API, which will allow the agent to retrieve live weather information 🌦️.&lt;/p&gt;

&lt;p&gt;Here’s how you do it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Get an API Key from OpenWeather&lt;br&gt;
Head over to &lt;a href="https://openweathermap.org/api" rel="noopener noreferrer"&gt;OpenWeather&lt;/a&gt; and sign up for a free API key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make the API Request&lt;br&gt;
In this next part, we’ll modify our agent so that it fetches live weather data from OpenWeather’s API, and then outputs it as part of the conversation.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.llms&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_weather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your-openweather-api-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://api.openweathermap.org/data/2.5/weather?q=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;&amp;amp;appid=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;&amp;amp;units=metric&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Extract relevant data
&lt;/span&gt;    &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;main&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;temp&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;weather&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;description&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The current temperature in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;°C with &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;# Now use the LangChain LLM model to integrate this data
&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your-openai-api-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;New York&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;weather_info&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_weather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Tell me about the weather in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;weather_info&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, the get_weather function makes a request to the OpenWeather API and extracts data like temperature and weather description.&lt;/p&gt;

&lt;p&gt;The response is then integrated into the AI agent’s output, making it look like the agent is providing up-to-date weather information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Deploying Your AI Agent as an API&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that our agent can chat and retrieve live data, let’s make it accessible to others by turning it into an API. This way, anyone can interact with the agent through HTTP requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using FastAPI for Deployment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fastapi.tiangolo.com/" rel="noopener noreferrer"&gt;FastAPI&lt;/a&gt; is a powerful web framework that makes it easy to create APIs in Python. Here’s how we can deploy our agent using FastAPI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;fastapi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.llms&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_weather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your-openweather-api-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://api.openweathermap.org/data/2.5/weather?q=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;&amp;amp;appid=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;&amp;amp;units=metric&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;main&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;temp&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;weather&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;description&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The weather in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;°C with &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your-openai-api-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/ask&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;ask_question&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;weather&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_weather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Tell me about the weather in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;weather&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;response&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;Now&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;API&lt;/span&gt; &lt;span class="n"&gt;locally&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;access&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;sending&lt;/span&gt; &lt;span class="n"&gt;HTTP&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;localhost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ask&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;&lt;span class="n"&gt;city&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;New&lt;/span&gt; &lt;span class="n"&gt;York&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion: What’s Next?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Congratulations!🎉 You’ve just built your first AI agent from scratch and connected it to an open API to fetch real-time data. You’ve also deployed your agent as an API that others can interact with. From here, the possibilities are endless—you can integrate more APIs, build multi-agent systems, or deploy it on cloud platforms for broader use.🚀&lt;/p&gt;

&lt;p&gt;If you’re ready for more 🔥, and want to explore advanced features of LangChain, like memory management for long conversations, or dive into multi-agent systems to handle more complex tasks, do let me know in the comments below. &lt;/p&gt;

&lt;p&gt;Have fun experimenting, and feel free to drop your thoughts in the comments below!💬&lt;/p&gt;

&lt;p&gt;🌐 You can also learn more about my work and projects at &lt;a href="https://santhoshvijayabaskar.com" rel="noopener noreferrer"&gt;https://santhoshvijayabaskar.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>agentai</category>
      <category>tutorial</category>
      <category>automation</category>
      <category>ai</category>
    </item>
    <item>
      <title>Build Your Own AI Language Model with Python and NumPy</title>
      <dc:creator>Santhosh Vijayabaskar</dc:creator>
      <pubDate>Fri, 18 Oct 2024 23:35:15 +0000</pubDate>
      <link>https://dev.to/santhoshvijayabaskar/build-your-own-language-model-a-simple-guide-with-python-and-numpy-1k3l</link>
      <guid>https://dev.to/santhoshvijayabaskar/build-your-own-language-model-a-simple-guide-with-python-and-numpy-1k3l</guid>
      <description>&lt;p&gt;Artificial Intelligence is everywhere these days, and language models are a big part of that. We all have always wondered how AI can predict the next word in a sentence or even write entire paragraphs. In this tutorial, we’ll build a super simple language model without relying on fancy frameworks like TensorFlow or PyTorch—just plain Python and NumPy. &lt;/p&gt;

&lt;p&gt; &lt;br&gt;
Sounds cool? Let’s get started!🚀&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  What We’re Building:
&lt;/h3&gt;

&lt;p&gt;We'll be creating a &lt;strong&gt;bigram model&lt;/strong&gt;. It predicts the next word in a sentence based on the current word. We’ll keep it straightforward and easy to follow so you’ll learn how things work without getting buried in too much detail.🧠💡&lt;/p&gt;


&lt;h2&gt;
  
  
  Step 1: Set Up
&lt;/h2&gt;

&lt;p&gt;Before we begin, let's make sure you’ve got Python and NumPy ready to go. If you don’t have NumPy installed, quickly install it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Understanding the Basics
&lt;/h2&gt;

&lt;p&gt;A language model predicts the next word in a sentence. We’ll keep things simple and build a bigram model. This just means that our model will predict the next word using only the current word.&lt;/p&gt;

&lt;p&gt;We’ll start with a short text to train the model. Here’s a small sample we’ll use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;

&lt;span class="c1"&gt;# Sample dataset: A small text corpus
&lt;/span&gt;&lt;span class="n"&gt;corpus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Artificial Intelligence is the new electricity.
Machine learning is the future of AI.
AI is transforming industries and shaping the future.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Preparing the Text
&lt;/h2&gt;

&lt;p&gt;First things first, we need to break this text into individual words and create a vocabulary (basically a list of all unique words). This gives us something to work with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Tokenize the corpus into words
&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;corpus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Create a vocabulary of unique words
&lt;/span&gt;&lt;span class="n"&gt;vocab&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;vocab_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vocab&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Vocabulary: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;vocab&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Vocabulary size: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;vocab_size&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we’re converting the text to lowercase and splitting it into words. After that, we create a list of unique words to serve as our vocabulary.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Map Words to Numbers
&lt;/h2&gt;

&lt;p&gt;Computers work with numbers, not words. So, we’ll map each word to an index and create a reverse mapping too (this will help when we convert them back to words later).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;word_to_idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vocab&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
&lt;span class="n"&gt;idx_to_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;word_to_idx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;

&lt;span class="c1"&gt;# Convert the words in the corpus to indices
&lt;/span&gt;&lt;span class="n"&gt;corpus_indices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;word_to_idx&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically, we’re just turning words into numbers that our model can understand. Each word gets its own number, like “AI” might become 0, and “learning” might become 1, depending on the order.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Building the Model
&lt;/h2&gt;

&lt;p&gt;Now, let’s get to the heart of it: building the bigram model. We want to figure out the probability of one word following another. To do that, we’ll count how often each word pair (bigram) shows up in our dataset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Initialize bigram counts matrix
&lt;/span&gt;&lt;span class="n"&gt;bigram_counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;zeros&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;vocab_size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vocab_size&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# Count occurrences of each bigram in the corpus
&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;corpus_indices&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;current_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;corpus_indices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;next_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;corpus_indices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;bigram_counts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;current_word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next_word&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# Apply Laplace smoothing by adding 1 to all bigram counts
&lt;/span&gt;&lt;span class="n"&gt;bigram_counts&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mf"&gt;0.01&lt;/span&gt;

&lt;span class="c1"&gt;# Normalize the counts to get probabilities
&lt;/span&gt;&lt;span class="n"&gt;bigram_probabilities&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bigram_counts&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;bigram_counts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keepdims&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bigram probabilities matrix: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bigram_probabilities&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what’s happening:&lt;/p&gt;

&lt;p&gt;We’re counting how often each word follows another (that's the bigram).&lt;br&gt;
Then, we turn those counts into probabilities by normalizing them.&lt;br&gt;
In simple terms, this means that if "AI" is often followed by "is," the probability for that pair will be higher.&lt;/p&gt;

&lt;p&gt;Note: When we use bigram_count += 0.01, we're applying Laplace smoothing with a small adjustment to avoid zero probabilities when certain word pairs don't appear in the corpus. This ensures that every word pair has a slightly positive probability, even if it’s rare, and helps prevent issues like division errors during the normalization process. By using a smaller value like 0.01, we strike a balance between avoiding zeros and not overly inflating probabilities for unseen word pairs.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;h2&gt;
  
  
  Step 6: Predicting the Next Word
&lt;/h2&gt;

&lt;p&gt;Let’s now test our model by making it predict the next word based on any given word. We do this by sampling from the probability distribution of the next word.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;predict_next_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bigram_probabilities&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;word_idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;word_to_idx&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;current_word&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;next_word_probs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bigram_probabilities&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;word_idx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;next_word_idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vocab_size&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;next_word_probs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;idx_to_word&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;next_word_idx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# Test the model with a word
&lt;/span&gt;&lt;span class="n"&gt;current_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ai&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;next_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;predict_next_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bigram_probabilities&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Given &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;current_word&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, the model predicts &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;next_word&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function takes a word, looks up its probabilities, and randomly selects the next word based on those probabilities. If you pass in "AI," the model might predict something like "is" as the next word.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Generate a Sentence
&lt;/h2&gt;

&lt;p&gt;Finally, let's generate a whole sentence! We’ll start with a word and keep predicting the next word a few times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_sentence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start_word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bigram_probabilities&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;sentence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;start_word&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;current_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;start_word&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;next_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;predict_next_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bigram_probabilities&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;sentence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;next_word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;current_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;next_word&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sentence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Generate a sentence starting with "artificial"
&lt;/span&gt;&lt;span class="n"&gt;generated_sentence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generate_sentence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;artificial&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bigram_probabilities&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Generated sentence: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;generated_sentence&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function takes an initial word and predicts the next one, then uses that word to predict the following one, and so on. Before you know it, you’ve got a full sentence!&lt;/p&gt;

&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;santhoshs-mbp:bigram-language-model santhosh1&lt;span class="nv"&gt;$ &lt;/span&gt;python3 main.py
Vocabulary: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'electricity.'&lt;/span&gt;, &lt;span class="s1"&gt;'artificial'&lt;/span&gt;, &lt;span class="s1"&gt;'future'&lt;/span&gt;, &lt;span class="s1"&gt;'industries'&lt;/span&gt;, &lt;span class="s1"&gt;'intelligence'&lt;/span&gt;, &lt;span class="s1"&gt;'ai.'&lt;/span&gt;, &lt;span class="s1"&gt;'future.'&lt;/span&gt;, &lt;span class="s1"&gt;'new'&lt;/span&gt;, &lt;span class="s1"&gt;'the'&lt;/span&gt;, &lt;span class="s1"&gt;'machine'&lt;/span&gt;, &lt;span class="s1"&gt;'is'&lt;/span&gt;, &lt;span class="s1"&gt;'learning'&lt;/span&gt;, &lt;span class="s1"&gt;'of'&lt;/span&gt;, &lt;span class="s1"&gt;'transforming'&lt;/span&gt;, &lt;span class="s1"&gt;'ai'&lt;/span&gt;, &lt;span class="s1"&gt;'shaping'&lt;/span&gt;, &lt;span class="s1"&gt;'and'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
Vocabulary size: 17
Bigram probabilities matrix:  &lt;span class="o"&gt;[[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.11111111 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.11111111 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.11111111 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.11111111]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.11111111 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.11111111 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05882353 0.05882353 0.05882353 0.05882353 0.05882353 0.05882353
  0.05882353 0.05882353 0.05882353 0.05882353 0.05882353 0.05882353
  0.05882353 0.05882353 0.05882353 0.05882353 0.05882353]
 &lt;span class="o"&gt;[&lt;/span&gt;0.11111111 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05       0.05       0.1        0.05       0.05       0.05
  0.1        0.1        0.05       0.05       0.05       0.05
  0.05       0.05       0.05       0.05       0.05      &lt;span class="o"&gt;]&lt;/span&gt;
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.11111111
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05       0.05       0.05       0.05       0.05       0.05
  0.05       0.05       0.15       0.05       0.05       0.05
  0.05       0.1        0.05       0.05       0.05      &lt;span class="o"&gt;]&lt;/span&gt;
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.11111111 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.11111111
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.11111111 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.11111111 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.11111111 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556]
 &lt;span class="o"&gt;[&lt;/span&gt;0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.05555556 0.05555556 0.05555556
  0.05555556 0.05555556 0.05555556 0.11111111 0.05555556]]
Given &lt;span class="s1"&gt;'ai'&lt;/span&gt;, the model predicts &lt;span class="s1"&gt;'ai.'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Generated sentence: artificial ai. of electricity. ai. artificial future learning artificial of ai.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🚀📂 Check out the complete code for the Bigram Language Model on &lt;a href="https://github.com/SanthoshVijayabaskar/bigram-language-model" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;There you have it—a simple bigram language model built from scratch using just Python and NumPy! 🧑‍💻✨ No fancy libraries needed, and now you’ve got a basic idea of how AI can predict text. Feel free to experiment, tweak the code, or even extend it with more advanced models! 🚀&lt;/p&gt;

&lt;p&gt;Give it a go, and let me know how it turns out. Happy coding! 😄💻&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
PS: Got questions or thoughts? 💡 Drop them in the comments! Let’s keep the conversation going! 🔄 &lt;/p&gt;

&lt;p&gt;🌐 You can also learn more about my work and projects at &lt;a href="https://santhoshvijayabaskar.com" rel="noopener noreferrer"&gt;https://santhoshvijayabaskar.com&lt;/a&gt; &lt;/p&gt;

</description>
      <category>llm</category>
      <category>tutorial</category>
      <category>python</category>
      <category>numpy</category>
    </item>
  </channel>
</rss>
