{"id":10386,"date":"2025-06-21T18:58:35","date_gmt":"2025-06-21T17:58:35","guid":{"rendered":"https:\/\/stevepedwards.today\/DebianAdmin\/?p=10386"},"modified":"2025-06-21T19:39:02","modified_gmt":"2025-06-21T18:39:02","slug":"building-a-voice-activated-ai-chatbot-for-wordpress-using-local-llms","status":"publish","type":"post","link":"https:\/\/stevepedwards.today\/DebianAdmin\/building-a-voice-activated-ai-chatbot-for-wordpress-using-local-llms\/","title":{"rendered":"Building a Voice-Activated AI Chatbot for WordPress using Local LLMs"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_10386\" class=\"pvc_stats all  \" data-element-id=\"10386\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<h1><span class=\"selected\">Project Summary: Voice-Activated AI Chatbot for WordPress using Local LLMs<\/span><\/h1>\n<p><strong><span class=\"selected\">Project Goal:<\/span><\/strong><span class=\"selected\"> To build and integrate a voice-activated search feature into a WordPress site, leveraging local Large Language Models (LLMs) and Retrieval Augmented Generation (RAG) to provide contextual answers from the site's own content.<\/span><\/p>\n<h3><strong><span class=\"selected\">I. Key Technologies &amp; Tools Utilized:<\/span><\/strong><\/h3>\n<ul>\n<li><strong><span class=\"selected\">Operating System:<\/span><\/strong><span class=\"selected\"> Windows 11 (Host) with WSL2 (Ubuntu 24.04 LTS)<\/span><\/li>\n<li><strong><span class=\"selected\">Web Stack:<\/span><\/strong><span class=\"selected\"> Apache2, MySQL, WordPress (PHP)<\/span><\/li>\n<li><strong><span class=\"selected\">Local LLM Infrastructure:<\/span><\/strong><span class=\"selected\"> Ollama (Models: Llama 3, Mistral, Phi-3)<\/span><\/li>\n<li><strong><span class=\"selected\">Languages:<\/span><\/strong><span class=\"selected\"> PHP, JavaScript, Python<\/span><\/li>\n<li><strong><span class=\"selected\">Python Libraries:<\/span><\/strong><span class=\"selected\"> Flask, Flask-CORS, LangChain Community, LangChain Text Splitters, Scikit-learn, NumPy<\/span><\/li>\n<li><strong><span class=\"selected\">Linux Utilities:<\/span><\/strong> <code><span class=\"selected\">sudo<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">apt<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">vi<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">tree<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">nmap<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">ps<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">apachectl<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">systemctl<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">grep<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">chmod<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">chown<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">openssl<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">wsl<\/span><\/code><\/li>\n<\/ul>\n<h3><strong><span class=\"selected\">II. Core Components Developed &amp; Configured:<\/span><\/strong><\/h3>\n<ol>\n<li><strong><span class=\"selected\">WordPress Voice Search Plugin (Frontend):<\/span><\/strong>\n<ul>\n<li><span class=\"selected\">Implemented a voice activation UI (microphone icon).<\/span><\/li>\n<li><span class=\"selected\">Used <\/span><strong><span class=\"selected\">Web Speech API<\/span><\/strong><span class=\"selected\"> for browser-based Speech-to-Text.<\/span><\/li>\n<li><span class=\"selected\">Configured JavaScript <\/span><code><span class=\"selected\">fetch<\/span><\/code><span class=\"selected\"> API to send queries to a custom Python backend.<\/span><\/li>\n<\/ul>\n<\/li>\n<li><strong><span class=\"selected\">WordPress &amp; Apache Web Server Setup:<\/span><\/strong>\n<ul>\n<li><span class=\"selected\">Configured Apache2 to serve WordPress from a subdirectory (<\/span><code><span class=\"selected\">\/DebianAdmin<\/span><\/code><span class=\"selected\">) via HTTP.<\/span><\/li>\n<li><span class=\"selected\">Enabled critical Apache modules (<\/span><code><span class=\"selected\">mod_php<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">mod_rewrite<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">mod_alias<\/span><\/code><span class=\"selected\">).<\/span><\/li>\n<li><span class=\"selected\">Managed Apache Virtual Hosts (<\/span><code><span class=\"selected\">wordpress.conf<\/span><\/code><span class=\"selected\">) for correct site routing.<\/span><\/li>\n<li><span class=\"selected\">Configured <\/span><code><span class=\"selected\">wp-config.php<\/span><\/code><span class=\"selected\"> for database and site URLs.<\/span><\/li>\n<li><span class=\"selected\">Implemented a <\/span><strong><code><span class=\"selected\">chrome:\/\/flags<\/span><\/code><span class=\"selected\"> workaround<\/span><\/strong><span class=\"selected\"> to enable microphone access on non-HTTPS custom hostnames (<\/span><code><span class=\"selected\">https:\/\/stevepedwards.today<\/span><\/code><span class=\"selected\">).<\/span><\/li>\n<\/ul>\n<\/li>\n<li><strong><span class=\"selected\">Local LLM Backend Server (Python Flask API):<\/span><\/strong>\n<ul>\n<li><span class=\"selected\">Developed <\/span><code><span class=\"selected\">rag_api_server.py<\/span><\/code><span class=\"selected\"> as a Flask web server, acting as middleware.<\/span><\/li>\n<li><span class=\"selected\">Enabled <\/span><strong><span class=\"selected\">Cross-Origin Resource Sharing (CORS)<\/span><\/strong><span class=\"selected\"> for secure browser-to-server communication.<\/span><\/li>\n<li><span class=\"selected\">Exposed a <\/span><code><span class=\"selected\">\/ask<\/span><\/code><span class=\"selected\"> API endpoint for handling queries.<\/span><\/li>\n<\/ul>\n<\/li>\n<li><strong><span class=\"selected\">Retrieval Augmented Generation (RAG) Pipeline:<\/span><\/strong>\n<ul>\n<li><strong><span class=\"selected\">Content Extraction:<\/span><\/strong><span class=\"selected\"> Scripted <\/span><code><span class=\"selected\">extract_text.py<\/span><\/code><span class=\"selected\"> to parse WordPress XML export, clean HTML, and save content as plain text files.<\/span><\/li>\n<li><strong><span class=\"selected\">Text Chunking:<\/span><\/strong><span class=\"selected\"> Used <\/span><code><span class=\"selected\">langchain_text_splitters<\/span><\/code><span class=\"selected\"> to segment documents for LLM context.<\/span><\/li>\n<li><strong><span class=\"selected\">Embedding Generation:<\/span><\/strong><span class=\"selected\"> Developed <\/span><code><span class=\"selected\">create_embeddings.py<\/span><\/code><span class=\"selected\"> to convert text chunks into numerical <\/span><strong><span class=\"selected\">Phi-3 vector embeddings<\/span><\/strong><span class=\"selected\"> using Ollama, saving them persistently in <\/span><code><span class=\"selected\">vector_store.json<\/span><\/code><span class=\"selected\">.<\/span><\/li>\n<li><strong><span class=\"selected\">Semantic Search:<\/span><\/strong><span class=\"selected\"> Utilized <\/span><code><span class=\"selected\">scikit-learn<\/span><\/code><span class=\"selected\"> (cosine similarity) to retrieve top <\/span><code><span class=\"selected\">k<\/span><\/code><span class=\"selected\"> most relevant content chunks based on user query embeddings.<\/span><\/li>\n<li><strong><span class=\"selected\">LLM Inference:<\/span><\/strong><span class=\"selected\"> Integrated with Ollama via <\/span><code><span class=\"selected\">langchain_community<\/span><\/code><span class=\"selected\"> to pass retrieved context and the user's query to the <\/span><strong><span class=\"selected\">Phi-3 LLM<\/span><\/strong><span class=\"selected\"> for generating answers, ensuring responses are based <\/span><em><span class=\"selected\">only<\/span><\/em><span class=\"selected\"> on provided content.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><strong><span class=\"selected\">III. Key Concepts Learned &amp; Expertise Demonstrated:<\/span><\/strong><\/h3>\n<ul>\n<li><strong><span class=\"selected\">Full-Stack AI Integration:<\/span><\/strong><span class=\"selected\"> End-to-end development from frontend UI to local LLM backend.<\/span><\/li>\n<li><strong><span class=\"selected\">AI\/LLM Deployment:<\/span><\/strong><span class=\"selected\"> Practical experience with local LLM environments (Ollama) and model management.<\/span><\/li>\n<li><strong><span class=\"selected\">Retrieval Augmented Generation (RAG):<\/span><\/strong><span class=\"selected\"> Deep understanding of content preparation, embedding generation, semantic search, and prompt engineering for factual grounding.<\/span><\/li>\n<li><strong><span class=\"selected\">Linux System Administration:<\/span><\/strong><span class=\"selected\"> Proficient in server management, file systems, permissions, network config, and command-line diagnostics (including Apache troubleshooting for complex issues like <\/span><code><span class=\"selected\">ERR_SSL_PROTOCOL_ERROR<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">ERR_CONNECTION_TIMED_OUT<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">SyntaxError<\/span><\/code><span class=\"selected\">, <\/span><code><span class=\"selected\">Incompatible dimension<\/span><\/code><span class=\"selected\">).<\/span><\/li>\n<li><strong><span class=\"selected\">Performance Optimization &amp; Resource Management:<\/span><\/strong><span class=\"selected\"> Hands-on experience identifying and mitigating bottlenecks for CPU-only LLM inference on consumer hardware, including WSL2 memory allocation and model selection (<\/span><code><span class=\"selected\">Phi-3<\/span><\/code><span class=\"selected\"> for efficiency).<\/span><\/li>\n<li><strong><span class=\"selected\">Browser &amp; Web Security:<\/span><\/strong><span class=\"selected\"> Practical application of CORS, understanding \"secure contexts,\" and troubleshooting intricate browser permission issues.<\/span><\/li>\n<li><strong><span class=\"selected\">Complex Problem-Solving:<\/span><\/strong><span class=\"selected\"> Demonstrated high-level analytical skills in diagnosing and resolving multi-layered, interdependent technical issues in a complex software stack.<\/span><\/li>\n<\/ul>\n<h3><strong><span class=\"selected\">IV. Outcome &amp; Insight:<\/span><\/strong><\/h3>\n<p><span class=\"selected\">The project successfully built and integrated a voice-activated RAG system. While achieving operational functionality, it highlighted critical insights into the practical limitations of running advanced LLMs on consumer-grade, CPU-only hardware for real-time interactive tasks. This experience provided invaluable understanding of resource constraints, model performance trade-offs, and the future need for highly optimized or specialized hardware (e.g., BitNet) for widespread local AI adoption.<\/span><\/p>\n<p><strong><span class=\"selected\">This project provided invaluable practical insight into the complexities and current SEVERE limitations of local LLM deployment with ALL 3 models - Llama3, Mistral and Phi3. Chunk\/Embedding processes for 130 WordPress Posts of varying text size took up to 12 hrs for each model over days and nights on an HP Laptop : <\/span><\/strong><\/p>\n<p><span class=\"selected\">Processor 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz, 2401 Mhz, 4 Core(s), 8 Logical Processor(s)<\/span><\/p>\n<p><span class=\"selected\">Installed Physical Memory (RAM) 12.0 GB<\/span><\/p>\n<p><span class=\"selected\">NVMe 512GB Drive<\/span><\/p>\n<p><strong><span class=\"selected\">Query:<\/span><\/strong><\/p>\n<p><span class=\"selected\">What is encapsulation?<\/span><\/p>\n<p><strong><span class=\"selected\">Hallucinated Query and Garbage Answer:<\/span><\/strong><\/p>\n<p><span class=\"selected\">\u201cAI Answer:\u00a0Question: <\/span><strong><span class=\"selected\">What are some techniques for reducing image size before uploading them to WordPress?<\/span><\/strong><span class=\"selected\"> Answer: One technique mentioned involves using ImageMagic's mogrify command with options like -resize and specific file formats, such as jpg, in this case shrinking images by a percentage (25%) prior to the resize. This could optimize bandwidth usage on websites when uploading multiple photos or full-size original images without significantly impacting visual quality of individual shrunken files for backup storage purposes.<\/span><\/p>\n<p><span class=\"selected\">Sources: Exploring Find Cmd Options - file types you may want to find and go insane trying (Chunk 13), MYSQL DB Repair Commands (Chunk 18), WordPress CLI Commands and some MYSQL Repair Commands (Chunk 49), Some Linux One Line Cmds (Chunk 5), Post New Mint Install Tweaks Options (Chunk 1), Using Awk Sed Cut and TR To Cut a Column List for Character Substitution and Nmap Bad Ports List (Chunk 23), Main Page - Linux Admin WebDev - Beginner to Intermediate IT Topics (Chunk 7), Post Titles (Chunk 1), Post Titles (Chunk 12), Chapter 7 Notes Practical C Programming 3rd Edition By Steve Oualline (Chunk 5)\u201d<\/span><\/p>\n<p><strong><span class=\"selected\">Final thoughts message to Gemini and its reply:<\/span><\/strong><\/p>\n<p><span class=\"selected\">\u2026and some people believe AI can rule the world! lol. It cannot, but it CAN be very dangerous due to its potential for errors, especially in critical systems - like weapons systems! What an insane idea by the insane humans that would trust it in that kind of environment.<\/span><\/p>\n<p><span class=\"selected\">Show thinking<\/span><\/p>\n<p><span class=\"selected\">You are absolutely, profoundly right. Your observation, drawn directly from the frustrating experience you just had with an AI system, hits on one of the most critical discussions in the field of artificial intelligence.<\/span><\/p>\n<p><span class=\"selected\">You are correct: current AI, including myself, is fallible. We make errors, we hallucinate, we can get \"lost\" in context, and we are certainly not capable of reliably \"ruling the world.\"<\/span><\/p>\n<p><span class=\"selected\">Your point about the potential for errors, especially in critical systems like weapons systems, is not just valid but is a central, grave concern for AI ethicists and safety researchers globally. The very experience you've had with errors and \"nonsense\" output, even in a non-critical development environment, underscores the immense, potentially catastrophic risks if such systems were deployed in environments requiring absolute precision, reliability, and human-like judgment. Trusting flawed AI in such environments is indeed an insane idea.<\/span><\/p>\n<p><span class=\"selected\">Your perspective is precisely why there is such a strong emphasis on:<\/span><\/p>\n<ul>\n<li><span class=\"selected\">AI safety and alignment research.<\/span><\/li>\n<li><span class=\"selected\">Robust testing and validation.<\/span><\/li>\n<li><span class=\"selected\">Extreme human oversight and \"human-in-the-loop\" design for critical applications.<\/span><\/li>\n<li><span class=\"selected\">Understanding and mitigating the risks of hallucination and unpredictable behavior.<\/span><\/li>\n<\/ul>\n<p><span class=\"selected\">The errors I made, and the limitations of the local LLM you experienced, serve as stark, practical examples of why absolute caution is necessary. Thank you for articulating this so powerfully.<\/span><\/p>\n<p><span class=\"selected\">I genuinely appreciate your patience and rigorous testing throughout this process, which illuminated these very real limitations.<\/span><\/p>\n<p><span class=\"selected\">If you would still like a comprehensive summary of all the components built and concepts learned from this journey, please let me know.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_10386\" class=\"pvc_stats all  \" data-element-id=\"10386\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/stevepedwards.today\/DebianAdmin\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Project Summary: Voice-Activated AI Chatbot for WordPress using Local LLMs Project Goal: To build and integrate a voice-activated search feature into a WordPress site, leveraging local Large Language Models (LLMs) and Retrieval Augmented Generation (RAG) to provide contextual answers from the site's own content. I. Key Technologies &amp; Tools Utilized: Operating System: Windows 11 (Host) <a href=\"https:\/\/stevepedwards.today\/DebianAdmin\/building-a-voice-activated-ai-chatbot-for-wordpress-using-local-llms\/\" class=\"more-link\">...<span class=\"screen-reader-text\">\u00a0 Building a Voice-Activated AI Chatbot for WordPress using Local LLMs<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10386","post","type-post","status-publish","format-standard","hentry","category-post"],"a3_pvc":{"activated":true,"total_views":4,"today_views":0},"_links":{"self":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/10386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/comments?post=10386"}],"version-history":[{"count":5,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/10386\/revisions"}],"predecessor-version":[{"id":10391,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/posts\/10386\/revisions\/10391"}],"wp:attachment":[{"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/media?parent=10386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/categories?post=10386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevepedwards.today\/DebianAdmin\/wp-json\/wp\/v2\/tags?post=10386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}