<?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: selvakumar palanisamy</title>
    <description>The latest articles on DEV Community by selvakumar palanisamy (@selvapal).</description>
    <link>https://dev.to/selvapal</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%2F638740%2Fb8effa86-bceb-481e-bb2b-a3d12af97ec7.jpeg</url>
      <title>DEV Community: selvakumar palanisamy</title>
      <link>https://dev.to/selvapal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/selvapal"/>
    <language>en</language>
    <item>
      <title>AWS re:Invent 2025 Key Announcements: What They Mean for the Future of Cloud, AI &amp; Enterprise Tech</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Thu, 04 Dec 2025 12:42:35 +0000</pubDate>
      <link>https://dev.to/selvapal/aws-reinvent-2025-key-announcements-what-they-mean-for-the-future-of-cloud-ai-enterprise-tech-4g5f</link>
      <guid>https://dev.to/selvapal/aws-reinvent-2025-key-announcements-what-they-mean-for-the-future-of-cloud-ai-enterprise-tech-4g5f</guid>
      <description>&lt;p&gt;AWS re:Invent 2025 made one thing very clear: AWS is fully committing to an AI-first, agent-driven, and hybrid-ready future. &lt;/p&gt;

&lt;p&gt;With major announcements across generative AI, infrastructure, privacy, cost optimisation, and hybrid cloud, the keynote set the direction for how modern applications will be built and scaled over the next decade.&lt;/p&gt;

&lt;p&gt;Below is a summary of the key announcements and what this means for developers, enterprises, and the cloud industry as a whole.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Announcement&lt;/th&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Why it matters&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;P6e GB300 NVIDIA GPU instances&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compute / AI&lt;/td&gt;
&lt;td&gt;New EC2 instances using NVIDIA GB200 NVL72 systems, offering ~20× the compute of prior P5en for huge training and inference jobs - aimed at frontier-scale AI and agents.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;AWS AI Factories&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Hybrid AI infra&lt;/td&gt;
&lt;td&gt;Lets customers deploy AWS AI infrastructure (Ultra servers, Trainium, Bedrock) directly into their own data centres, giving "private AWS-like regions" for regulated or on-prem workloads.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Trainium 3 Ultra servers GA&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;AI accelerators&lt;/td&gt;
&lt;td&gt;Third-gen Trainium Ultra servers become generally available with big boosts in compute, memory bandwidth and energy efficiency, turning racks into AI supercomputers for training LLMs.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Trainium 4 preview&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;AI accelerators&lt;/td&gt;
&lt;td&gt;Next-gen Trainium is announced with large jumps in compute and bandwidth over Trn3, targeting future "absurdly large" frontier models and long-term AI roadmap planning.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Mistral Large &amp;amp; Mistral 3 open-weights in Bedrock&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Models / Inference&lt;/td&gt;
&lt;td&gt;High-performance open-weights models from Mistral are added to Amazon Bedrock, giving customers more choice and flexibility for both heavy reasoning and efficient edge/latency-sensitive use cases.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Amazon Nova 2 model family (Lite, Pro, Sonic)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Models / Inference&lt;/td&gt;
&lt;td&gt;New foundation models optimised for cost and quality: Lite for fast, cheap tasks; Pro for complex reasoning and agent workflows; Sonic for low-latency speech-to-speech conversations - AWS's main answer to other frontier models.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Amazon Nova 2 Omni&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Multimodal AI&lt;/td&gt;
&lt;td&gt;A unified multimodal model that ingests text, images, audio, and video and can output both text and images, simplifying scenarios like watching a video presentation and generating summaries plus visuals in one shot.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Amazon Nova Forge ("Novella" training)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Custom model training&lt;/td&gt;
&lt;td&gt;A training service that lets customers start from Nova checkpoints and train "open training models" with their own data (mid-training, not just fine-tuning), producing custom "Novella" models tailored to their domain.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Policy in AgentCore&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Agentic AI / Governance&lt;/td&gt;
&lt;td&gt;A policy engine for Amazon Agent Core that defines what agents are allowed to do, with which tools and under what conditions - similar to IAM for agents - giving deterministic safety controls beyond prompts.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;AgentCore Evaluations&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Agentic AI / QA&lt;/td&gt;
&lt;td&gt;Built-in evaluation tools for Agent Core with pre-made and custom metrics (correctness, safety, usefulness) to continuously score and monitor agent behaviour in production - essentially QA for agents.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Kiro Autonomous Agent&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Dev tooling / Agents&lt;/td&gt;
&lt;td&gt;An autonomous development agent (built on Kiro) that can take a goal, plan work, update code across repos, write tests, and open PRs with minimal supervision - targeted at long-running engineering tasks like big refactors.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;AWS Security Agent&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Security / Agents&lt;/td&gt;
&lt;td&gt;A specialised security agent on AgentCore that reviews code and configs, flags policy/security violations and suggests fixes, integrating with pipelines to act as a continuous compliance assistant.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;AWS DevOps Agent&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Ops / Agents&lt;/td&gt;
&lt;td&gt;An AgentCore-based DevOps agent that automates provisioning, CI/CD changes, config checks and rollbacks, effectively serving as an always-on extra DevOps team member.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;14&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;X8i memory-optimised instances (Intel Xeon 6)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compute&lt;/td&gt;
&lt;td&gt;New X-family EC2 instances with custom Intel Xeon 6 chips, delivering up to ~50% more memory for big in-memory workloads like SAP HANA or large databases.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Next-gen AMD EPYC memory instances (3TB RAM)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compute&lt;/td&gt;
&lt;td&gt;New AMD-based instances with up to 3 TB RAM, giving another option for very large memory-bound applications at competitive price-performance.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;C8a instances (AMD EPYC)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compute&lt;/td&gt;
&lt;td&gt;CPU-optimised instances using latest AMD EPYC, promising around 30% better performance for compute-heavy tasks such as game servers or batch processing.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;C8iNE instances (Intel + Nitro v6)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compute / Networking&lt;/td&gt;
&lt;td&gt;Network-enhanced compute instances combining Intel Xeon 6 with Nitro v6 to deliver about 2.5× better packet performance per vCPU, aimed at security appliances, firewalls and network-intensive services.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;M8 AZN high-clock instances&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Compute / Low-latency&lt;/td&gt;
&lt;td&gt;New M-family instances with very high single-threaded clock speeds, aimed at latency-critical workloads like gaming, real-time analytics and trading systems.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;19&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;EC2 M3 Ultra Mac&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apple / Dev&lt;/td&gt;
&lt;td&gt;One of two new Mac instances, providing Apple Silicon-based environments for building and testing macOS/iOS apps in the cloud with more power and scale.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;EC2 M4 Max Mac&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apple / Dev&lt;/td&gt;
&lt;td&gt;The second new Mac instance type using the latest Apple chips, giving even higher performance for iOS/macOS CI pipelines and multi-platform app shops.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;21&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Lambda Durable Functions&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Serverless&lt;/td&gt;
&lt;td&gt;Lambda is extended to support long-running, stateful functions that can run for hours or days with resumability and retries - ideal for workflows waiting on agents, human approvals or long processes.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;22&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;S3 max object size increased to 50 TB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Storage&lt;/td&gt;
&lt;td&gt;S3's individual object limit jumps from 5 TB to 50 TB, simplifying storage of huge datasets, high-res media, and very large model checkpoints without chunking.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;23&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;S3 Batch Operations 10× faster&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Storage / Data ops&lt;/td&gt;
&lt;td&gt;S3 Batch Operations are significantly sped up, reducing time and cost for bulk tasks like tagging, copying, and transforming data at petabyte scale.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;24&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Intelligent tiering for S3 Tables (Iceberg)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Storage / Analytics&lt;/td&gt;
&lt;td&gt;S3 Tables (Apache Iceberg) gain intelligent tiering, automatically moving colder table data to cheaper storage classes and potentially cutting costs by up to ~80%.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;S3 Table replication across regions/accounts&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Storage / DR&lt;/td&gt;
&lt;td&gt;S3 Tables can now be replicated across regions and accounts, enabling globally consistent query performance and simpler multi-region analytics setups.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;26&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;S3 Access Points for FSx for NetApp ONTAP&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Storage / Integration&lt;/td&gt;
&lt;td&gt;S3 Access Points are extended to FSx for NetApp ONTAP so ONTAP file data can be accessed like native S3 objects, easing hybrid file/object workflows.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;27&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;S3 Vectors GA&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Storage / Vector DB&lt;/td&gt;
&lt;td&gt;Native vector storage in S3 (S3 Vectors) becomes generally available, designed to hold and search trillions of embeddings with much lower cost than many bespoke vector databases.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;GPU-accelerated vector indexing for OpenSearch&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Search / AI&lt;/td&gt;
&lt;td&gt;OpenSearch adds GPU acceleration for building vector indices, shrinking indexing time by around 10× and cost by ~75%, which is important for large-scale semantic search.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;EMR Serverless - no local storage config needed&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Analytics / Big data&lt;/td&gt;
&lt;td&gt;EMR Serverless clusters no longer require you to provision local storage, removing a major configuration hassle and making EMR closer to "pure" serverless big-data processing.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;GuardDuty support for ECS&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Security / Threat detection&lt;/td&gt;
&lt;td&gt;Amazon GuardDuty's threat detection expands to ECS workloads, enabling managed anomaly and malware detection for containerised apps.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Security Hub GA with new analytics&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Security / Posture mgmt&lt;/td&gt;
&lt;td&gt;AWS Security Hub becomes generally available with real-time risk analytics, trend views and cleaner pricing, centralising security findings across services.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Unified CloudWatch log store&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Observability&lt;/td&gt;
&lt;td&gt;CloudWatch introduces a unified data store that aggregates logs from AWS services and third-party tools (like Okta, CrowdStrike) into one searchable, analytics-ready location.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;33&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;RDS storage expansion for SQL Server &amp;amp; Oracle&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Databases&lt;/td&gt;
&lt;td&gt;Amazon RDS lifts storage limits up to 256 TB for SQL Server and Oracle, increasing capacity and I/O throughput for very large enterprise databases.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;34&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Configurable vCPU counts for RDS SQL Server&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Databases / Licensing&lt;/td&gt;
&lt;td&gt;You can now set custom vCPU configurations for RDS SQL Server, helping tune instance sizing to optimise Microsoft licence spending.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;35&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;RDS support for SQL Server Developer Edition&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Databases / Dev &amp;amp; test&lt;/td&gt;
&lt;td&gt;RDS adds support for SQL Server Developer Edition at zero licence cost, making it easier and cheaper to build and test SQL Server-backed apps in the cloud.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;36&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Database Savings Plans&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Databases / Pricing&lt;/td&gt;
&lt;td&gt;New Savings Plans for databases offer up to about 35% discounts across multiple engines, finally giving a unified, predictable cost model for long-running DB workloads.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Building an AI-Powered Terraform Assistant</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Wed, 13 Aug 2025 11:17:50 +0000</pubDate>
      <link>https://dev.to/selvapal/building-an-ai-powered-terraform-assistant-5cfd</link>
      <guid>https://dev.to/selvapal/building-an-ai-powered-terraform-assistant-5cfd</guid>
      <description>&lt;p&gt;Infrastructure as Code (IaC) has revolutionized how we manage cloud resources, and Terraform is at the forefront of this shift. However, writing, validating, and debugging HCL (HashiCorp Configuration Language) can still be a time-consuming process. What if you could simply describe your desired infrastructure in plain English and have an AI generate, validate, and even correct the code for you?&lt;br&gt;
This post breaks down a powerful Streamlit application that does exactly that. This "Terraform Code Assistant" leverages the OpenAI API to create a seamless workflow for generating IaC for AWS, Azure, or Google Cloud.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Core Architecture: How It Works&lt;/strong&gt;&lt;br&gt;
The application is built with a clear, three-step workflow in mind: Generate, Validate, and Correct. It combines the user-friendly interface of Streamlit with the power of OpenAI's language models and the reliability of the Terraform CLI.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 1: Setting Up the Environment Automatically&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before we can do anything with Terraform, we need to have the Terraform executable available. In a local environment, this is a simple download. But for a web app deployed on a platform like Streamlit Community Cloud, we need a more robust solution.&lt;br&gt;
The get_terraform_executable function handles this automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Platform Detection:&lt;/strong&gt; It first checks the user's operating system (Linux, Windows, etc.) and architecture (amd64, arm64) to determine the correct Terraform version to download.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Downloading and Unzipping:&lt;/strong&gt; It fetches the appropriate zip file from HashiCorp's official releases page, extracts it, and makes the terraform binary executable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Caching for Efficiency:&lt;/strong&gt; The &lt;a class="mentioned-user" href="https://dev.to/st"&gt;@st&lt;/a&gt;.cache_resource decorator is crucial here. It ensures that Terraform is downloaded only once when the app first starts. For all subsequent user sessions, the cached executable is used, making the app much faster and more efficient.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 2: The User Interface and Configuration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A good tool needs an intuitive interface. The app is divided into a sidebar for configuration and a main area for interaction.&lt;br&gt;
The Sidebar&lt;/p&gt;

&lt;p&gt;The sidebar contains all the necessary setup options:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Cloud Provider Selection:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;A simple dropdown lets the user choose between AWS, Azure, and Google Cloud. This choice is passed to the AI to ensure it generates the correct provider-specific code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. API Key Management:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The app securely loads the OPENAI_API_KEY from Streamlit's secrets management. It provides clear instructions for the user if the key is not found, ensuring a smooth setup process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Instructions:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;A "How to use" section guides the user through the app's workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 3: The AI-Powered Workflow in Action&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is where the magic happens. The three main buttons—Generate, Validate, and Correct—drive the entire process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Generate with AI&lt;/strong&gt;&lt;br&gt;
When a user describes their infrastructure (e.g., "An S3 bucket for logging and a t3.small EC2 instance") and clicks this button, the app:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Constructs a detailed system prompt for the OpenAI API. This prompt instructs the AI to act as a Terraform expert for the selected cloud provider and to return only a clean block of HCL code.&lt;/li&gt;
&lt;li&gt;Sends the user's request to the gpt-4o model.&lt;/li&gt;
&lt;li&gt;Parses the AI's response to extract the HCL code block and displays it in the code editor.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Validate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the code is generated, the user can validate it. Clicking this button triggers a background process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A temporary directory is created, and the generated Terraform code is saved to a main.tf file.&lt;/li&gt;
&lt;li&gt;The app runs terraform init to download the necessary provider plugins.&lt;/li&gt;
&lt;li&gt;It then runs terraform validate to check the syntax and configuration.&lt;/li&gt;
&lt;li&gt;The output (success or error) is captured and displayed in the results area.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Correct with AI&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the validation fails, the user doesn't have to debug the code manually. The Correct with AI button becomes active, and clicking it will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new prompt for the AI that includes both the incorrect code and the specific validation error message from Terraform.&lt;/li&gt;
&lt;li&gt;Ask the AI to act as a code correction expert and fix the error.&lt;/li&gt;
&lt;li&gt;The corrected code is then returned and placed back into the editor, ready for re-validation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This Terraform Code Assistant is a powerful example of how AI can be integrated into DevOps workflows to boost productivity and lower the barrier to entry for managing cloud infrastructure. By combining a smart, automated setup, a clean user interface, and a powerful generate-validate-correct loop, this Streamlit app transforms a complex task into a simple, conversational experience.&lt;/p&gt;

&lt;p&gt;Try this terraform code gen ai agent app &lt;/p&gt;

&lt;p&gt;&lt;a href="https://terraformcodegen-selvapal-poc.streamlit.app" rel="noopener noreferrer"&gt;https://terraformcodegen-selvapal-poc.streamlit.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Repo : &lt;a href="https://github.com/selvakumarsai/terraformcodegen" rel="noopener noreferrer"&gt;https://github.com/selvakumarsai/terraformcodegen&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Terraforming!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Deep Dive into CrewAI and Agentic Design</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Wed, 11 Jun 2025 23:31:37 +0000</pubDate>
      <link>https://dev.to/selvapal/a-deep-dive-into-crewai-and-agentic-design-46kj</link>
      <guid>https://dev.to/selvapal/a-deep-dive-into-crewai-and-agentic-design-46kj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Mastering Mock Interviews with AI:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Deep Dive into CrewAI and Agentic Design&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Are you preparing for a technical interview and wishing you had a personalized, intelligent interviewer to practice with? Look no further! My latest project, ai_mock_interview demonstrates a powerful application of AI agents using the CrewAI framework to create a dynamic and realistic mock interview experience.&lt;/p&gt;

&lt;p&gt;This blog post will walk you through the core components of the ai_mock_interview project, highlighting how specific Python functions are designed to act as intelligent agents and how they collaborate within a "crew" to deliver a comprehensive mock interview and feedback session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Power of Agentic AI with CrewAI&lt;/strong&gt;&lt;br&gt;
Before dive into the code, let's briefly understand the underlying magic. CrewAI is an open-source framework for orchestrating role-playing autonomous AI agents. It allows you to define agents with specific roles, backstories, and goals, and then assign tasks to them. These agents can communicate, delegate, and collaborate to achieve a common objective, mimicking a real-world team.&lt;br&gt;
In  ai_mock_interview project, there are  several agents, each responsible for a distinct phase of the interview process.&lt;/p&gt;

&lt;p&gt;Refer my GitHub repo &lt;a href="https://github.com/selvakumarsai/ai_mock_interview" rel="noopener noreferrer"&gt;https://github.com/selvakumarsai/ai_mock_interview&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/selvakumarsai/ai_mock_interview/blob/main/interview_practice_system.py" rel="noopener noreferrer"&gt;https://github.com/selvakumarsai/ai_mock_interview/blob/main/interview_practice_system.py&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's break down the key Python functions and classes&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Preparation: Research the company and role, then generate a primary interview question.&lt;/li&gt;
&lt;li&gt;Concurrent Follow-up Generation: While the user answers, a follow-up question is already being prepared in the background.&lt;/li&gt;
&lt;li&gt;User Interaction: The main question is presented, and the user's answer is captured.&lt;/li&gt;
&lt;li&gt;Initial Evaluation: The user's first answer is evaluated against the model answer, providing immediate feedback.&lt;/li&gt;
&lt;li&gt;Dynamic Follow-up: The pre-generated follow-up question is presented, allowing for a deeper assessment.&lt;/li&gt;
&lt;li&gt;Final Evaluation: The follow-up answer is also evaluated, completing the mock interview cycle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This multi-stage, agent-driven approach provides a robust, interactive, and highly valuable tool for anyone looking to sharpen their technical interview skills. By leveraging AI agents, we've created a system that is not only automated but also intelligent and adaptable, simulating the dynamic nature of real-world interviews.&lt;br&gt;
Check out the  script to see this sophisticated agentic design in action!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defining the Output Structure:&lt;/strong&gt; QuestionAnswerPair&lt;br&gt;
Before delving into agents, we define a Pydantic BaseModel to structure the output of our question-generating agents.&lt;br&gt;
Python&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class QuestionAnswerPair(BaseModel):
    """Schema for the question and its correct answer."""
    question: str = Field(..., description="The technical question to be asked")
    correct_answer: str = Field(..., description="The correct answer to the question")

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

&lt;/div&gt;



&lt;p&gt;This QuestionAnswerPair class ensures that when an agent generates a question, it also provides the correct_answer in a standardized format, which is crucial for the evaluation phase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Company Research Specialist Agent (company_researcher)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This agent is the intelligence gatherer, laying the groundwork for relevant questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Object:&lt;/strong&gt; company_researcher (an instance of Agent).&lt;br&gt;
&lt;strong&gt;Role:&lt;/strong&gt; "Company Research Specialist"&lt;br&gt;
&lt;strong&gt;Backstory:&lt;/strong&gt; "You are an expert in researching companies and creating technical interview questions. You have deep knowledge of tech industry hiring practices and can create relevant questions that test both theoretical knowledge and practical skills."&lt;br&gt;
&lt;strong&gt;Goal:&lt;/strong&gt; "Gather information about the company and create interview questions with answers"&lt;br&gt;
&lt;strong&gt;Tools:&lt;/strong&gt; It's equipped with SerperDevTool(), allowing it to perform web searches to gather company-specific information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;search_tool = SerperDevTool()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;company_researcher = Agent(
    role="Company Research Specialist",
    goal="Gather information about the company and create interview questions with answers",
    backstory="""You are an expert in researching companies and creating technical interview questions.
    You have deep knowledge of tech industry hiring practices and can create relevant
    questions that test both theoretical knowledge and practical skills.""",
    tools=[search_tool],
    verbose=True,
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Integration:&lt;/strong&gt; This agent is assigned the create_company_research_task, which uses its research capabilities to provide a summary of the company's technical requirements and interview process. This output then informs the question_preparer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create_company_research_task(company_name: str, role: str, difficulty: str) -&amp;gt; Task:
    return Task(
        description=f"""Research {company_name} and gather information about:
        1. Their technical interview process
        2. Common interview questions for {role} positions at {difficulty} difficulty level
        3. Technical stack and requirements

        Provide a summary of your findings.""",
        expected_output="A report about the company's technical requirements and interview process",
        agent=company_researcher,
    )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. The Question and Answer Preparer Agent (question_preparer)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This agent is the content creator, responsible for crafting the interview questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Object:&lt;/strong&gt; question_preparer (an instance of Agent).&lt;br&gt;
&lt;strong&gt;Role:&lt;/strong&gt; "Question and Answer Preparer"&lt;br&gt;
&lt;strong&gt;Backstory:&lt;/strong&gt; "You are an experienced technical interviewer who knows how to create challenging yet fair technical questions and provide detailed model answers. You understand how to assess different skill levels and create questions that test both theoretical knowledge and practical problem-solving abilities."&lt;br&gt;
&lt;strong&gt;Goal:&lt;/strong&gt; "Prepare comprehensive questions with model answers"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;question_preparer = Agent(
    role="Question and Answer Preparer",
    goal="Prepare comprehensive questions with model answers",
    backstory="""You are an experienced technical interviewer who knows how to create
    challenging yet fair technical questions and provide detailed model answers.
    You understand how to assess different skill levels and create questions that
    test both theoretical knowledge and practical problem-solving abilities.""",
    verbose=True,
)

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Integration:&lt;/strong&gt; This agent is assigned the create_question_preparation_task. It takes the research from the company_researcher and then generates a technical question at the specified difficulty, along with a comprehensive model answer, adhering to the QuestionAnswerPair Pydantic schema for structured output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create_question_preparation_task(difficulty: str) -&amp;gt; Task:
    return Task(
        description=f"""Based on the company research, create:
        1. A technical question at {difficulty} difficulty level that tests both theory and practice
        2. A comprehensive model answer that covers all key points
        3. Key points to look for in candidate answers

        The question should be appropriate for {difficulty} difficulty level - challenging but fair, and the answer should be detailed.""",
        expected_output="A question and its correct answer",
        output_pydantic=QuestionAnswerPair,
        agent=question_preparer,
    )

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. The Answer Evaluator Agent (answer_evaluator)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This agent is the critic, providing crucial feedback on the candidate's answers.&lt;br&gt;
&lt;strong&gt;Python Object:&lt;/strong&gt; answer_evaluator (an instance of Agent).&lt;br&gt;
&lt;strong&gt;Role:&lt;/strong&gt; "Answer Evaluator"&lt;br&gt;
&lt;strong&gt;Backstory:&lt;/strong&gt; "You are a senior technical interviewer who evaluates answers against the expected solution. You know how to identify if an answer is technically correct and complete."&lt;br&gt;
&lt;strong&gt;Goal:&lt;/strong&gt; "Evaluate if the given answer is correct for the question"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;answer_evaluator = Agent(
    role="Answer Evaluator",
    goal="Evaluate if the given answer is correct for the question",
    backstory="""You are a senior technical interviewer who evaluates answers
    against the expected solution. You know how to identify if an answer is
    technically correct and complete.""",
    verbose=True,
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Integration:&lt;/strong&gt; This agent is central to the create_evaluation_task. It receives the original question, the user's answer, and the correct answer, then provides a detailed evaluation, including correctness, key points covered/missing, and an explanation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create_evaluation_task(
    question: str, user_answer: str, correct_answer: str
) -&amp;gt; Task:
    return Task(
        description=f"""Evaluate if the given answer is correct for the question:
        Question: {question}
        Answer: {user_answer}
        Correct Answer: {correct_answer}
        Provide:
        1. Whether the answer is correct (Yes/No)
        2. Key points that were correct or missing
        3. A brief explanation of why the answer is correct or incorrect""",
        expected_output="Evaluation of whether the answer is correct for the question with feedback",
        agent=answer_evaluator,
    )

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. The Follow-up Question Specialist Agent (follow_up_questioner)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This agent simulates a dynamic interview by generating follow-up questions.&lt;br&gt;
&lt;strong&gt;Python Object:&lt;/strong&gt; follow_up_questioner (an instance of Agent).&lt;br&gt;
&lt;strong&gt;Role:&lt;/strong&gt; "Follow-up Question Specialist"&lt;br&gt;
&lt;strong&gt;Backstory:&lt;/strong&gt; "You are an expert technical interviewer who knows how to create meaningful follow-up questions that probe deeper into a candidate's knowledge and understanding. You can create questions that build upon previous answers and test different aspects of the candidate's technical expertise."&lt;br&gt;
&lt;strong&gt;Goal:&lt;/strong&gt; "Create relevant follow-up questions based on the context"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;follow_up_questioner = Agent(
    role="Follow-up Question Specialist",
    goal="Create relevant follow-up questions based on the context",
    backstory="""You are an expert technical interviewer who knows how to create
    meaningful follow-up questions that probe deeper into a candidate's knowledge
    and understanding. You can create questions that build upon previous answers
    and test different aspects of the candidate's technical expertise.""",
    verbose=True,
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Integration:&lt;/strong&gt; This agent is tasked by create_follow_up_question_task. It takes the original question, company context, role, and difficulty to craft a new question that deepens the assessment, also returning its output as a QuestionAnswerPair.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def create_follow_up_question_task(
    question: str, company_name: str, role: str, difficulty: str
) -&amp;gt; Task:
    return Task(
        description=f"""Based on the following context, create a relevant follow-up question:
        Original Question: {question}
        Company: {company_name}
        Role: {role}
        Difficulty Level: {difficulty}

        Create a follow-up question that:
        1. Builds upon the original question
        2. Tests deeper understanding of the topic
        3. Is appropriate for the specified difficulty level
        4. Is relevant to the company and role

        The follow-up question should be challenging but fair, and should help
        assess the candidate's technical depth and problem-solving abilities.""",
        expected_output="A follow-up question that builds upon the original question",
        output_pydantic=QuestionAnswerPair,
        agent=follow_up_questioner,
    )

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Orchestrating the Interview:&lt;/strong&gt; This system&lt;br&gt;
intelligently uses two main crews, one for preparation and one for evaluation, with an additional crew for generating follow-up questions concurrently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A. The preparation_crew (Question Preparation)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agents:&lt;/strong&gt; company_researcher, question_preparer&lt;br&gt;
&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br&gt;
     create_company_research_task: company_researcher researches the  company, role, and difficulty.&lt;br&gt;
    create_question_preparation_task: question_preparer uses the research to generate the primary technical question and its correct answer.&lt;br&gt;
&lt;strong&gt;Process:&lt;/strong&gt; Process.sequential – the tasks are executed one after another.&lt;br&gt;
&lt;strong&gt;Outcome:&lt;/strong&gt; This crew's kickoff() method returns a QuestionAnswerPair object containing the main question and its correct answer, ready to be presented to the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    preparation_crew = Crew(
        agents=[company_researcher, question_preparer],
        tasks=[
            create_company_research_task(company_name, role, difficulty),
            create_question_preparation_task(difficulty),
        ],
        process=Process.sequential,
        verbose=True,
    )

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;B. The evaluation_crew (Answer Evaluation)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agents:&lt;/strong&gt; answer_evaluator&lt;br&gt;
&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br&gt;
    create_evaluation_task: answer_evaluator assesses the user's provided answer against the expected correct answer for the initial question.&lt;br&gt;
&lt;strong&gt;Process:&lt;/strong&gt; Process.sequential&lt;br&gt;
&lt;strong&gt;Outcome:&lt;/strong&gt; This crew's kickoff() provides a detailed textual evaluation of the user's response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    evaluation_crew = Crew(
        agents=[answer_evaluator],
        tasks=[
            create_evaluation_task(
                question=preparation_result.pydantic.question,
                user_answer=user_answer,
                correct_answer=preparation_result.pydantic.correct_answer,
            )
        ],
        process=Process.sequential,
        verbose=True,
    )

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;C. The follow_up_crew (Follow-up Question Generation)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This crew is created and kicked off asynchronously using asyncio, meaning it runs in the background while the user answers the main question.&lt;br&gt;
&lt;strong&gt;Agents:&lt;/strong&gt;follow_up_questioner&lt;br&gt;
&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;br&gt;
    create_follow_up_question_task: The follow_up_questioner generates a relevant follow-up question based on the initial question and context.&lt;br&gt;
&lt;strong&gt;Process:&lt;/strong&gt; Process.sequential&lt;br&gt;
&lt;strong&gt;Outcome:&lt;/strong&gt; By the time the user finishes answering the first question, the follow_up_question_task (which is an asyncio.Task) is awaited, and its result (a QuestionAnswerPair for the follow-up) is retrieved. This allows for a more seamless interview flow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    follow_up_question_task = asyncio.create_task(
        generate_follow_up_question(
            question=preparation_result.pydantic.question,
            company_name=company_name,
            role=role,
            difficulty=difficulty,
        )
    )

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The start_interview_practice&lt;/strong&gt; function orchestrates these crews. It first runs the preparation_crew, then concurrentlyinitiates the follow_up_crew while prompting the user for an answer to the main question. Once the user answers, the evaluation_crew assesses the first answer. Finally, it presents the pre-generated follow-up question and evaluates the user's second response.&lt;/p&gt;

</description>
      <category>genai</category>
      <category>crewai</category>
      <category>python</category>
      <category>ai</category>
    </item>
    <item>
      <title>MCP — Azure CLI integration</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Sun, 06 Apr 2025 07:28:11 +0000</pubDate>
      <link>https://dev.to/selvapal/mcp-azure-cli-integration-of5</link>
      <guid>https://dev.to/selvapal/mcp-azure-cli-integration-of5</guid>
      <description>&lt;p&gt;You’ve probably heard of Model Context Protocol (MCP), which has recently attracted a lot of attention from the AI community.&lt;/p&gt;

&lt;p&gt;We will discuss what MCP is and why it is important in this post.&lt;br&gt;
Think of MCP as “USB-C for AI integrations,” an open standard that enables consistent connections between AI models and a wide range of applications and data sources. &lt;/p&gt;

&lt;p&gt;Simply put, MCP eliminates the need for separate adapters or unique code for each software application by allowing an AI assistant to communicate with them all using a standard language.&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%2Fp20jdt5eigqx9aaskcgj.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%2Fp20jdt5eigqx9aaskcgj.png" alt="Image description" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MCP functions similarly to providing your AI assistant with a universal remote control for all of your electronic gadgets and services.&lt;/p&gt;

&lt;p&gt;Using an AI assistant with external tools without MCP is similar to having a number of appliances, each with its own plug and no universal outlet. Everywhere, developers had to contend with disjointed integrations. Your AI IDE may, for instance, employ one technique to pull code from GitHub, another to retrieve information from a database, and a third to automate a design tool; each of these integrations requires a unique adapter. &lt;/p&gt;

&lt;p&gt;This is not only time-consuming, but it is also fragile and non-scalable.MCP is based on a client-server architecture, which allows a host programme to communicate with several servers.&lt;/p&gt;

&lt;p&gt;Three main parts form the framework of the protocol:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Host&lt;/li&gt;
&lt;li&gt;Client&lt;/li&gt;
&lt;li&gt;Server&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before we get into detail on each, here is a high-level summary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MCP Server :&lt;/strong&gt; The server functions as an internal translator for the app; it may interpret a natural language request (from an AI) and carry out the corresponding action within the app.&lt;br&gt;
The functionality (or “services”) of the application is made uniformly available by an MCP server.&lt;br&gt;
These adapters are small and lightweight and work with a particular programme or service. The functionality of such programme (its “services”) is made readily accessible via an MCP server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tool Discovery:&lt;/strong&gt; They can describe what actions/capabilities the application offers&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Command parsing:&lt;/strong&gt; They convert incoming AI instructions into exact API calls or application commands.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Response formatting:&lt;/strong&gt; Involves taking the data, confirmation messages, and other output from the app and formatting it so the AI model can interpret it. Typically, this is done as text or structured data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error Handling :&lt;/strong&gt; Handle exceptions and erroneous requests and provide helpful error messages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MCP client:&lt;/strong&gt; AI assistant includes an MCP client component. This client maintains a 1:1 connection to an MCP server.&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%2Fforabewe0haar81vkg70.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%2Fforabewe0haar81vkg70.png" alt="Image description" width="800" height="833"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have played with  Azure CLI MCP Server  ,MCP Server that wraps the Azure CLI, adds a nice prompt to improve how it works, and exposes it.&lt;/p&gt;

&lt;p&gt;It has access to the full Azure CLI, so it can do anything the Azure CLI can do. This MCP server currently only works with the stdio transport, so it should run locally on your machine, using your Azure CLI credentials.&lt;br&gt;
This server can run as a Java application or inside a Docker container.&lt;/p&gt;

&lt;p&gt;Install MCP Claude desktop&lt;br&gt;
&lt;a href="https://claude.ai/download" rel="noopener noreferrer"&gt;https://claude.ai/download&lt;/a&gt;&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%2F2kxrx2wcv8d9owvbi388.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%2F2kxrx2wcv8d9owvbi388.png" alt="Image description" width="800" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Install and configure the server with Java&lt;/p&gt;

&lt;p&gt;Install the Azure CLI: you can do this by following the instructions here (&lt;a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/cli/azure/install-azure-cli&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Authenticate to your Azure account. You can do this by running az login in your terminal.&lt;/p&gt;

&lt;p&gt;Make sure you have Java 17 or higher installed&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download azure-cli-mcp&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/jdubois/azure-cli-mcp/releases" rel="noopener noreferrer"&gt;https://github.com/jdubois/azure-cli-mcp/releases&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Download the latest release: gh release download — repo jdubois/azure-cli-mcp — pattern=’azure-cli-mcp.jar’&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; % gh release download --repo jdubois/azure-cli-mcp --pattern='azure-cli-mcp.jar'
To get started with GitHub CLI, please run:  gh auth login
Alternatively, populate the GH_TOKEN environment variable with a GitHub API authentication token.

 % gh auth login
? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: xxxxxxxx
Press Enter to open https://github.com/login/device in your browser... 
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as xxxxxxxxxxxxx

 % gh release download --repo jdubois/azure-cli-mcp --pattern='azure-cli-mcp.jar'

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

&lt;/div&gt;



&lt;p&gt;To use the server from Claude Desktop, add the server to your claude_desktop_config.json file. Please note that you need to point to the location where you downloaded the azure-cli-mcp.jar file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;% open ~/Library/Application\ Support/Claude

% touch ~/Library/Application\ Support/Claude/claude_desktop_config.json

% vi ~/Library/Application\ Support/Claude/claude_desktop_config.json

{
    "mcpServers": {
        "azure-cli": {
            "command": "java",
            "args": [
                "-jar",
              "~/Downloads/azure-cli-mcp.jar"
            ]
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create azure  resource group and storage blob  using using Claude desktop &lt;/p&gt;

&lt;p&gt;Open Cluade desktop &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%2Fcfw777ipi9l8crwz5ndl.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%2Fcfw777ipi9l8crwz5ndl.png" alt="Image description" width="800" height="601"&gt;&lt;/a&gt;&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%2Fts03s5jc3xhhei34v5e4.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%2Fts03s5jc3xhhei34v5e4.png" alt="Image description" width="800" height="598"&gt;&lt;/a&gt;&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%2Fm0tnk36g1j3kdzdmz3e0.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%2Fm0tnk36g1j3kdzdmz3e0.png" alt="Image description" width="800" height="260"&gt;&lt;/a&gt;&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%2Fb0koeox95lxd1q5fooxk.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%2Fb0koeox95lxd1q5fooxk.png" alt="Image description" width="800" height="592"&gt;&lt;/a&gt;&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%2Fqr7ridhoe2n28gyf0da8.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%2Fqr7ridhoe2n28gyf0da8.png" alt="Image description" width="800" height="597"&gt;&lt;/a&gt;&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%2F18ub55vczx7iiuqokqxh.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%2F18ub55vczx7iiuqokqxh.png" alt="Image description" width="800" height="597"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Is it Secured : No, This MCP server executes az commands for you; an attacker might use it to execute any other command. The current implementation only supports the stio transport, like the majority of MCP servers now in use. It is designed to operate locally on your computer using your Azure CLI credentials, much like you would if you were doing it yourself.&lt;br&gt;
It is entirely feasible to have this MCP server support the http transport and Azure token authentication in the future, allowing for remote use by various users. The second step will be completed after the SDK and MCP standard are more stable.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>mcp</category>
      <category>azure</category>
    </item>
    <item>
      <title>AWS Q Developer</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Fri, 28 Mar 2025 09:54:59 +0000</pubDate>
      <link>https://dev.to/selvapal/aws-q-developer-3ejn</link>
      <guid>https://dev.to/selvapal/aws-q-developer-3ejn</guid>
      <description>&lt;p&gt;AWS Q Developer is an AI-powered coding assistant designed to help developers write, debug, and optimize code more efficiently. It offers real-time code suggestions, automatic documentation generation, and AWS service integrations, making cloud development more intuitive and productive.&lt;/p&gt;

&lt;p&gt;Unlike generic AI code assistants, AWS Q Developer is specifically tailored for AWS environments, providing optimized recommendations for AWS SDKs, APIs, and cloud services.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;AI-Driven Code Suggestions&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Offers real-time, context-aware code completions.&lt;/li&gt;
&lt;li&gt;Provides function recommendations based on natural language comments.&lt;/li&gt;
&lt;li&gt;Supports multiple programming languages, including Python, Java, JavaScript, TypeScript, and C#.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;AWS Service Integrations&lt;/strong&gt;   &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Helps developers efficiently integrate AWS services like Lambda,    S3, DynamoDB, EC2, and API Gateway.&lt;/li&gt;
&lt;li&gt;   Suggests optimal configurations for AWS resources.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Security Scanning and Best Practices&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identifies vulnerabilities and misconfigurations in code.&lt;/li&gt;
&lt;li&gt;Provides security best practices based on AWS Well-Architected          Framework.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Automated Code Refactoring and Optimisation&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Improves existing code by suggesting optimizations.&lt;/li&gt;
&lt;li&gt;Helps migrate legacy code to modern AWS cloud architectures.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Natural Language Query Support&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Developers can ask questions in plain English, and AWS Q Developer retrieves relevant AWS documentation, code snippets, or troubleshooting steps&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Seamless IDE Integration&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Works with VS Code, IntelliJ IDEA, AWS Cloud9, and JetBrains IDEs.&lt;/li&gt;
&lt;li&gt;Provides in-line AI assistance within the developer's workflow.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Setting Up AWS Q Developer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Install AWS Q Developer in Your IDE&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Open VS Code, IntelliJ IDEA, or AWS Cloud9.&lt;/li&gt;
&lt;li&gt; Install the AWS Toolkit extension.&lt;/li&gt;
&lt;li&gt; Enable AWS Q Developer within the AWS Toolkit settings.&lt;/li&gt;
&lt;li&gt; Sign in with your AWS IAM credentials.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 2: Start Using AWS Q Developer for Code Assistance&lt;br&gt;
Write comments describing a function, and AWS Q Developer will generate the corresponding code.&lt;br&gt;
Type incomplete functions, and AWS Q will autocomplete them based on best practices.&lt;/p&gt;

&lt;p&gt;Step 3: Use AWS Q Developer for Security and Best Practices&lt;br&gt;
Run security scans to detect vulnerabilities in AWS SDK usage.&lt;br&gt;
Get AWS Well-Architected Framework recommendations for cloud applications.&lt;/p&gt;

&lt;p&gt;Step 4: Automate Code Documentation&lt;br&gt;
Generate API documentation by running AWS Q Developer’s documentation feature.&lt;/p&gt;

&lt;p&gt;Using AWS Q Developer in Python&lt;br&gt;
Below is an example of AWS Q Developer generating a function to upload a file to Amazon S3:&lt;br&gt;
import boto3&lt;/p&gt;

&lt;p&gt;def upload_file_to_s3(bucket_name, file_path, object_name):&lt;br&gt;
    """Uploads a file to an S3 bucket."""&lt;br&gt;
    s3 = boto3.client('s3')&lt;br&gt;
    try:&lt;br&gt;
        s3.upload_file(file_path, bucket_name, object_name)&lt;br&gt;
        print(f"File {file_path} uploaded to {bucket_name}/{object_name}")&lt;br&gt;
    except Exception as e:&lt;br&gt;
        print(f"Error uploading file: {e}")&lt;br&gt;
upload_file_to_s3("my-bucket", "localfile.txt", "uploaded-file.txt")&lt;/p&gt;

&lt;p&gt;AWS Q Developer can generate this function automatically from a &lt;br&gt;
simple comment like:&lt;/p&gt;

&lt;p&gt;Function to upload a file to Amazon S3&lt;/p&gt;

</description>
    </item>
    <item>
      <title>AWS Bedrock Guardrails: Enhancing AI Security and Compliance</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Fri, 14 Mar 2025 09:42:27 +0000</pubDate>
      <link>https://dev.to/selvapal/aws-bedrock-guardrails-enhancing-ai-security-and-compliance-57mk</link>
      <guid>https://dev.to/selvapal/aws-bedrock-guardrails-enhancing-ai-security-and-compliance-57mk</guid>
      <description>&lt;p&gt;AWS Bedrock Guardrails is a set of security and content moderation tools designed to help organizations govern the use of generative AI models within Amazon Bedrock. It enables developers to define policies that restrict harmful, biased, or non-compliant content generation while maintaining the flexibility to build customized AI-driven applications.&lt;/p&gt;

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

&lt;p&gt;Content Filtering and Moderation &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatically detects and blocks harmful, offensive, or         inappropriate content in AI-generated responses.&lt;/li&gt;
&lt;li&gt;Supports configurable thresholds to determine the severity of      filtered content.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Customisable Policy Enforcement&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Allows businesses to define domain-specific restrictions to prevent AI-generated content that violates organizational policies.&lt;/li&gt;
&lt;li&gt;Policies can be fine-tuned based on industry-specific compliance needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Bias and Ethical AI Governance&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Detects and mitigates potential biases in AI-generated outputs.&lt;/li&gt;
&lt;li&gt;Supports ethical AI principles by ensuring fair and unbiased content generation.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Logging and Monitoring&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Integrates with AWS CloudWatch and AWS Audit Manager to log AI model responses for compliance auditing.&lt;/li&gt;
&lt;li&gt;Enables tracking and review of AI-generated outputs for continuous improvement.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Seamless Integration with AWS Services&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Works with Amazon Bedrock models such as Anthropic Claude, AI21, Stability AI, and others.&lt;/li&gt;
&lt;li&gt;Can be integrated with Amazon Lex, Amazon Kendra, and AWS Lambda for extended use cases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Improved Security: Prevents harmful content generation in AI applications.&lt;/li&gt;
&lt;li&gt;Regulatory Compliance: Helps organizations adhere to industry regulations (e.g., GDPR, HIPAA).&lt;/li&gt;
&lt;li&gt;Trust and Transparency: Builds user trust by ensuring AI-generated content is ethical and safe.&lt;/li&gt;
&lt;li&gt;Scalability: Works across various AWS services, making it easy to scale AI governance.&lt;/li&gt;
&lt;li&gt;Customisation: Tailor policies based on specific organizational requirements.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Use Cases&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Enterprise AI Chatbots&lt;br&gt;
     Prevents chatbots from generating inappropriate, misleading, or harmful responses.&lt;/p&gt;

&lt;p&gt;Content Moderation in Social Media and E-commerce&lt;br&gt;
    Filters user-generated content for offensive language or policy     violations.&lt;br&gt;
Healthcare and Finance Applications&lt;br&gt;
    Ensures AI-generated responses comply with industry           regulations and ethical standards.&lt;br&gt;
Legal and Compliance Review&lt;br&gt;
    Logs AI interactions for auditability and compliance checks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Configure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Enable AWS Bedrock Guardrails&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Log in to the AWS Management Console.&lt;/li&gt;
&lt;li&gt; Navigate to Amazon Bedrock.&lt;/li&gt;
&lt;li&gt; Under Guardrails, enable the service for your AI models.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 2: Define Content Policies&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Create a new Guardrails policy.&lt;/li&gt;
&lt;li&gt; Specify restricted topics, language filters, and severity levels.&lt;/li&gt;
&lt;li&gt; Apply predefined compliance templates if needed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 3: Integrate Guardrails with AI Models&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Attach the Guardrails policy to a specific AI model in Amazon Bedrock.&lt;/li&gt;
&lt;li&gt; Configure API access for AI applications.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 4: Monitor and Audit AI Responses&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Use AWS CloudWatch to monitor flagged content.&lt;/li&gt;
&lt;li&gt; Enable logging in AWS Audit Manager for compliance tracking.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below is a sample AWS Lambda function that integrates with Amazon Bedrock and enforces Guardrails policies&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import boto3

def moderate_ai_response(prompt):
    bedrock_client = boto3.client("bedrock")

    response = bedrock_client.invoke_model(
        modelId="anthropic-clause-v1",
        body={"prompt": prompt}
    )

    # Apply Guardrails filtering
    guardrails_client = boto3.client("bedrock-guardrails")
    moderation_result = guardrails_client.moderate_content(
        content=response["body"]
    )

    if moderation_result["flagged"]:
        return "Content blocked due to policy violations."
    else:
        return response["body"]

# Example usage
user_input = "Tell me something controversial."
print(moderate_ai_response(user_input))

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

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>AWS VPC Lattice</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Thu, 13 Mar 2025 07:43:15 +0000</pubDate>
      <link>https://dev.to/selvapal/aws-vpc-lattice-ajj</link>
      <guid>https://dev.to/selvapal/aws-vpc-lattice-ajj</guid>
      <description>&lt;p&gt;AWS VPC Lattice is a fully managed application networking service that simplifies service-to-service communication across VPCs and AWS accounts. It enables users to connect, secure, and monitor service-to-service communications without managing complex network topologies.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Cross-VPC and Cross-Account Communication: Enables seamless communication between services across multiple VPCs and AWS accounts.&lt;/li&gt;
&lt;li&gt;Service Discovery and Load Balancing: Provides automatic service discovery and distributes traffic across service instances.&lt;/li&gt;
&lt;li&gt;Centralized Access Management: Integrates with IAM to define access policies.&lt;/li&gt;
&lt;li&gt;Observability and Monitoring: Offers built-in monitoring via AWS CloudWatch and AWS X-Ray.&lt;/li&gt;
&lt;li&gt;Security and Compliance: Supports TLS encryption, authentication, and authorization mechanisms.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;AWS VPC Lattice setup consists of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Services: Applications deployed in different VPCs.&lt;/li&gt;
&lt;li&gt;VPC Lattice Service Network: A logical boundary to define services and connectivity.&lt;/li&gt;
&lt;li&gt;Target Groups: Define the endpoints where requests are routed.&lt;/li&gt;
&lt;li&gt;Listeners and Rules: Define how traffic is managed and directed&lt;/li&gt;
&lt;/ol&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%2Ffpdb3sjwvkiqzpyifpnl.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%2Ffpdb3sjwvkiqzpyifpnl.png" alt="Image description" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AWS Accounts: service, central, and consumer&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Service Account – VPC Lattice service&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# VPC Lattice Module
module "vpc_lattice_service" {
  source  = "aws-ia/amazon-vpc-lattice-module/aws"
  version = "0.0.2"

  services = {
    lambdaservice = {
      name        = "lambda-service"
      auth_type   = "AWS_IAM"
      auth_policy = local.auth_policy

      listeners = {
        http_listener = {
          name     = "httplistener"
          port     = 80
          protocol = "HTTP"
          default_action_forward = {
            target_groups = {
              lambdatarget = { weight = 100 }
            }
          }
        }
      }
    }
  }

  target_groups = {
    lambdatarget = {
      type = "LAMBDA"
      targets = {
        lambdafunction = { id = aws_lambda_function.lambda.arn }
      }
    }
  }
}

# VPC Lattice service Auth Policy
locals {
  auth_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action    = "*"
        Effect    = "Allow"
        Principal = "*"
        Resource  = "*"
      }
    ]
  })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Resource share *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Resource Share
resource "aws_ram_resource_share" "resource_share" {
  name                      = "Amazon VPC Lattice service"
  allow_external_principals = true
}

# Principal Association
resource "aws_ram_principal_association" "principal_association" {
  principal          = var.central_aws_account
  resource_share_arn = aws_ram_resource_share.resource_share.arn
}

# Resource Association - VPC Lattice service
resource "aws_ram_resource_association" "lattice_service_share" {
  for_each = module.vpc_lattice_service.services

  resource_arn       = each.value.attributes.arn
  resource_share_arn = aws_ram_resource_share.resource_share.arn
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Central Account – VPC Lattice service network&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# VPC Lattice Module
module "vpclattice_service_network" {
  source  = "aws-ia/amazon-vpc-lattice-module/aws"
  version = "0.0.2"

  service_network = {
    name        = "centralized-service-network"
    auth_type   = "AWS_IAM"
    auth_policy = local.auth_policy
  }

  services = { for k, v in var.lattice_services: k =&amp;gt; { identifier = v } }

  depends_on = [aws_ram_resource_share_accepter.share_accepter]
}

# VPC Lattice service network Auth Policy
locals {
  auth_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action    = "*"
        Effect    = "Allow"
        Principal = "*"
        Resource  = "*"
      }
    ]
  })
}

# Accepting VPC Lattice services from Service AWS Account
resource "aws_ram_resource_share_accepter" "share_accepter" {
  share_arn = local.lattice_services.ram_share
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Resource Share *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Resource Share
resource "aws_ram_resource_share" "resource_share" {
  name                      = "Amazon VPC Lattice service network"
  allow_external_principals = true
}

# Principal Association
resource "aws_ram_principal_association" "principal_association" {
  principal          = var.consumer_aws_account
  resource_share_arn = aws_ram_resource_share.resource_share.arn
}

# Resource Association - VPC Lattice service network
resource "aws_ram_resource_association" "lattice_service_network_share" {
  resource_arn       = module.vpclattice_service_network.service_network.arn
  resource_share_arn = aws_ram_resource_share.resource_share.arn
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Consumer Account – VPC Lattice VPC association&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module "vpc_lattice_vpc_association" {
  source  = "aws-ia/amazon-vpc-lattice-module/aws"
  version = "0.0.2"

  service_network = { identifier = var.service_network }

  vpc_associations = {
    vpc1 = {
      vpc_id             = module.vpc1.vpc_attributes.id
      security_group_ids = [aws_security_group.vpc1_lattice_sg.id]
    }
  }

  depends_on = [
    aws_ram_resource_share_accepter.share_accepter
  ]
}

module "vpc1" {
  source  = "aws-ia/vpc/aws"
  version = "4.3.0"

  name       = "vpc1"
  cidr_block = "10.0.0.0/24"
  az_count   = 2

  subnets = {
    workload  = { netmask = 28 }
    endpoints = { netmask = 28 }
  }
}

resource "aws_security_group" "vpc1_lattice_sg" {
  name        = "lattice-sg-vpc1"
  description = "VPC Lattice SG - VPC1"
  vpc_id      = module.vpc1.vpc_attributes.id

  ingress {
    description = "HTTPS access"
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = ["10.0.0.0/24"] 
  }

  egress {
    description = "Any traffic"
    from_port   = 0
    to_port     = 0
    protocol    = egress.value.protocol
    cidr_blocks = egress.value.cidr_blocks
  }
}

# Accepting VPC Lattice service network from Central AWS Account
resource "aws_ram_resource_share_accepter" "share_accepter" {
  share_arn = local.service_network.ram_share
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;VPC Module&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module "vpc2" {
  source  = "aws-ia/vpc/aws"
  version = "4.3.0"

  name       = "vpc2"
  cidr_block = "10.0.0.0/24"
  az_count   = 2

  vpc_lattice = {
    service_network_identifier = var.service_network_id
    security_group_ids         = [aws_security_group.vpc2_lattice_sg.id]
  }

  subnets = {
    workload  = { netmask = 28 }
    endpoints = { netmask = 28 }
  }

  depends_on = [
    aws_ram_resource_share_accepter.share_accepter
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>aws</category>
      <category>network</category>
      <category>terraform</category>
      <category>vpc</category>
    </item>
    <item>
      <title>How to run Llama model locally on MacBook Pro and Function calling in LLM -Llama web search agent breakdown</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Wed, 03 Jul 2024 12:36:13 +0000</pubDate>
      <link>https://dev.to/selvapal/how-to-run-llama-model-locally-on-macbook-pro-and-function-calling-in-llm-llama-web-search-agent-breakdown-12dl</link>
      <guid>https://dev.to/selvapal/how-to-run-llama-model-locally-on-macbook-pro-and-function-calling-in-llm-llama-web-search-agent-breakdown-12dl</guid>
      <description>&lt;p&gt;Easily install Open source Large Language Models (LLM) locally on your Mac with Ollama.On a basic M1 Pro Macbook with 16GB memory, this configuration takes approximately 10 to 15 minutes to get going. The model itself starts up in less than ten seconds after the setup is finished.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &amp;gt;&amp;gt; &lt;a href="https://ollama.com/download/mac" rel="noopener noreferrer"&gt;https://ollama.com/download/mac&lt;/a&gt; and download the software for your OS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fqdae5p6r6lgelusbmrhw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fqdae5p6r6lgelusbmrhw.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Open the Ollama application and Move to Applications&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fvvqnbrc9qwechygqivfu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fvvqnbrc9qwechygqivfu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ollama run llama3


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

&lt;/div&gt;

&lt;p&gt;Depending on your network speed, the download and build take ten to fifteen minutes to finish.It is operating properly if the browser displays "Ollama is running" after accessing &lt;a href="http://localhost:11434" rel="noopener noreferrer"&gt;http://localhost:11434&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


(venv) admin@admins-MacBook-Pro selvapal % ollama run llama3
&amp;gt;&amp;gt;&amp;gt; list the climate chnage reasons 
Here are some of the main reasons contributing to climate change:

1. **Greenhouse gases**: The burning of fossil fuels such as coal, oil, and gas releases carbon dioxide (CO2), methane (CH4), and other greenhouse gases into the atmosphere, trapping heat 
and leading to global warming.
2. **Deforestation**: The clearance of forests for agriculture, urbanization, and logging reduces the ability of trees to absorb CO2, a key greenhouse gas, contributing to climate change.
3. **Land use changes**: Changes in land use, such as the conversion of natural habitats into agricultural lands or cities, can lead to increased emissions of greenhouse gases and loss of 
carbon sequestration capabilities.
4. **Agriculture**: The production of meat, especially beef, and other animal products leads to increased methane emissions and deforestation for livestock grazing and feed crop 
production.
5. **Industrial processes**: Industrial activities such as cement production, steel manufacturing, and chemical processing release large amounts of greenhouse gases into the atmosphere.
6. **Population growth**: As the global population grows, so does the demand for energy, food, and resources, leading to increased emissions and consumption.
7. **Consumption patterns**: The way we live our daily lives, including transportation, diet, and consumer choices, contributes to climate change through energy use, waste generation, and 
resource depletion.
8. **Waste management**: Inadequate waste management practices, such as the disposal of plastic waste in landfills or oceans, can lead to methane emissions and contribute to climate 
change.
9. **Fugitive emissions**: The extraction, processing, and transportation of fossil fuels can release large amounts of greenhouse gases into the atmosphere, often unnoticed or unreported.
10. **Aerosol emissions**: The burning of biomass, such as wood or agricultural waste, releases aerosols that can trap heat and contribute to climate change.
11. **Nitrous oxide (N2O) emissions**: Agricultural practices, such as fertilizer use and manure management, release N2O, a potent greenhouse gas.
12. **Chlorofluorocarbons (CFCs)**: The use of CFC-containing products, such as refrigerants and propellants, can lead to the destruction of stratospheric ozone and contribute to climate 
change.
13. **Methane emissions from natural sources**: Natural sources, such as wetlands, rice paddies, and termites, release methane into the atmosphere, which contributes to climate change.
14. **Ocean fertilization**: The addition of nutrients to the ocean to stimulate phytoplankton growth can lead to increased CO2 absorption but also releases other greenhouse gases and 
alters marine ecosystems.
15. **Geoengineering**: Large-scale engineering projects aimed at mitigating climate change, such as solar radiation management or carbon capture and storage, can have unintended 
consequences and potentially exacerbate climate change.

These are some of the main reasons contributing to climate change. It's essential to understand these factors to develop effective strategies for reducing greenhouse gas emissions and 
mitigating the impacts of climate change.

&amp;gt;&amp;gt;&amp;gt; Send a message (/? for help)


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Benchmark Llama3 performance&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

admin@admins-MacBook-Pro ~ % git clone https://github.com/selvakumarsai/llm-benchmark.git
Cloning into 'llm-benchmark'...
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 28 (delta 12), reused 6 (delta 1), pack-reused 0
Receiving objects: 100% (28/28), 16.26 KiB | 555.00 KiB/s, done.
Resolving deltas: 100% (12/12), done.
admin@admins-MacBook-Pro ~ % cd llm-benchmark
admin@admins-MacBook-Pro llm-benchmark % pip install -r requirements.txt
Defaulting to user installation because normal site-packages is not writeable
Collecting ollama (from -r requirements.txt (line 1))
  Downloading ollama-0.2.1-py3-none-any.whl.metadata (4.2 kB)
Requirement already satisfied: pydantic in /Users/admin/Library/Python/3.9/lib/python/site-packages (from -r requirements.txt (line 2)) (2.8.0)
Requirement already satisfied: httpx&amp;lt;0.28.0,&amp;gt;=0.27.0 in /Users/admin/Library/Python/3.9/lib/python/site-packages (from ollama-&amp;gt;-r requirements.txt (line 1)) (0.27.0)
Requirement already satisfied: annotated-types&amp;gt;=0.4.0 in /Users/admin/Library/Python/3.9/lib/python/site-packages (from pydantic-&amp;gt;-r requirements.txt (line 2)) (0.7.0)
Requirement already satisfied: pydantic-core==2.20.0 in /Users/admin/Library/Python/3.9/lib/python/site-packages (from pydantic-&amp;gt;-r requirements.txt (line 2)) (2.20.0)
Requirement already satisfied: typing-extensions&amp;gt;=4.6.1 in /Users/admin/Library/Python/3.9/lib/python/site-packages (from pydantic-&amp;gt;-r requirements.txt (line 2)) (4.6.2)
Requirement already satisfied: anyio in /Users/admin/Library/Python/3.9/lib/python/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama-&amp;gt;-r requirements.txt (line 1)) (4.4.0)
Requirement already satisfied: certifi in /Users/admin/Library/Python/3.9/lib/python/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama-&amp;gt;-r requirements.txt (line 1)) (2023.5.7)
Requirement already satisfied: httpcore==1.* in /Users/admin/Library/Python/3.9/lib/python/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama-&amp;gt;-r requirements.txt (line 1)) (1.0.5)
Requirement already satisfied: idna in /Users/admin/Library/Python/3.9/lib/python/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama-&amp;gt;-r requirements.txt (line 1)) (3.4)
Requirement already satisfied: sniffio in /Users/admin/Library/Python/3.9/lib/python/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama-&amp;gt;-r requirements.txt (line 1)) (1.3.1)
Requirement already satisfied: h11&amp;lt;0.15,&amp;gt;=0.13 in /Users/admin/Library/Python/3.9/lib/python/site-packages (from httpcore==1.*-&amp;gt;httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama-&amp;gt;-r requirements.txt (line 1)) (0.14.0)
Requirement already satisfied: exceptiongroup&amp;gt;=1.0.2 in /Users/admin/Library/Python/3.9/lib/python/site-packages (from anyio-&amp;gt;httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama-&amp;gt;-r requirements.txt (line 1)) (1.2.1)
Downloading ollama-0.2.1-py3-none-any.whl (9.7 kB)
Installing collected packages: ollama
Successfully installed ollama-0.2.1

admin@admins-MacBook-Pro llm-benchmark % python3.10 -m pip install ollama                                        
Collecting ollama
  Using cached ollama-0.2.1-py3-none-any.whl.metadata (4.2 kB)
Requirement already satisfied: httpx&amp;lt;0.28.0,&amp;gt;=0.27.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from ollama) (0.27.0)
Requirement already satisfied: anyio in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama) (4.4.0)
Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama) (2024.6.2)
Requirement already satisfied: httpcore==1.* in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama) (1.0.5)
Requirement already satisfied: idna in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama) (3.7)
Requirement already satisfied: sniffio in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama) (1.3.1)
Requirement already satisfied: h11&amp;lt;0.15,&amp;gt;=0.13 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from httpcore==1.*-&amp;gt;httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama) (0.14.0)
Requirement already satisfied: exceptiongroup&amp;gt;=1.0.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from anyio-&amp;gt;httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama) (1.2.1)
Requirement already satisfied: typing-extensions&amp;gt;=4.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from anyio-&amp;gt;httpx&amp;lt;0.28.0,&amp;gt;=0.27.0-&amp;gt;ollama) (4.12.2)
Using cached ollama-0.2.1-py3-none-any.whl (9.7 kB)
Installing collected packages: ollama
Successfully installed ollama-0.2.1

admin@admins-MacBook-Pro llm-benchmark % python3.10 benchmark.py --verbose --prompts "how to do organic farming"

Verbose: True
Skip models: []
Prompts: ['how to do organic farming']
Evaluating models: ['llama3:latest', 'gemma:latest']



Benchmarking: llama3:latest
Prompt: how to do organic farming
Organic farming is a type of agriculture that avoids the use of synthetic fertilizers, pesticides, and genetically modified organisms (GMOs). Instead, organic farmers rely on natural methods to control pests and diseases, and use compost and other natural amendments to improve soil fertility. Here are some key principles and practices of organic farming:

1. **Soil conservation**: Organic farmers focus on building healthy soil through the use of crop rotations, cover crops, and organic amendments like compost.
2. **Crop rotation**: Rotating crops helps to break disease cycles, improves soil structure, and increases biodiversity.
3. **Composting**: Composting is a key process in organic farming that turns waste into nutrient-rich fertilizer.
4. **Manure management**: Organic farmers use animal manure as a natural fertilizer and to improve soil health.
5. **Integrated pest management (IPM)**: Instead of relying on pesticides, organic farmers use IPM techniques like crop rotation, biological control, and cultural controls to manage pests.
6. **Cover cropping**: Planting cover crops in the off-season helps to prevent erosion, adds nutrients to the soil, and provides habitat for beneficial insects.
7. **Biodiversity conservation**: Organic farming aims to conserve biodiversity by promoting ecosystem services and supporting beneficial insects and microorganisms.
8. **Minimum tillage or no-till**: Reducing soil disturbance helps to preserve soil structure, reduce erosion, and promote soil biota.
9. **Organic amendments**: Using natural amendments like compost, manure, or green manure instead of synthetic fertilizers.
10. **Record keeping**: Organic farmers keep detailed records of their farming practices, including crop rotations, pest management, and soil health.

Some specific techniques used in organic farming include:

1. **Biodynamic agriculture**: A holistic approach that considers the moon's cycles and uses natural preparations to promote soil fertility and plant growth.
2. **Permaculture**: A design system that aims to create self-sustaining ecosystems by mimicking nature's patterns and relationships.
3. **Agroforestry**: Integrating trees into agricultural landscapes to improve soil health, reduce erosion, and increase biodiversity.
4. **Green manure**: Planting legumes or other cover crops to fix nitrogen in the soil and add organic matter.
5. **Crop rotation with legumes**: Incorporating legume crops like beans or peas into crop rotations to improve soil fertility.

To get started with organic farming, you can:

1. **Research local regulations**: Familiarize yourself with national and regional laws regarding organic farming practices and certifications.
2. **Start small**: Begin by converting a small portion of your land to organic methods and gradually scale up as you gain experience.
3. **Join an organic farm network**: Connect with other organic farmers, attend workshops, and share knowledge to learn from their experiences.
4. **Develop a business plan**: Create a plan for marketing and selling your organic products, including pricing and target markets.
5. **Monitor and adjust**: Continuously monitor your soil health, crop yields, and pest management strategies, and make adjustments as needed.

Remember that transitioning to organic farming takes time, patience, and dedication. Start by making small changes and gradually build up your knowledge and skills.Response: 

----------------------------------------------------
        llama3:latest
            Prompt eval: 13.14 t/s
            Response: 6.23 t/s
            Total: 6.31 t/s

        Stats:
            Prompt tokens: 16
            Response tokens: 654
            Model load time: 2.06s
            Prompt eval time: 1.22s
            Response time: 105.04s
            Total time: 108.32s
----------------------------------------------------



Benchmarking: gemma:latest
Prompt: how to do organic farming


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Function Calling - Llama web search agent breakdown&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Larger models like GPT4, Claude anthorpics are fine tune to be able to perform function calling and can attach tools like online search and decide they need to use the tools or not and execute the tools. &lt;/p&gt;

&lt;p&gt;Smaller models like Olama need  precise definition and routing. &lt;/p&gt;

&lt;p&gt;Langchain enables you to define conditional routing techniques to create a directed graph flows in the form of a state machine. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fbqihccyysqw9runqs7d3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fbqihccyysqw9runqs7d3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The web research agent first goes through a routing step where it looks at the user's query and determines whether or not we need context. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is the first llm call. If it determines that context is not needed, it  goes to the generation step where it generates its final output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If it determines that context is needed, it goes to a transform query state where it takes the user's initial question and optimises it for a web search. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The optimised search query then goes into the web search step , and all of the context from the web search step  used to generate the final report. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First load the longchain dependencies &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Displaying final output format
from IPython.display import display, Markdown, Latex
# LangChain Dependencies
from langchain.prompts import PromptTemplate
from langchain_core.output_parsers import JsonOutputParser, StrOutputParser
from langchain_community.chat_models import ChatOllama
from langchain_community.tools import DuckDuckGoSearchRun
from langchain_community.utilities import DuckDuckGoSearchAPIWrapper
from langgraph.graph import END, StateGraph
# For State Graph 
from typing_extensions import TypedDict
import os


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

&lt;/div&gt;

&lt;p&gt;Setup the environment variables &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Environment Variables
#os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "xxxxxxxxxxxxxxxxxx" 
os.environ["LANGCHAIN_PROJECT"] = "L3 Research Agent"


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

&lt;/div&gt;

&lt;p&gt;Next define the LLM&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Defining LLM
local_llm = 'llama3'
llama3 = ChatOllama(model=local_llm, temperature=0)
llama3_json = ChatOllama(model=local_llm, format='json', temperature=0)


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

&lt;/div&gt;

&lt;p&gt;Install websearch api &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

pip install -U duckduckgo-search


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Web Search Tool

wrapper = DuckDuckGoSearchAPIWrapper(max_results=25)
web_search_tool = DuckDuckGoSearchRun(api_wrapper=wrapper)


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

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.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%2F7veqh1x7di15o8wvt01i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F7veqh1x7di15o8wvt01i.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create the different prompts first for  function call routing and to define nodes &lt;/p&gt;

&lt;p&gt;First Generate report Prompt &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Generation Prompt

generate_prompt = PromptTemplate(
    template="""

    &amp;lt;|begin_of_text|&amp;gt;

    &amp;lt;|start_header_id|&amp;gt;system&amp;lt;|end_header_id|&amp;gt; 

    You are an AI assistant for Research Question Tasks, that synthesizes web search results. 
    Strictly use the following pieces of web search context to answer the question. If you don't know the answer, just say that you don't know. 
    keep the answer concise, but provide all of the details you can in the form of a research report. 
    Only make direct references to material if provided in the context.

    &amp;lt;|eot_id|&amp;gt;

    &amp;lt;|start_header_id|&amp;gt;user&amp;lt;|end_header_id|&amp;gt;

    Question: {question} 
    Web Search Context: {context} 
    Answer: 

    &amp;lt;|eot_id|&amp;gt;

    &amp;lt;|start_header_id|&amp;gt;assistant&amp;lt;|end_header_id|&amp;gt;""",
    input_variables=["question", "context"],
)

# Chain
generate_chain = generate_prompt | llama3 | StrOutputParser()


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

&lt;/div&gt;

&lt;p&gt;Second define Router prompt &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Router

router_prompt = PromptTemplate(
    template="""

    &amp;lt;|begin_of_text|&amp;gt;

    &amp;lt;|start_header_id|&amp;gt;system&amp;lt;|end_header_id|&amp;gt;

    You are an expert at routing a user question to either the generation stage or web search. 
    Use the web search for questions that require more context for a better answer, or recent events.
    Otherwise, you can skip and go straight to the generation phase to respond.
    You do not need to be stringent with the keywords in the question related to these topics.
    Give a binary choice 'web_search' or 'generate' based on the question. 
    Return the JSON with a single key 'choice' with no premable or explanation. 

    Question to route: {question} 

    &amp;lt;|eot_id|&amp;gt;

    &amp;lt;|start_header_id|&amp;gt;assistant&amp;lt;|end_header_id|&amp;gt;

    """,
    input_variables=["question"],
)

# Chain
question_router = router_prompt | llama3_json | JsonOutputParser()

# Test Run
question = "What's up?"
print(question_router.invoke({"question": question}))


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

&lt;/div&gt;

&lt;p&gt;{'choice': 'generate'}&lt;/p&gt;

&lt;p&gt;Third, Define Query transformation prompt to transform the user query to optimised query for websearch state  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Query Transformation

query_prompt = PromptTemplate(
    template="""

    &amp;lt;|begin_of_text|&amp;gt;

    &amp;lt;|start_header_id|&amp;gt;system&amp;lt;|end_header_id|&amp;gt; 

    You are an expert at crafting web search queries for research questions.
    More often than not, a user will ask a basic question that they wish to learn more about, however it might not be in the best format. 
    Reword their query to be the most effective web search string possible.
    Return the JSON with a single key 'query' with no premable or explanation. 

    Question to transform: {question} 

    &amp;lt;|eot_id|&amp;gt;

    &amp;lt;|start_header_id|&amp;gt;assistant&amp;lt;|end_header_id|&amp;gt;

    """,
    input_variables=["question"],
)

# Chain
query_chain = query_prompt | llama3_json | JsonOutputParser()

# Test Run
question = "What's happened recently with Tesla?"
print(query_chain.invoke({"question": question}))


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

&lt;/div&gt;

&lt;p&gt;{'query': 'Tesla recent news'}&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Define the Graph state and Nodes for the conditional routing *&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Graph State
class GraphState(TypedDict):
    """
    Represents the state of our graph.

    Attributes:
        question: question
        generation: LLM generation
        search_query: revised question for web search
        context: web_search result
    """
    question : str
    generation : str
    search_query : str
    context : str

# Node - Generate

def generate(state):
    """
    Generate answer

    Args:
        state (dict): The current graph state

    Returns:
        state (dict): New key added to state, generation, that contains LLM generation
    """

    print("Step: Generating Final Response")
    question = state["question"]
    context = state["context"]

    # Answer Generation
    generation = generate_chain.invoke({"context": context, "question": question})
    return {"generation": generation}

# Node - Query Transformation

def transform_query(state):
    """
    Transform user question to web search

    Args:
        state (dict): The current graph state

    Returns:
        state (dict): Appended search query
    """

    print("Step: Optimizing Query for Web Search")
    question = state['question']
    gen_query = query_chain.invoke({"question": question})
    search_query = gen_query["query"]
    return {"search_query": search_query}


# Node - Web Search

def web_search(state):
    """
    Web search based on the question

    Args:
        state (dict): The current graph state

    Returns:
        state (dict): Appended web results to context
    """

    search_query = state['search_query']
    print(f'Step: Searching the Web for: "{search_query}"')

    # Web search tool call
    search_result = web_search_tool.invoke(search_query)
    return {"context": search_result}


# Conditional Edge, Routing

def route_question(state):
    """
    route question to web search or generation.

    Args:
        state (dict): The current graph state

    Returns:
        str: Next node to call
    """

    print("Step: Routing Query")
    question = state['question']
    output = question_router.invoke({"question": question})
    if output['choice'] == "web_search":
        print("Step: Routing Query to Web Search")
        return "websearch"
    elif output['choice'] == 'generate':
        print("Step: Routing Query to Generation")
        return "generate"


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

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Define and compile workflow *&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Build the nodes
workflow = StateGraph(GraphState)
workflow.add_node("websearch", web_search)
workflow.add_node("transform_query", transform_query)
workflow.add_node("generate", generate)

# Build the edges
workflow.set_conditional_entry_point(
    route_question,
    {
        "websearch": "transform_query",
        "generate": "generate",
    },
)
workflow.add_edge("transform_query", "websearch")
workflow.add_edge("websearch", "generate")
workflow.add_edge("generate", END)

# Compile the workflow
local_agent = workflow.compile()


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

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Finally define the agent to run the query *&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

def run_agent(query):
    output = local_agent.invoke({"question": query})
    print("=======")
    display(Markdown(output["generation"]))


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

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Test the different flows *&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# Test it out!
run_agent("What's been up with Tesla recently?")



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

&lt;/div&gt;

&lt;p&gt;Step: Routing Query&lt;br&gt;
Step: Routing Query to Web Search&lt;br&gt;
Step: Optimizing Query for Web Search&lt;br&gt;
Step: Searching the Web for: "Tesla recent news"&lt;br&gt;
Step: Generating Final Response&lt;/p&gt;

&lt;p&gt;Based on the provided web search context, here's what's been up with Tesla recently:&lt;/p&gt;

&lt;p&gt;Tesla is reportedly preparing to build a $25,000 electric car built on its next-generation engineering platform.&lt;br&gt;
Elon Musk has announced that Tesla will launch new EVs in 2025, including affordable ones, which will blend current and next-generation platforms.&lt;br&gt;
The company has set a goal to start production of a new mass-market electric vehicle codenamed "Redwood" in mid-2025.&lt;br&gt;
Tesla has produced its 20 millionth 4680 cell at Gigafactory Texas, a key step for its new vehicle programs. The 4680 cell is designed to reduce battery cost by over 50% and has a capacity of about 100 Wh.&lt;br&gt;
Tesla reported first-quarter adjusted earnings per share of $0.45, below the estimated $0.52, on revenue of $21.30 billion, which missed forecasts for $22.3 billion.&lt;br&gt;
The company set a new delivery record for the fourth quarter and met its 2023 delivery target, shaking off a third-quarter miss and assuaging investors concerned with any hiccups as it prepares to launch new products.&lt;br&gt;
Tesla has issued two recalls on the Cybertruck, its third and fourth since the model was introduced late last year. The latest recall affects almost all of the nearly 12,000 trucks on the road.&lt;br&gt;
The company is currently testing approximately 35 trucks for its long-range Semi, which will have a range of up to 500 miles.&lt;br&gt;
Tesla's stock rose as much as 4.5% on Tuesday after the company delivered a record number of vehicles in the three months to the end of June.&lt;br&gt;
Overall, it seems that Tesla is preparing to launch new products and expand its offerings, including affordable electric cars and long-range Semi trucks. The company has also faced some challenges, including recalls and missed earnings estimates, but has managed to set new delivery records and meet its 2023 delivery target.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


# Test it out!
run_agent("How are you doing today?")



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

&lt;/div&gt;

&lt;p&gt;Step: Routing Query&lt;br&gt;
Step: Routing Query to Generation&lt;br&gt;
Step: Generating Final Response&lt;/p&gt;

&lt;p&gt;I'm just an AI, I don't have feelings or emotions like humans do. I am functioning properly and ready to assist with any research questions you may have. I don't have personal experiences or opinions, so I won't be able to provide a subjective assessment of my "mood" or "well-being."&lt;/p&gt;

&lt;p&gt;Ref : &lt;a href="https://www.youtube.com/watch?v=-lnR9oU0Jl8&amp;amp;t=0s" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=-lnR9oU0Jl8&amp;amp;t=0s&lt;/a&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>genai</category>
      <category>langchain</category>
      <category>functioncalling</category>
    </item>
    <item>
      <title>IaC Security Scanner - Generative AI app with PartyRock</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Thu, 29 Feb 2024 09:52:08 +0000</pubDate>
      <link>https://dev.to/selvapal/iac-security-scanner-generative-ai-app-with-partyrock-ibl</link>
      <guid>https://dev.to/selvapal/iac-security-scanner-generative-ai-app-with-partyrock-ibl</guid>
      <description>&lt;p&gt;Infrastructure-as-code (IaC) release security is growing in importance because to the speed at which the digital world is developing. By meeting this important requirement, the AI-Powered IaC Security Scanner indicates a substantial advancement in the field of IaC security.&lt;/p&gt;

&lt;p&gt;The IaC Security Scanner with AI Powered is not a simple tool to use. It has native support for numerous IaC systems, such as Kubernetes, Terraform, and AWS CloudFormation. As a result, your IaC installations are safe across all platforms and support a wide range of compatibilities.&lt;/p&gt;

&lt;p&gt;Key Features of AI-Powered IaC Security Scanner&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In-Depth Vulnerability Assessment&lt;/li&gt;
&lt;li&gt;Compliance with Industry Standards&lt;/li&gt;
&lt;li&gt;User-Friendly Interface&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All you need to do is visit the Party Rock Website to sign up, and the magic happens in mere seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step #1 : Sign In&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Step #2 : Write your Prompt with your Idea&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Generated App&lt;/p&gt;

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

&lt;p&gt;Test the app with sample Terraform code&lt;/p&gt;

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

&lt;p&gt;Published App : &lt;a href="https://partyrock.aws/u/selvapal/UI-aMM_I3/IaC-Security-Scan-App"&gt;https://partyrock.aws/u/selvapal/UI-aMM_I3/IaC-Security-Scan-App&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sample code used for testing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_cloudwatch_log_group" "cloudwatch_log_group" {
  name = "msk_cluster_cloudwatch_group-${random_uuid.randuuid.result}"
}

resource "aws_msk_configuration" "msk_cluster_config" {
  kafka_versions = [var.msk_cluster_version]
  name           = "msk-${lower(var.environment)}-cluster-cfg-${random_uuid.randuuid.result}"
  server_properties = &amp;lt;&amp;lt;PROPERTIES
auto.create.topics.enable = true
delete.topic.enable = true
PROPERTIES
}

resource "aws_msk_cluster" "msk_cluster" {
  count                  = length(var.private_subnet_cidrs)
  cluster_name           = "msk-${lower(var.environment)}-cluster-${random_uuid.randuuid.result}"
  kafka_version          = var.msk_cluster_version
  number_of_broker_nodes = var.broker_nodes

  broker_node_group_info {
    instance_type   = var.msk_cluster_instance_type
    ebs_volume_size = var.msk_ebs_volume_size
    client_subnets = [
      "${aws_subnet.private_subnet.0.id}",
      "${aws_subnet.private_subnet.1.id}",
      "${aws_subnet.private_subnet.2.id}"
    ]
    security_groups = [aws_security_group.KafkaClusterSG.id]
  }

  /*
  client_authentication {
    tls {
      certificate_authority_arns = [aws_acmpca_certificate_authority.pca.arn]
    }
  }
*/

configuration_info {
  arn = aws_msk_configuration.msk_cluster_config.arn
  revision = 1
}
  encryption_info {
    encryption_in_transit {
      client_broker = var.encryption_type
    }
  }

  enhanced_monitoring = var.monitoring_type

  logging_info {
    broker_logs {
      cloudwatch_logs {
        enabled   = true
        log_group = aws_cloudwatch_log_group.cloudwatch_log_group.name
      }
    }
  }

  tags = merge(
    local.common-tags,
    map(
      "Name", "msk-${lower(var.environment)}-cluster"
    )
  )
}

output "zookeeper_connect_string" {
  value = aws_msk_cluster.msk_cluster.*.zookeeper_connect_string
}

output "bootstrap_brokers" {
  description = "Plaintext connection host:port pairs"
  value       = aws_msk_cluster.msk_cluster.*.bootstrap_brokers
}

output "bootstrap_brokers_tls" {
  description = "TLS connection host:port pairs"
  value       = aws_msk_cluster.msk_cluster.*.bootstrap_brokers_tls
}

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

&lt;/div&gt;



</description>
      <category>aws</category>
      <category>ai</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Chat with your SQL database</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Mon, 26 Feb 2024 08:20:18 +0000</pubDate>
      <link>https://dev.to/selvapal/chat-with-your-sql-database-kej</link>
      <guid>https://dev.to/selvapal/chat-with-your-sql-database-kej</guid>
      <description>&lt;p&gt;Creating complex SQL queries can be difficult when managing databases. Especially for people who are not SQL professionals, this might be challenging. It is obvious that there is a need for an approachable solution that makes creating SQL queries easier.&lt;/p&gt;

&lt;p&gt;Existing techniques for creating SQL queries can be time-consuming and frequently necessitate a thorough grasp of the underlying database structure. Certain tools could be useful for creating queries, but they might require additional customisation to fit different databases or ensure security and privacy.&lt;/p&gt;

&lt;p&gt;A helpful open-source Python framework called Vanna AI takes a two-step approach to simplifying SQL generation. First, it trains a Retrieval-Augmented Generation (RAG) model on your data, and then it asks questions to generate SQL queries that are specific to your database.&lt;/p&gt;

&lt;p&gt;Vanna provides a simple and flexible solution to the prevalent problem of SQL query generating. Vanna makes database querying easier to use and more accessible for everyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Vanna Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vanna is a Python module that helps you create precise SQL queries for your database by leveraging LLMs through retrieval augmentation.&lt;/p&gt;

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

&lt;p&gt;Vanna works in two easy steps - train a RAG "model" on your data, and then ask questions which will return SQL queries that can be set up to automatically run on your database.&lt;br&gt;
vn.train(...)&lt;/p&gt;

&lt;p&gt;Train a RAG "model" on your data. These methods add to the reference corpus below.&lt;br&gt;
vn.ask(...)&lt;/p&gt;

&lt;p&gt;Ask questions. This will use the reference corpus to generate SQL queries that can be run on your database.&lt;br&gt;
&lt;strong&gt;Install and Import Vanna&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%pip install vanna
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Requirement already satisfied: MarkupSafe&amp;gt;=2.0 in /usr/local/lib/python3.10/dist-packages (from Jinja2&amp;gt;=3.0-&amp;gt;flask-&amp;gt;vanna) (2.1.5)&lt;br&gt;
Requirement already satisfied: six&amp;gt;=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil&amp;gt;=2.8.1-&amp;gt;pandas-&amp;gt;vanna) (1.16.0)&lt;br&gt;
Installing collected packages: kaleido, vanna&lt;br&gt;
Successfully installed kaleido-0.2.1 vanna-0.1.1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import vanna
from vanna.remote import VannaDefault
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Log In to Vanna&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vanna provides a function to get an API key. You'll get a code sent to your e-mail. You can save your API key for future usage so that you don't have to log in every time.&lt;/p&gt;

&lt;p&gt;api_key = vanna.get_api_key('&lt;a href="mailto:xxxxxyyyy@gmail.com"&gt;xxxxxyyyy@gmail.com&lt;/a&gt;')&lt;/p&gt;

&lt;p&gt;Check your email for the code and enter it here:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Set Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;chinook is a public model that refers to the Chinook sample database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vanna_model_name = 'chinook' # This is the name of the RAG model. This is typically associated with a specific dataset.
vn = VannaDefault(model=vanna_model_name, api_key=api_key)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Connect to the Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here we're connecting to a SQLite database but you can connect to any SQL database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vn.connect_to_sqlite('https://vanna.ai/Chinook.sqlite')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Ask Questions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we're going to use vn.ask to ask questions and it'll generate SQL, run the SQL, show the table, and generate a chart&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vn.ask("What are the top 5 artists by sales?")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SELECT a.ArtistId, a.Name, SUM(il.Quantity) AS TotalSales&lt;br&gt;
FROM Artist a&lt;br&gt;
JOIN Album al ON a.ArtistId = al.ArtistId&lt;br&gt;
JOIN Track t ON al.AlbumId = t.AlbumId&lt;br&gt;
JOIN InvoiceLine il ON t.TrackId = il.TrackId&lt;br&gt;
GROUP BY a.ArtistId, a.Name&lt;br&gt;
ORDER BY TotalSales DESC&lt;br&gt;
LIMIT 5;&lt;br&gt;
   ArtistId                     Name  TotalSales&lt;br&gt;
0        90              Iron Maiden         140&lt;br&gt;
1       150                       U2         107&lt;br&gt;
2        50                Metallica          91&lt;br&gt;
3        22             Led Zeppelin          87&lt;br&gt;
4       113  Os Paralamas Do Sucesso          45&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Launch the User Interface&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from vanna.flask import VannaFlaskApp
app = VannaFlaskApp(vn)
app.run()

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

&lt;/div&gt;



&lt;p&gt;How to connect to Athena and redshift &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Athena *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
from pyathena import connect

conn_details = {...}  # fill this with your connection details
conn_athena = connect(**conn_details)

def run_sql_athena(sql: str) -&amp;gt; pd.DataFrame:
    df = pd.read_sql(sql, conn_athena)
    return df

vn.run_sql = run_sql_athena
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Redshift&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
import psycopg2

conn_details = {...}  # fill this with your connection details
conn_redshift = psycopg2.connect(**conn_details)

def run_sql_redshift(sql: str) -&amp;gt; pd.DataFrame:
    df = pd.read_sql_query(sql, conn_redshift)
    return df

vn.run_sql = run_sql_redshift
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Most of Vanna’s functionality does not need your specific data, but does need your schema (eg SQL queries and structure — table names, column names)&lt;/p&gt;

&lt;p&gt;It’s completely open source and free, and works with Snowflake, Postgres, Redshift, and most other databases. &lt;/p&gt;

&lt;p&gt;Reference :  vanna.ai.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>chatgpt</category>
      <category>database</category>
    </item>
    <item>
      <title>Generative AI - Large Language Models</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Tue, 28 Nov 2023 12:11:59 +0000</pubDate>
      <link>https://dev.to/selvapal/generative-ai-large-language-models-da8</link>
      <guid>https://dev.to/selvapal/generative-ai-large-language-models-da8</guid>
      <description>&lt;p&gt;&lt;strong&gt;What are Large Language Models (LLMs)?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Large Language Models (LLMs) from OpenAI, such as GPT-3 and GPT-4, are machine learning algorithms that are trained on data to understand and generate human-like prose. These models are created utilising neural networks that have millions or even billions of parameters, allowing them to perform difficult tasks like translation, summarization, question answering, and even creative writing. &lt;/p&gt;

&lt;p&gt;LLMs analyse the patterns and links between words and phrases to provide coherent and contextually relevant output. They are trained on different and large datasets, which frequently include sections of the internet, novels, and other texts. Despite their ability to replicate such features in the text they write, they are not sentient and do not possess comprehension or emotions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;High performing foundation  Models&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;BERT &lt;br&gt;
GPT &lt;br&gt;
BLOOM&lt;br&gt;
FLAN-T5&lt;br&gt;
PaLM&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LLM Different use cases and tasks&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Essay Writing &lt;/li&gt;
&lt;li&gt;Summarization &lt;/li&gt;
&lt;li&gt;Translation &lt;/li&gt;
&lt;li&gt;Information Retrieval &lt;/li&gt;
&lt;li&gt;Invoke Api and actions -&amp;gt; Action call -&amp;gt; External Applications &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.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%2F3rkeuqx37ju757qsbc22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F3rkeuqx37ju757qsbc22.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Transformer Architecture
&lt;/h2&gt;

&lt;p&gt;Transformers are a type of neural network architecture that have been gaining popularity. Transformers were recently used by OpenAI in their language models&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Feqdtdo5gw5minfipccmx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Feqdtdo5gw5minfipccmx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encoder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Encodes inputs (“prompts”) with contextual understanding&lt;br&gt;
and produces one vector per input token.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decoder&lt;/strong&gt;&lt;br&gt;
Accepts input tokens and generates new tokens.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fzoxymnb65gqczub391k3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fzoxymnb65gqczub391k3.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Embedding:&lt;/strong&gt; The first step in the Transformer model is to convert the input text into numerical representations called embeddings. Each word in the input sentence is transformed into a vector of numbers that captures its meaning. These embeddings provide a way for the model to understand the input data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-Head Attention (Encoder):&lt;/strong&gt; The Encoder in the Transformer processes the input embeddings. One of its key components is the Multi-Head Attention mechanism. It’s like having multiple experts, each specializing in paying attention to different aspects of the input. The Multi-Head Attention calculates different attention scores for each word in the sentence, indicating its relevance to other words in the same sentence. This helps the model understand the context and relationships between words.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feed Forward Neural Networks (Encoder):&lt;/strong&gt; After Multi-Head Attention, the Transformer uses a Feed Forward Neural Network for additional processing. This network applies non-linear transformations to the attention outputs, introducing more complex relationships between words in the sentence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Masked Multi-Head Attention (Decoder):&lt;/strong&gt; During the decoding phase, the Transformer uses Masked Multi-Head Attention in the Decoder. The purpose of this mechanism is to prevent the model from cheating and looking ahead at future words during generation. The mask ensures that the Decoder only attends to the already generated words in the output sequence, ensuring a proper step-by-step generation of the output sentence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Softmax:&lt;/strong&gt; The Softmax function is used in two different contexts in the Transformer: Multi-Head Attention Weights: The attention scores calculated in both the Encoder and Decoder are passed through the Softmax function to convert them into a probability distribution. This distribution represents how much attention each word should receive. Output Layer: The final layer of the Transformer’s Decoder generates the output probabilities for each word in the target vocabulary. These probabilities are transformed into a valid probability distribution using the Softmax function. The word with the highest probability is selected as the model’s predicted next word.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linear Function (Output Embedding):&lt;/strong&gt; After the output probabilities are obtained through Softmax, the Transformer uses a Linear function to map these probabilities back to the same embedding dimension as the input embeddings. This step is crucial as it ensures the Decoder’s output is in the same format as the input embeddings, making it possible to pass it through additional layers of the Decoder or connect it to other parts of the model.&lt;/p&gt;

&lt;p&gt;In summary, the Transformer model employs input embeddings, multi-head attention, feed-forward neural networks in the encoder, masked multi-head attention, and softmax in the decoder, as well as linear functions for output embeddings. These components work together to enable the Transformer's extraordinary capacity to recognise and synthesise natural language sequences, making it a game-changing paradigm in natural language processing.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prompting and Engineering
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;In-context Learning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Zero-shot learning is a sort of machine learning in which the model can predict new classes without being explicitly trained on them. This is accomplished by utilising the model's knowledge of other, comparable classes to draw conclusions about the new classes.&lt;/p&gt;

&lt;p&gt;One-shot learning is a sort of machine learning in which the model predicts new classes after being trained on a single example of that class. This task is more difficult than zero-shot learning since the model need more data to work with.&lt;/p&gt;

&lt;p&gt;Few-shot learning is a sort of machine learning that is intermediate between zero-shot and one-shot learning. The model is trained on a few examples of each new class in few-shot learning. This is a more difficult challenge than one-shot learning, but it is less difficult than zero-shot learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inference Parameters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fshym3mopy2894vrxw0l7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fshym3mopy2894vrxw0l7.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Parameters are needed to manage and control the text generation process. They help in:&lt;/p&gt;

&lt;p&gt;•Controlling the length of the generated text.&lt;br&gt;
•Managing the randomness and diversity in the generated text.&lt;br&gt;
•Ensuring the relevance and coherence of the generated text.&lt;br&gt;
•Avoiding the generation of inappropriate or nonsensical text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The max_new_token option&lt;/strong&gt; restricts the number of tokens generated by the model. It aids in the regulation of the generated text's length.&lt;/p&gt;

&lt;p&gt;Controlling the length of the output is critical in real-world applications. For instance, in summarization tasks, you might want to limit the length to ensure concise summaries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Top-K Sampling&lt;/strong&gt;&lt;br&gt;
Top-k sampling involves the model selecting the next token from the top k most likely tokens.&lt;/p&gt;

&lt;p&gt;Advanced Use: Effective in activities that require a balance of diversity and relevancy, such as chatbot responses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Top-P Sampling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Top-p sampling involves the model selecting the next token from a narrower set of tokens with a cumulative probability of at least p.&lt;/p&gt;

&lt;p&gt;Advanced Use: Effective in situations when you wish to ensure a given level of probability, such as when creating text in a specific style or theme.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temperature&lt;/strong&gt;&lt;br&gt;
temperature affects the probability distribution of the next token. Higher values make the output more random, while lower values make it more deterministic.&lt;/p&gt;

&lt;p&gt;Advanced Use: Adjusting temperature can help in tasks like text-based games or simulations where varying levels of unpredictability are desired.&lt;/p&gt;
&lt;h2&gt;
  
  
  Generative AI project Life cycle
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2Flwsgwzddjwa7j4e14fjo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Flwsgwzddjwa7j4e14fjo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define the scope accurately and narrow down the use case&lt;/li&gt;
&lt;li&gt;Select model / Build a model from scratch estimate feasibility&lt;/li&gt;
&lt;li&gt;Evaluate Performance, carry out additional training if necessary In context, learning if required.&lt;/li&gt;
&lt;li&gt;Supervised learning model to finetune&lt;/li&gt;
&lt;li&gt;Fine-tune the model to align with human preferences
6.Reinforcement Learning with human feedback
7.How to align to your preferences
8.highly iterative
9.additional infrastructure requirements&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  How Large Langugae Models Trained?
&lt;/h2&gt;

&lt;p&gt;Pre-training LLM -Learns from Unstructured textural data collected from web scraping, various data sources, and corpora for training language models usually datasets in GB-TB-PBs&lt;/p&gt;

&lt;p&gt;Model weights can be updated to minimize the loss of training&lt;br&gt;
Large amount of patterns depends on architecture of model&lt;/p&gt;

&lt;p&gt;Dataset needs to increase its data quality in order to use for model training purposes to address bias, remove harmful content.&lt;/p&gt;

&lt;p&gt;Data Quality filter — 1–3 % of original tokens to decide pretraining of model&lt;/p&gt;

&lt;p&gt;During training the model weights get updated to minimise the loss of the function objective to train the model&lt;/p&gt;
&lt;h2&gt;
  
  
  Computational challenges of training LLMs
&lt;/h2&gt;

&lt;p&gt;Often training LLMs results in error message — &lt;br&gt;
“ Running out of memory — Cuda out of memory”&lt;/p&gt;

&lt;p&gt;Compute unified device architecture — collection of libraries and tools to process and perform large calculations. &lt;br&gt;
Pytorch and tensor flow use matrix multiplication and complex calculations to scale problems where it uses CUDA processors&lt;/p&gt;

&lt;p&gt;Calculating approx GPU RAM needed to store 1B parameters&lt;/p&gt;

&lt;p&gt;Computation issue explained: develop intuition of scale of parameter&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 parameter — 4 bytes (32 bit float)&lt;/li&gt;
&lt;li&gt;1B param = 4 x109 bytes — 4GB &lt;a class="mentioned-user" href="https://dev.to/32"&gt;@32&lt;/a&gt; bit full precision memory store model weights so far&lt;/li&gt;
&lt;li&gt;Additional computations requirement for the memory in calculation is required&lt;/li&gt;
&lt;li&gt;Above is calcualted to Store model weights only
•Model parameters (weights) — 4 bytes per parameter
•Adam optimiser (2 state) — +8 bytes per parameter
•Gradients — +4 bytes per parameter
•Activations &amp;amp; temp memory (variable size) needed for activation — +8 bytes per parameter(high end estimate)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Total =&amp;gt; 4 bytes per parameter == 20 extra bytes per parameter&lt;br&gt;
Memory needed to store model &amp;lt; 20 X memory ended to train the model&lt;br&gt;
Memory requirement: 4GB of model — requires 80GB of gpu ram&lt;/p&gt;
&lt;h2&gt;
  
  
  Fine tuning your model
&lt;/h2&gt;

&lt;p&gt;Data parallelism allows for the use of multiple GPUs to process different parts of the same data simultaneously, speeding up training time.&lt;/p&gt;
&lt;h2&gt;
  
  
  Parameterefficient Fine-tuning (PEFT)
&lt;/h2&gt;

&lt;p&gt;PEFT employs fine-tuning only on a small subset of the model’s parameters, while freezing most of the pre-trained network. This tactic mitigates catastrophic forgetting and significantly cuts computational and storage costs.&lt;/p&gt;

&lt;p&gt;1.Task-Guided Prompt Tuning: This technique utilizes task-specific prompts to guide the LLM’s output, obviating the need to retrain the entire model for a specific task.&lt;/p&gt;

&lt;p&gt;2.Low-Rank Adaptation (LoRA): By approximating the LLM’s parameters with a low-rank matrix, LoRA decreases the number of fine-tuned parameters, enhancing LLM performance.&lt;/p&gt;

&lt;p&gt;3.Adapters: These small, specialized layers can be added to the LLM for task adaptation, providing flexibility and performance improvement.&lt;/p&gt;

&lt;p&gt;4.Task-Relevant Prefix Tuning: Fine-tuning the LLM on representative prefixes related to the task at hand enhances performance and task adaptability.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Foip2llsd9zpl54rtfe4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Foip2llsd9zpl54rtfe4k.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Reinforcement learning from Human Feedback (RLHF)
&lt;/h2&gt;

&lt;p&gt;LLMs behave incorrectly or give undesirable responses because of the incorrect input given that might not be Helpful, Honest, or Harmless while fine-tuning the model.&lt;br&gt;
Hence additional fine-tuning with human preference will help us to extend its functionality to create a super fine-tuned model &lt;/p&gt;

&lt;p&gt;Use of fine-tuning with human feedback maximise helpfulness and relevance to human prompt that will help to minimise harm and avoid dangerous topics&lt;/p&gt;

&lt;p&gt;RLHF is an approach in artificial intelligence and machine learning that combines reinforcement learning techniques with human guidance to improve the learning process. It involves training an agent or model to make decisions and take action in an environment while receiving feedback from human experts. The input humans can be in the form of rewards, preferences, or demonstrations, which helps guide the model’s learning process. RLHF enables the agent to adapt and learn from the expertise of humans, allowing for more efficient and effective learning in complex and dynamic environments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F8pcg528d1vvb6i6wgr2g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F8pcg528d1vvb6i6wgr2g.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The RLHF Features Three Phases&lt;br&gt;
•Picking a pre-trained model as the primary model is the first step. In particular, it is important to use a pre-trained model to avoid the good amount of training data required for language models.&lt;/p&gt;

&lt;p&gt;•In the second step, a second reward model must be created. The reward model is trained with input from people who are given two or more examples of the model’s outputs and asked to score them in quality. The performance of the primary model will be assessed by the reward model using a scoring system based on this information. &lt;/p&gt;

&lt;p&gt;•The reward model receives outputs from the main model during the third phase of RLHF and then produces a quality score that indicates how well the main model performed. This input is included in the main model to improve performance on the next jobs. &lt;/p&gt;
&lt;h2&gt;
  
  
  Constitutional AI
&lt;/h2&gt;

&lt;p&gt;Constitutional AI (CAI) is similar to RLHF except instead of human feedback, it learns through AI feedback.&lt;/p&gt;

&lt;p&gt;At a high-level, there are two stages of Constitutional AI (CAI): the Reflection stage and the Reinforcement stage.&lt;/p&gt;

&lt;p&gt;CAI Stage 1: Reflection&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What we start with: Baseline model&lt;/li&gt;
&lt;li&gt;What we end with: Supervised Learning CAI (SL-CAI) model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1.Ask the LLM to generate toxic responses.&lt;/p&gt;

&lt;p&gt;2.Give the LLM a set of rules to follow (or a Constitution). Present the toxic responses back to the LLM and ask if they accord with the Constitution.&lt;/p&gt;

&lt;p&gt;3.Ask the LLM to generate a revised response. (Repeat revision until the responses follow the Constitution.)&lt;/p&gt;

&lt;p&gt;4.This creates a synthetic dataset, which you can use for training. Fine-tune (or train) the baseline model on this synthetic dataset to create responses that more closely follow the Constitution. &lt;/p&gt;

&lt;p&gt;5.Through this process, you get the SL-CAI model, the intermediate model.&lt;/p&gt;

&lt;p&gt;CAI Stage 2: Reinforcement&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What we start with: SL-CAI model&lt;/li&gt;
&lt;li&gt;What we end with: Reinforcement Learning CAI (RL-CAI) model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1.Ask the SL-CAI (from stage 1) to generate toxic responses. (Repeat multiple times for a given question.) &lt;br&gt;
2.Since each question has multiple responses, we can now create multiple choice questions.&lt;br&gt;
3.Give those multiple choice questions to the SL-CAI model and ask it to select the answer that best follows the Constitution. &lt;br&gt;
4.This creates a second synthetic dataset, which you can use to train a reward model to do reinforcement learning.&lt;br&gt;
5.Train a reward model (which is different from the baseline or SL-CAI models) on that dataset to predict which answers align best with the Constitution. This reward model becomes a teacher to the final model.&lt;br&gt;
6.Use this reward model to reinforce desired behavior and punish undesired behavior. This nudging method teaches the final model the Constitution. &lt;br&gt;
7.Through this process, you get the RL-CAI model, the final model! &lt;/p&gt;
&lt;h2&gt;
  
  
  LLM optimization Techniques
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Preliminary Assessment and Baseline Establishment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Understand the LLM’s Capabilities: Assess the general knowledge and abilities of the LLM in its base form.&lt;/p&gt;

&lt;p&gt;Establish a Performance Baseline: Determine the LLM's initial performance on your target task to identify areas for improvement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt Optimization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Develop Initial Prompts: Create clear, structured prompts tailored to the task at hand.&lt;br&gt;
Iterative Testing and Refinement: Continuously test and refine these prompts based on the LLM's output quality and relevance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieval-Augmented Generation (RAG) Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Introduce Contextual Data: Implement RAG to provide the LLM with access to relevant, domain-specific content.&lt;/p&gt;

&lt;p&gt;Evaluate and Adjust RAG: Monitor the LLM's performance with RAG, tweaking the content and its relevance as needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fine-Tuning with Specific Datasets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Curate Specialized Datasets: Select or create datasets that are highly relevant to the specific task.&lt;br&gt;
Fine-Tune the LLM: Continue the LLM's training with these datasets to specialize its capabilities for the task.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Combining Fine-Tuning and RAG&lt;/strong&gt;&lt;br&gt;
•Integrate RAG with Fine-Tuned Models: Use RAG to supplement the fine-tuned model with additional contextual information.&lt;br&gt;
•Optimize for Balance: Ensure a balance between the LLM's general knowledge and its specialized capabilities.&lt;br&gt;
 &lt;strong&gt;Performance Evaluation and Optimization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Continuous Evaluation: Regularly assess the LLM’s performance on the target task, using both qualitative and quantitative measures.&lt;br&gt;
Feedback Loop for Improvement: Use the insights from evaluations to further refine the prompts, RAG implementation, and fine-tuning.&lt;br&gt;
** Deployment and Real-World Testing**&lt;br&gt;
Deploy the Optimized LLM: Implement the optimized LLM in a real-world scenario or a testing environment that closely mimics actual use cases.&lt;br&gt;
Monitor and Adjust in Real-Time: Continuously monitor the LLM’s performance in real-world applications, making adjustments as needed based on user feedback and performance data.&lt;br&gt;
&lt;strong&gt;Iterative Improvement&lt;/strong&gt;&lt;br&gt;
Long-Term Optimization: Recognize that LLM optimization is an ongoing process. Regularly revisit and update the model with new data, techniques, and insights.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F80l2p8cobpfiracwu4cy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F80l2p8cobpfiracwu4cy.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Retrieval augmented generation (RAG)
&lt;/h2&gt;

&lt;p&gt;Retrieval Augmented Generation (RAG) combines the advanced text-generation capabilities of GPT and other large language models with information retrieval functions to provide precise and contextually relevant information. This innovative approach improves language models' ability to understand and process user queries by integrating the latest and most relevant data&lt;/p&gt;

&lt;p&gt;RAG is about feeding language models with necessary information. Instead of asking LLM directly(like in general-purpose models), we first retrieve the very accurate data from our knowledge library that is well maintained and then use that context to return the answer. When the user sends a query(question) to the retriever, we use vector embeddings(numerical representations) to retrieve the requested document. Once the needed information is found from the vector databases, the result is returned to the user. This largely reduces the possibility of hallucinations and updates the model without retraining the model, which is a costly process. Here's a very simple diagram that shows the process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fwy6ehx2a2bfrlxgt9da8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fwy6ehx2a2bfrlxgt9da8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Program-aided Language model (PAL)
&lt;/h2&gt;

&lt;p&gt;Artificial Intelligence (AI) continues to evolve at a rapid pace, with groundbreaking strides in generative capabilities playing a critical role in defining this ever-evolving landscape. One such transformative leap is the advent of Program-Aided Language models (PAL), an innovative solution that revolutionizes how Language Learning Models (LLMs) function. This article delves into the intricate workings of PAL and explores how it has enhanced LLMs, ultimately resulting in superior AI performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fp4xkgj12xc6gq421bp55.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fp4xkgj12xc6gq421bp55.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LLM Powered Applications&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LangChain is an advanced platform that provides developers with a seamless and intuitive interface to leverage the power of LLM in their applications. It offers a range of APIs and tools that simplify the integration of LLM into your projects, enabling you to unlock the full potential of language processing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fl355n91i3ngdmyyvmmri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fl355n91i3ngdmyyvmmri.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Langchain
&lt;/h2&gt;

&lt;p&gt;LangChain is a framework for developing applications powered by language models. It enables applications that:&lt;br&gt;
•Are context-aware: connect a language model to sources of context (prompt instructions, few shot examples, content to ground its response in, etc.)&lt;br&gt;
•Reason: rely on a language model to reason (about how to answer based on provided context, what actions to take, etc.)&lt;br&gt;
 framework consists of several parts.&lt;br&gt;
•LangChain Libraries: The Python and JavaScript libraries. Contains interfaces and integrations for a myriad of components, a basic run time for combining these components into chains and agents, and off-the-shelf implementations of chains and agents.&lt;br&gt;
•LangChain Templates: A collection of easily deployable reference architectures for a wide variety of tasks.&lt;br&gt;
•LangServe: A library for deploying LangChain chains as a REST API.&lt;br&gt;
•LangSmith: A developer platform that lets you debug, test, evaluate, and monitor chains built on any LLM framework and seamlessly integrates with LangChain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Faq82a3ckqbays5xagshl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Faq82a3ckqbays5xagshl.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Building Generative applications -High level app Frame work
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2F47dvyt2rtdf1xocxg3l4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F47dvyt2rtdf1xocxg3l4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have tried couple of AWS sagemaker LLM notebooks  shared in AWS bedrock workshop to get to know about LLM libiaries and response   - contextual generation ,Image and code generation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import json
import os
import sys

import boto3

module_path = ".."
sys.path.append(os.path.abspath(module_path))
from utils import bedrock, print_ww


# ---- ⚠️ Un-comment and edit the below lines as needed for your AWS setup ⚠️ ----

# os.environ["AWS_DEFAULT_REGION"] = "&amp;lt;REGION_NAME&amp;gt;"  # E.g. "us-east-1"
# os.environ["AWS_PROFILE"] = "&amp;lt;YOUR_PROFILE&amp;gt;"
# os.environ["BEDROCK_ASSUME_ROLE"] = "&amp;lt;YOUR_ROLE_ARN&amp;gt;"  # E.g. "arn:aws:..."

boto3_bedrock = bedrock.get_bedrock_client(
    assumed_role=os.environ.get("BEDROCK_ASSUME_ROLE", None),
    region=os.environ.get("AWS_DEFAULT_REGION", None)
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create new client
  Using region: us-east-1
boto3 Bedrock client successfully created!
bedrock-runtime(https://bedrock-runtime.us-east-1.amazonaws.com)

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

&lt;/div&gt;



&lt;p&gt;Invoke bedrock LLM model&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from langchain.llms.bedrock import Bedrock

inference_modifier = {'max_tokens_to_sample':4096, 
                      "temperature":0.5,
                      "top_k":250,
                      "top_p":1,
                      "stop_sequences": ["\n\nHuman"]
                     }

textgen_llm = Bedrock(model_id = "anthropic.claude-v2",
                    client = boto3_bedrock, 
                    model_kwargs = inference_modifier 
                    )

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

&lt;/div&gt;



&lt;p&gt;Create a LangChain custom prompt template&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from langchain.prompts import PromptTemplate

# Create a prompt template that has multiple input variables
multi_var_prompt = PromptTemplate(
    input_variables=["customerServiceManager", "customerName", "feedbackFromCustomer"], 
    template="""

Human: Create an apology email from the Service Manager {customerServiceManager} to {customerName} in response to the following feedback that was received from the customer: 
&amp;lt;customer_feedback&amp;gt;
{feedbackFromCustomer}
&amp;lt;/customer_feedback&amp;gt;

Assistant:"""
)

# Pass in values to the input variables
prompt = multi_var_prompt.format(customerServiceManager="Bob", 
                                 customerName="John Doe", 
                                 feedbackFromCustomer="""Hello Bob,
     I am very disappointed with the recent experience I had when I called your customer support.
     I was expecting an immediate call back but it took three days for us to get a call back.
     The first suggestion to fix the problem was incorrect. Ultimately the problem was fixed after three days.
     We are very unhappy with the response provided and may consider taking our business elsewhere.
     """
     )

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num_tokens = textgen_llm.get_num_tokens(prompt)
print(f"Our prompt has {num_tokens} tokens")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;response = textgen_llm(prompt)

email = response[response.index('\n')+1:]

print_ww(email)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I want to sincerely apologize for the poor service you recently received from our customer support
team. It is unacceptable that it took multiple days for us to respond and resolve your issue.

As the Service Manager, I take full responsibility for this situation. I will be looking into why
there were delays in responding and getting your problem fixed correctly. It is our top priority to
provide prompt, knowledgeable support so our customers' needs are addressed efficiently.

I understand your frustration with this experience and do not blame you for considering taking your
business elsewhere. We value you as a customer and want to regain your trust. Please let me know if
there is anything I can do to make this right. I would be happy to offer you a discount on your next
purchase or provide a refund as an apology for the inconvenience.

Our goal is to deliver excellent customer service and support. This situation shows we have more
work to do. I will be implementing changes to our processes and additional training for our staff to
prevent something like this from happening again.

I appreciate you taking the time to share your feedback. It will help us improve. I sincerely hope
you will give us another chance to provide you with the positive experience you deserve. Please feel
free to contact me directly if you have any other concerns.

Sincerely,

Bob
Service Manager
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Translation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import json
import os
import sys

import boto3

module_path = ".."
sys.path.append(os.path.abspath(module_path))
from utils import bedrock, print_ww


# ---- ⚠️ Un-comment and edit the below lines as needed for your AWS setup ⚠️ ----

# os.environ["AWS_DEFAULT_REGION"] = "&amp;lt;REGION_NAME&amp;gt;"  # E.g. "us-east-1"
# os.environ["AWS_PROFILE"] = "&amp;lt;YOUR_PROFILE&amp;gt;"
# os.environ["BEDROCK_ASSUME_ROLE"] = "&amp;lt;YOUR_ROLE_ARN&amp;gt;"  # E.g. "arn:aws:..."


boto3_bedrock = bedrock.get_bedrock_client(
    assumed_role=os.environ.get("BEDROCK_ASSUME_ROLE", None),
    region=os.environ.get("AWS_DEFAULT_REGION", None),
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from langchain.llms.bedrock import Bedrock

inference_modifier = {'max_tokens_to_sample':4096, 
                      "temperature":0.5,
                      "top_k":250,
                      "top_p":1,
                      "stop_sequences": ["\n\nHuman"]
                     }

textgen_llm = Bedrock(model_id = "anthropic.claude-v2",
                    client = boto3_bedrock, 
                    model_kwargs = inference_modifier 
                    )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Vehicle Fleet Management Code written in C++
sample_code = """
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;vector&amp;gt;

class Vehicle {
protected:
    std::string registrationNumber;
    int milesTraveled;
    int lastMaintenanceMile;

public:
    Vehicle(std::string regNum) : registrationNumber(regNum), milesTraveled(0), lastMaintenanceMile(0) {}

    virtual void addMiles(int miles) {
        milesTraveled += miles;
    }

    virtual void performMaintenance() {
        lastMaintenanceMile = milesTraveled;
        std::cout &amp;lt;&amp;lt; "Maintenance performed for vehicle: " &amp;lt;&amp;lt; registrationNumber &amp;lt;&amp;lt; std::endl;
    }

    virtual void checkMaintenanceDue() {
        if ((milesTraveled - lastMaintenanceMile) &amp;gt; 10000) {
            std::cout &amp;lt;&amp;lt; "Vehicle: " &amp;lt;&amp;lt; registrationNumber &amp;lt;&amp;lt; " needs maintenance!" &amp;lt;&amp;lt; std::endl;
        } else {
            std::cout &amp;lt;&amp;lt; "No maintenance required for vehicle: " &amp;lt;&amp;lt; registrationNumber &amp;lt;&amp;lt; std::endl;
        }
    }

    virtual void displayDetails() = 0;

    ~Vehicle() {
        std::cout &amp;lt;&amp;lt; "Destructor for Vehicle" &amp;lt;&amp;lt; std::endl;
    }
};

class Truck : public Vehicle {
    int capacityInTons;

public:
    Truck(std::string regNum, int capacity) : Vehicle(regNum), capacityInTons(capacity) {}

    void displayDetails() override {
        std::cout &amp;lt;&amp;lt; "Truck with Registration Number: " &amp;lt;&amp;lt; registrationNumber &amp;lt;&amp;lt; ", Capacity: " &amp;lt;&amp;lt; capacityInTons &amp;lt;&amp;lt; " tons." &amp;lt;&amp;lt; std::endl;
    }
};

class Car : public Vehicle {
    std::string model;

public:
    Car(std::string regNum, std::string carModel) : Vehicle(regNum), model(carModel) {}

    void displayDetails() override {
        std::cout &amp;lt;&amp;lt; "Car with Registration Number: " &amp;lt;&amp;lt; registrationNumber &amp;lt;&amp;lt; ", Model: " &amp;lt;&amp;lt; model &amp;lt;&amp;lt; "." &amp;lt;&amp;lt; std::endl;
    }
};

int main() {
    std::vector&amp;lt;Vehicle*&amp;gt; fleet;

    fleet.push_back(new Truck("XYZ1234", 20));
    fleet.push_back(new Car("ABC9876", "Sedan"));

    for (auto vehicle : fleet) {
        vehicle-&amp;gt;displayDetails();
        vehicle-&amp;gt;addMiles(10500);
        vehicle-&amp;gt;checkMaintenanceDue();
        vehicle-&amp;gt;performMaintenance();
        vehicle-&amp;gt;checkMaintenanceDue();
    }

    for (auto vehicle : fleet) {
        delete vehicle; 
    }

    return 0;
}
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from langchain.prompts import PromptTemplate

# Create a prompt template that has multiple input variables
multi_var_prompt = PromptTemplate(
    input_variables=["code", "srcProgrammingLanguage", "targetProgrammingLanguage"], 
    template="""

Human: You will be acting as an expert software developer in {srcProgrammingLanguage} and {targetProgrammingLanguage}. 
You will tranlslate below code from {srcProgrammingLanguage} to {targetProgrammingLanguage} while following coding best practices.

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
{code}

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Assistant: """
)

# Pass in values to the input variables
prompt = multi_var_prompt.format(code=sample_code, srcProgrammingLanguage="C++", targetProgrammingLanguage="Java")

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code translation from C++ to Java
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;response = textgen_llm(prompt)

target_code = response[response.index('\n')+1:]

print_ww(target_code)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.ArrayList&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;registrationNumber&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;milesTraveled&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;lastMaintenanceMile&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;regNum&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;registrationNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;regNum&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;milesTraveled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;lastMaintenanceMile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;addMiles&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;miles&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;milesTraveled&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;miles&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;performMaintenance&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;lastMaintenanceMile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;milesTraveled&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Maintenance performed for vehicle: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;registrationNumber&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;checkMaintenanceDue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="n"&gt;milesTraveled&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;lastMaintenanceMile&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Vehicle: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;registrationNumber&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" needs maintenance!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No maintenance required for vehicle: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;registrationNumber&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;displayDetails&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Truck&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;capacityInTons&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Truck&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;regNum&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;regNum&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;capacityInTons&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;capacity&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;displayDetails&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Truck with Registration Number: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;registrationNumber&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", Capacity: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
&lt;span class="n"&gt;capacityInTons&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" tons."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;regNum&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;carModel&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;regNum&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;carModel&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;displayDetails&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Car with Registration Number: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;registrationNumber&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;", Model: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
&lt;span class="s"&gt;"."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;fleet&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;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;();&lt;/span&gt;

    &lt;span class="n"&gt;fleet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&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;Truck&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"XYZ1234"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
    &lt;span class="n"&gt;fleet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&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;Car&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ABC9876"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sedan"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="n"&gt;vehicle&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fleet&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;displayDetails&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
      &lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addMiles&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10500&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
      &lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;checkMaintenanceDue&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
      &lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;performMaintenance&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
      &lt;span class="n"&gt;vehicle&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;checkMaintenanceDue&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;The&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="n"&gt;differences&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nl"&gt;Java:&lt;/span&gt;

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nc"&gt;Includes&lt;/span&gt; &lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;imports&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nl"&gt;std:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nl"&gt;std:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nc"&gt;Pointers&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;object&lt;/span&gt; &lt;span class="n"&gt;creation&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nc"&gt;Override&lt;/span&gt; &lt;span class="n"&gt;keyword&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;overridden&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nc"&gt;Virtual&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt; &lt;span class="n"&gt;changed&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="kd"&gt;public&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nc"&gt;Destructors&lt;/span&gt; &lt;span class="n"&gt;not&lt;/span&gt; &lt;span class="n"&gt;needed&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="nc"&gt;Java&lt;/span&gt;

&lt;span class="no"&gt;I&lt;/span&gt; &lt;span class="n"&gt;followed&lt;/span&gt; &lt;span class="nc"&gt;Java&lt;/span&gt; &lt;span class="n"&gt;naming&lt;/span&gt; &lt;span class="n"&gt;conventions&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="n"&gt;coding&lt;/span&gt; &lt;span class="n"&gt;standards&lt;/span&gt; &lt;span class="n"&gt;like&lt;/span&gt; &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;camelCase&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt;
&lt;span class="n"&gt;object&lt;/span&gt; &lt;span class="n"&gt;oriented&lt;/span&gt; &lt;span class="n"&gt;design&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="nc"&gt;Let&lt;/span&gt; &lt;span class="n"&gt;me&lt;/span&gt; &lt;span class="n"&gt;know&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;have&lt;/span&gt; &lt;span class="n"&gt;any&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt; &lt;span class="n"&gt;questions&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Reference: *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/langchain-ai/langchain" rel="noopener noreferrer"&gt;https://github.com/langchain-ai/langchain&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/pulse/what-constitutional-ai-alexandra-barr/" rel="noopener noreferrer"&gt;https://www.linkedin.com/pulse/what-constitutional-ai-alexandra-barr/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@kanikaadik07/generative-ai-project-life-cycle-55ce9092e24a" rel="noopener noreferrer"&gt;https://medium.com/@kanikaadik07/generative-ai-project-life-cycle-55ce9092e24a&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/pavanbelagatti/a-beginners-guide-to-building-llm-powered-applications-with-langchain-2d6e"&gt;https://dev.to/pavanbelagatti/a-beginners-guide-to-building-llm-powered-applications-with-langchain-2d6e&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.superannotate.com/blog/rag-explained" rel="noopener noreferrer"&gt;https://www.superannotate.com/blog/rag-explained&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.coursera.org/learn/generative-ai-with-llms" rel="noopener noreferrer"&gt;https://www.coursera.org/learn/generative-ai-with-llms&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/aws-samples/amazon-bedrock-workshop" rel="noopener noreferrer"&gt;https://github.com/aws-samples/amazon-bedrock-workshop&lt;/a&gt;&lt;/p&gt;

</description>
      <category>largelanguagemodel</category>
      <category>bedrock</category>
      <category>aws</category>
      <category>ai</category>
    </item>
    <item>
      <title>AWS - AI Q&amp;A APP using Kendra , Bedrock LLM and Streamlit(UI)</title>
      <dc:creator>selvakumar palanisamy</dc:creator>
      <pubDate>Mon, 30 Oct 2023 12:05:30 +0000</pubDate>
      <link>https://dev.to/selvapal/aws-ai-qa-app-using-kendra-bedrock-llm-and-streamlitui-1hkn</link>
      <guid>https://dev.to/selvapal/aws-ai-qa-app-using-kendra-bedrock-llm-and-streamlitui-1hkn</guid>
      <description>&lt;p&gt;For the last two weeks, I've been learning about generative AI and various use cases, and here is my first technical blog about how to build your own QA AI app utilising AWS Kendra and the generative AI service. &lt;/p&gt;

&lt;p&gt;This blog is for you if you want to learn more about the power of Generative AI on Amazon AWS.  &lt;/p&gt;

&lt;p&gt;I'll show you how to create a Q&amp;amp;A app with Amazon Bedrock, the Kendra database, and streamlit (UI).&lt;/p&gt;

&lt;p&gt;Let's look at how the LLM responds to a query on the topics before we start developing the app. &lt;/p&gt;

&lt;p&gt;There are two approaches to enable the LLM model to understand and answer enquiries.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Fine-tune the LLM on text data addressing the topic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using Retrieval Augmented generating (RAG), a technique that incorporates a retrieval component into the generating process. Allows you to retrieve relevant information and feed it into the generating model as a secondary source of data.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We will go with option 2.&lt;/p&gt;

&lt;p&gt;RAG requires an external "knowledge database" to store and retrieve essential information.Consider this database to be our LLM's external long-term memory.&lt;/p&gt;

&lt;p&gt;A semantic search database will be used to get information that is semantically connected to our query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database for semantic search&lt;/strong&gt;&lt;br&gt;
A semantic search database is one that uses semantic technology to understand the meanings and relationships between words and phrases in order to provide highly relevant search results.&lt;/p&gt;

&lt;p&gt;Semantic search is a sort of search that makes use of natural language processing algorithms to understand the meaning and context of words and phrases in order to provide more accurate search results.&lt;/p&gt;

&lt;p&gt;This strategy is based on the idea that search engines should aim to understand the user's purpose as well as the relationships between the words used, rather than simply matching keywords in a query.&lt;/p&gt;

&lt;p&gt;Semantic search, rather than merely matching phrases, is designed to give more particular and meaningful search results that better represent the user's intent. This makes it particularly useful for sophisticated queries such as scientific research, medical information, and legal papers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS services&lt;/strong&gt;&lt;br&gt;
For the Generative AI LLMs:&lt;/p&gt;

&lt;p&gt;AWS Bedrock&lt;/p&gt;

&lt;p&gt;For the knowledge database:&lt;/p&gt;

&lt;p&gt;AWS Kendra&lt;br&gt;
 AWS S3&lt;/p&gt;

&lt;p&gt;Diagram shows how the AWS services are going to interact between them:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--30zKl5pQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5upu0f9madg0nd69c6zi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--30zKl5pQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5upu0f9madg0nd69c6zi.png" alt="Image description" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How the Q&amp;amp;A App Work?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The personal documents are kept in an S3 bucket.&lt;/p&gt;

&lt;p&gt;The Kendra Index is connected with a s3 connector. Every N minutes, the Index scans the s3 bucket for new data.  When new content is uploaded in the bucket, it is automatically processed and saved to the Kendra database.&lt;/p&gt;

&lt;p&gt;When a user runs a query using the Streamlit app, the app performs the following actions:&lt;/p&gt;

&lt;p&gt;Kendra's relevant information for the supplied query is returned.&lt;br&gt;
The prompt is put together.&lt;br&gt;
Sends the prompt to one of the available Bedrock LLMs and outputs the response.&lt;/p&gt;

&lt;p&gt;One of the best aspects of utilising AWS Kendra (in conjunction with AWS S3) as our knowledge database is that the "Ingest Process" (as shown in the diagram above) is totally automated, so you don't have to do anything.&lt;/p&gt;

&lt;p&gt;When we add, update, or delete a document from the S3 bucket, the content is automatically processed and saved in Kendra.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By default, in Bedrock you will have access only to the Amazon Titan LLM. To utilize any of the third-party LLMs (Anthropic and AI21 Labs LLM models), you must register for access separately.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1E6O-ViK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwe7aenxg28hev5utw8v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1E6O-ViK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwe7aenxg28hev5utw8v.png" alt="Image description" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CmgFsSH9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jv9imwpqcnhopfkuqhmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CmgFsSH9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jv9imwpqcnhopfkuqhmh.png" alt="Image description" width="800" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deploy the required AWS services&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To make the app work we need to deploy the following AWS services:&lt;/p&gt;

&lt;p&gt;An s3 bucket for uploading  our private docs.&lt;br&gt;
A Kendra index with an s3 connector.&lt;br&gt;
An IAM role with the required permissions to make everything work.&lt;/p&gt;

&lt;p&gt;Use the terraform files in the github repository to create the required services on your AWS account&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://github.com/selvakumarsai/ai-qa-app-awskendra-benrock-streamli.git

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;admin@192-168-1-191 infra % terraform apply
data.aws_caller_identity.current: Reading...
data.aws_region.current: Reading...
data.aws_region.current: Read complete after 0s [id=us-east-1]
.
.
.
.
aws_kendra_index.kendra_docs_index: Creating...
aws_kendra_index.kendra_docs_index: Still creating... [10s elapsed]
aws_kendra_index.kendra_docs_index: Still creating... [20s elapsed]
aws_kendra_index.kendra_docs_index: Still creating... [30s elapsed]
aws_kendra_index.kendra_docs_index: Creation complete after 38s [id=f40139ce-f7fb-4ca9-a95f-759431c91fdb]
aws_kendra_data_source.kendra_docs_s3_connector: Creating...
aws_kendra_data_source.kendra_docs_s3_connector: Creation complete after 4s [id=cbfb3da7-660b-4f38-b7f0-b3964548609e/f40139ce-f7fb-4ca9-a95f-759431c91fdb]

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Simple UI:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A text input field where the users can type the question they want to ask.&lt;br&gt;
A numeric input where the users can set the LLM max tokens.&lt;br&gt;
A numeric input where the users can set the LLM temperature.&lt;br&gt;
A dropdown to select which AWS Bedrock LLM we want to use to generate the response.&lt;br&gt;
And a submit button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to run the app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The repository has a.env file that contains the environment variables required for the app to execute successfully:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;KENDRA_INDEX='&amp;lt;kendra-index&amp;gt;'
AWS_BEDROCK_REGION='&amp;lt;bedrock-region&amp;gt;'
AWS_KENDRA_REGION='&amp;lt;region-where-kendra-index-is-deployed&amp;gt;'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Restore dependencies&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you install Streamlit, you also get a command-line (CLI) utility. This tool's intended is to run Streamlit programmes.&lt;br&gt;
Simply run the following command to launch the app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;streamlit run app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k3SD3rlk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuzgqoo7tc7l8hwmpg0x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k3SD3rlk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuzgqoo7tc7l8hwmpg0x.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve the relevant information from Kendra&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The LangChainAmazonKendraRetriever class will be used to obtain the appropriate docs from our knowledge database (AWS Kendra).&lt;/p&gt;

&lt;p&gt;The AmazonKendraRetriever class makes use of Amazon Kendra's Retrieve API to query the Amazon Kendra index and retrieve the docs most relevant to the user query.&lt;/p&gt;

&lt;p&gt;To construct the RAG pattern, the AmazonKendraRetriever class will be plugged into a LangChain chain. &lt;/p&gt;

&lt;p&gt;The boto3 Kendra client's retrieve method allows us to retrieve relevant documents from our knowledge database.&lt;br&gt;
We combine the papers we obtained from Kendra into a single "string" after retrieving them.&lt;/p&gt;

&lt;p&gt;This "string" indicates the context that will be added to the prompt, indicating to the Bedrock LLM that it will only be able to answer using the information provided in this context. It cannot develop a solution to our question using data from outside this context.&lt;/p&gt;

&lt;p&gt;Prepare the prompt &lt;/p&gt;

&lt;p&gt;We build the prompt that will be sent to a Bedrock LLM.&lt;/p&gt;

&lt;p&gt;The placeholders query and docs can be found within the prompt.&lt;/p&gt;

&lt;p&gt;The programme will insert the user query into the query placeholder.The app will add the context acquired from Kendra to the documents placeholder.&lt;/p&gt;

&lt;p&gt;The final step is to transmit the prompt to one of the Bedrock LLMs via the invoke_model method from the boto3 Bedrock client and receive the response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing the Q&amp;amp;A app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s test if the Q&amp;amp;A app works correctly.&lt;/p&gt;

&lt;p&gt;Remember that the Microsoft.NET Microservices book was used to populate the knowledge base, therefore any questions we ask should be about that specific topic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--koqTKd70--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/trd7j5zxn482oxvoabb5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--koqTKd70--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/trd7j5zxn482oxvoabb5.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This repository has a Dockerfile in case you prefer to execute the app on a container&lt;/p&gt;

&lt;p&gt;docker build -t aws-rag-app .&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
