<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Clint Goodman on Medium]]></title>
        <description><![CDATA[Stories by Clint Goodman on Medium]]></description>
        <link>https://medium.com/@clintgoodman27?source=rss-caacac710f6e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bTqQiRFMUrHcCYv5YWd3Jw.png</url>
            <title>Stories by Clint Goodman on Medium</title>
            <link>https://medium.com/@clintgoodman27?source=rss-caacac710f6e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 18:06:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@clintgoodman27/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Chain of Thought with Tool Calling and Structured Output]]></title>
            <link>https://clintgoodman27.medium.com/chain-of-thought-with-tool-calling-and-structured-output-5afdfc984870?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5afdfc984870</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[openai-function-calling]]></category>
            <category><![CDATA[llm-function-calling]]></category>
            <category><![CDATA[chain-of-thought]]></category>
            <category><![CDATA[structured-output]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 15:27:04 GMT</pubDate>
            <atom:updated>2025-04-17T22:48:33.280Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wlj9YAYAdzv-Wem__lHUhg.jpeg" /></figure><p>I’ve heard that Chain-of-Thought (CoT) improves results, and after watching <a href="https://www.youtube.com/watch?v=7xTGNNLPyMI">Andrej Kaparthy explain</a> about spreading computation across many tokens, it makes sense.</p><p>So, how do you apply Chain-of-Thought to tool calling and structured output? The answer, it turns out, is super simple.</p><p>Let’s take the Large Language Model (LLM) prompt:</p><pre>Here is a user query:<br>---<br>Create a dozen projects that have a dozen and a half tasks each.<br>---<br>How many total objects would be created for this query?</pre><p>The answer is 12 + (12 * 18) = 228.</p><p>Let’s assume we wanted to get that answer in either a structured way, or as a parameter to a tool call. We need to set up the JSON schema for the desired output. In LangChain, we might do something like:</p><pre>prompt.pipe(azureOpenAi4o.withStructuredOutput({<br>  name: &#39;create_objects&#39;,<br>  description: `creates projects and tasks`,<br>  parameters: zodToJsonSchema(z.object({<br>    total_objects: z.number().describe(&#39;the total number of objects to create&#39;),<br>  }))<br>})).invoke({})</pre><p>When using gpt-4o, I get the wrong answer 100% of the time with this prompt. The common results are total_objects: 12 | 216 .</p><p>This is because we’re trying to get the LLM to do all the computation in just a few tokens, which is the result that has the answer.</p><p>If we provide space for the LLM to think before having to generate the tokens for total_objects , we immediately get better results:</p><pre>prompt.pipe(azureOpenAi4o.withStructuredOutput({<br>  name: &#39;create_objects&#39;,<br>  description: `creates projects and tasks`,<br>  parameters: zodToJsonSchema(z.object({<br>    reasoning_steps: z.string().describe(<br>        `Let&#39;s think step by step to find the total_objects.<br>         We should end with &#39;The answer to the total number<br>         of objects to create is &lt;number&gt;.&#39;`<br>    ),<br>    total_objects: z.number().describe(&#39;the total number of objects to create&#39;),<br>  }))<br>})).invoke({})</pre><p>The only difference in this example is that I’ve added, at the beginning of the structured output, a property called reasoning_steps , which prompts for very basic Chain-of-Thought “thinking”. The result? 100% accurate answers nearly every time: total_objects: 228 .</p><p>If the reasoning_steps is not the first property, it won’t work properly, as the Large Language Model won’t have had a chance to think first.</p><p>Below is a code snippet where I tested this out 20 times in 3 situations:</p><ol><li>No reasoning_steps</li><li>reasoning_steps as the last parameter</li><li>reasoning_steps as the first parameter</li></ol><p>The results (both for accuracy as well time it took to run) are in the screenshot below the code snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a06cd9afff6a699d5ff90ae75ae2d70/href">https://medium.com/media/0a06cd9afff6a699d5ff90ae75ae2d70/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*WHaM0xQdWvOHQgyw-6kUeA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5afdfc984870" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a Trick or Treat Bot]]></title>
            <link>https://clintgoodman27.medium.com/how-to-build-a-trick-or-treat-bot-df2069c95e9d?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/df2069c95e9d</guid>
            <category><![CDATA[halloween]]></category>
            <category><![CDATA[robots]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Tue, 29 Oct 2024 20:43:23 GMT</pubDate>
            <atom:updated>2024-10-29T20:43:23.230Z</atom:updated>
            <content:encoded><![CDATA[<p>I built a “robot” to hand out my Halloween treats this year — with the twist that the kids needed to answer a math question first 😊</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FAWq6uymhcRo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DAWq6uymhcRo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FAWq6uymhcRo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f69c4b2d8b207caee5d7f196c3f96613/href">https://medium.com/media/f69c4b2d8b207caee5d7f196c3f96613/href</a></iframe><p>All the code is here: <a href="https://github.com/cgood92/halloween-treat-robot">https://github.com/cgood92/halloween-treat-robot</a>.</p><p>All you need is:</p><ol><li>Laptop</li><li>2 other devices (ie old/current phones or tablets, but one of them has to have hot spot capabilities)</li><li><a href="https://www.amazon.com/dp/B01D8KOZF4">Arduino with servo motor</a></li><li>Cardboard/tape for the robot body</li></ol><p>Here’s the architecture, with some notes below about various pieces.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*OTA1HbIuUgWgETV7xNRI3A.png" /></figure><h3>LLMs</h3><p><a href="https://ollama.com/">Ollama</a> was a breeze to use! I found llama3.1 (8 billion parameters) to be better than llama3.2, and wicked fast. Since LLMs can’t do math well, I injected math questions and answers into the prompts so that the LLM didn’t have to figure out correctness. The reason I used an LLM for this project was:</p><ol><li>To produce varied text dialogue.</li><li>To give user feedback on their answer.</li><li>To allow a multi-turn conversation if needed (ie if the user said “Could you please repeat that?”).</li></ol><p>Llama 3.1+ supports function calling. However, what I couldn’t do is get a response that <em>didn’t</em> call a function — it always seemed to suggest a function no matter what the input or instructions were. So, I abandoned this idea, and instructed the LLM to say “Good bye” when the user should get a treat, which I searched for with regex on the front-end.</p><h3>Streaming LLM output -&gt; audio</h3><p>I wanted to stream the output from the LLM to audio for my users to hear. As of the writing of this article (late 2024), I couldn’t find any open-source text-to-speech (TTS) solutions that supported streamed text as input. I decided my best option was to take the streamed text from the LLM, concatenate the text until 4 words were available to speak, then use some basic TTS engine to say those 4 words, while the next 4 words were being queued up to speak.</p><p>I experimented with <a href="https://www.npmjs.com/package/say">say.JS</a>, which uses your system’s text-to-speech engine (on a mac, it uses say , similar to if you did it in the terminal). But, I found that even if you ran the command with 4 words and immediately/consecutively asked it to say the next 4-word-phrase, that there was a long awkward pause between dictations, which sounded awful.</p><p>Surprisingly, what I found was that Chrome’s <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a> could queue up the utterances to play seamlessly as if there were little to no gaps between the 4-word-phrases.</p><p>So, I took the streamed text from the LLM, when 4 words became available have the browser speak them, while queueing up the next 4 words, and it all ended up sounding like a single streamed audio output with no noticeable silence gaps (on my laptop — my other devices had noticeable gaps).</p><h3>Synchronizing 3 screens</h3><p>3 different browsers had to be kept in sync — 2 for visual, 1 for audio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lkwQvvFlAfvZhrMMkknExg.png" /></figure><p>If the tablet and phone would have just been mini monitors, I could have easily connected the 2 to my laptop as extra screens. But, that has 2 problems:</p><ol><li>I didn’t want cords, in order to look sleek and clean.</li><li>I couldn’t figure out how to use a phone or tablet as a display screen of a laptop.</li></ol><p>So, instead, I keep all 3 screens in-sync by using a simple Fastify server and websocket connections to communicate with each other. In addition to that, the server communicated with the arduino via USB port.</p><p>Each device had a browser open to a different website path :/head, /dialogue, /voice. I also used a phone’s hotspot just to have a mobile network to all share, so I could operate outside. I should note that none of the devices needed access to the internet itself, as everything was ran and hosted locally.</p><h3>More browser APIs</h3><p>The browser is amazing. Check out a list of all the available APIs: <a href="https://developer.mozilla.org/en-US/docs/Web/API">https://developer.mozilla.org/en-US/docs/Web/API</a>.</p><p>For this project, I used the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API">Screen Wake Lock API</a> to keep the screens on for a long time, the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API">Fullscreen API</a> to go full screen, and the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a> for speech-to-text and text-to-speech.</p><p>I also learned 2 things:</p><ol><li>Many APIs require user interaction to activate them (ie clicking on a button or keyboard event). For example, on a page load, you can’t start a microphone, keep a screen awake, or go full-screen. You can only start these APIs in response to a user interaction. This is for the user’s safety, and you can learn more by searching for “browser autoplay policy”.</li><li>Some Web APIs don’t work unless you have an https connection.</li></ol><h3>Putting it all together</h3><p>Here are a few photos to show the finished project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PY3wwYLmszoCDxRWKHzGpA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1__fVklasBTjCNITdTV0zA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zuJKzDXhE1UoJxRGUU-NvQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlXFLUzKVBkNgMDP_4SdfQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df2069c95e9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI in the browser is here]]></title>
            <link>https://clintgoodman27.medium.com/ai-in-the-browser-is-here-fcb4a8637a45?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcb4a8637a45</guid>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Sun, 08 Sep 2024 03:55:10 GMT</pubDate>
            <atom:updated>2024-10-14T10:30:19.142Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pFzKbl5z9D9PPcWPzkWIxg.jpeg" /></figure><p><em>Watch my 18 minute presentation of this topic with live demos here: https://youtu.be/6ic1-wtvYz4?si=SqXH9_IfNT7LAuR2.</em></p><p>This is what excites me about having AI run in the browser:</p><ol><li><strong>Client-side privacy</strong>. Customers are worried that their data is being trained/embedded into AI models, which may later get surfaced through some type of prompt hacking. There are lots of ways to prevent this, including keeping data and AI on the browser, where inference can happen without ever leaving the user’s computer.</li><li><strong>Rich interaction</strong>. On every keystroke or click, you can run AI in the browser’s background to provide intelligent experiences.</li><li><strong>Distributed computation</strong>. If the user’s computer has good enough resources, then offloading some of the computation to their browser instead of handling all that load on the servers could be a saver for you.</li><li><strong>Accessibility</strong>. Javascript is easy to develop in, <a href="https://survey.stackoverflow.co/2024/technology/">is the most popular programming language in the world</a>, and when published on the web makes your AI experiences available for everyone.</li></ol><p>AI can now be done in the browser, browser extensions, electron apps, and Node.js back-ends. Gone are the days where AI had to be written in Python.</p><p>Here are a few demos of different AI technologies that you can use directly on the front-end (and they’re available in Node.js for back-end development as well).</p><h3>Tensorflow.JS</h3><p><em>Official website: </em><a href="https://www.tensorflow.org/js"><em>tensorflow.org</em></a></p><p><strong>Notes</strong></p><p><a href="https://www.tensorflow.org/js/guide/platform_environment">It can run</a> in the browser using (in order from slowest to fastest):</p><ul><li>CPU</li><li>WASM (web assembly)</li><li>WebGL (100 times faster)</li></ul><p>When running in Node.js, it utilizes C libraries, hardware accelaration, and Cuda where available.</p><p>Also, you can convert Python models to JavaScript.</p><p><strong>Demos</strong></p><ul><li><a href="https://storage.googleapis.com/tfjs-examples/webcam-transfer-learning/dist/index.html">Webcam Pacman</a></li><li><a href="https://jeeliz.com/demos/weboji/demos/three/raccoon/">Weboji three.JS raccoon demo</a></li><li><a href="https://github.com/SashiDo/awesome-teachable-machine">The Awesome Teachable Machine List</a></li><li><a href="https://www.tensorflow.org/js/demos">TensorFlow.js demos</a></li><li><a href="https://github.com/tensorflow/tfjs/blob/master/GALLERY.md">tfjs/GALLERY.md</a></li><li><a href="https://victordibia.com/handtrack.js/#/">Handtracking in Javascript</a></li><li><a href="https://handsfreejs.netlify.app/">Handsfree.js</a></li><li><a href="https://github.com/mjyc/jammerjs">jammerjs</a></li></ul><h3>Web Speech API</h3><p><em>Documentation: </em><a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API/Using_the_Web_Speech_API"><em>Using the Web Speech API</em></a></p><p><strong>Notes</strong></p><p>A machine-learning task that may seem so “mainstream” that it doesn’t <em>feel</em> like AI anymore is text to speech (TTS) and speech to text. This is supported now as a web API.</p><p><strong>Demo</strong></p><ul><li><a href="https://mdn.github.io/dom-examples/web-speech-api/speech-color-changer/">Speech color changer</a></li></ul><h3>Transformers.JS</h3><p><em>Official website: </em><a href="https://huggingface.co/docs/transformers.js/en/index"><em>HuggingFace — Transformers.JS</em></a></p><p><strong>Notes</strong></p><p>Huggingface is THE hub right now for AI. They offer lots of things, including a Python and JavaScript library called “Transformers”, which uses models to accomplish a variety of tasks. The supported tasks at the moment are listed below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*er0OZt0hAiRT5DIR" /><figcaption>Source: <a href="https://huggingface.co/docs/transformers.js/en/index"><em>HuggingFace — Transformers.JS</em></a></figcaption></figure><p>You can use HuggingFace’s available models, or fine-tune a large language model, or convert any Python model to Javascript. Imagine a fine-tuned Llama-3 model running in your browser!</p><p>Transformers.JS downloads models to browser cache. Because it’s stored in local cache, it’s available on subsequent refreshes and offline.</p><p><strong>Demos</strong></p><ul><li><a href="https://huggingface.co/docs/transformers.js/en/index#examples">Transformers.JS examples</a></li><li><a href="https://xenova.github.io/transformers.js/">Demo playground</a></li></ul><h3>LangChain.JS</h3><p><em>Official website: </em><a href="https://js.langchain.com/v0.2/docs/introduction/"><em>LangChain.JS</em></a></p><p><strong>Notes</strong></p><p>I’m not yet on the LangChain craze that everyone else seems to be, but if you wanted to use it to interface with external large language models, this library is available in both Python and Javascript.</p><h3>Gemini Nano Web API</h3><p><em>Official website: </em><a href="https://developer.chrome.com/docs/ai"><em>Artificial Intelligence — Chrome for Developers</em></a></p><p><strong>Notes</strong></p><p><a href="https://www.google.com/chrome/canary/">Google Chrome Canary</a>, under a flag, downloads Gemini Nano embedded into Chrome itself. It’s only a matter of time before other browsers start shipping embedded large language models as well.</p><p><strong>Demos</strong></p><ul><li><a href="https://huggingface.co/spaces/Xenova/experimental-built-in-ai-chat">Built-in AI Chat — a Hugging Face Space by Xenova</a></li><li><a href="https://chrome.dev/web-ai-demos/prompt-api-playground/">Prompt API Playground</a></li></ul><h3>The Future</h3><p>This article shows that AI is available in browsers now. Some models and tasks require heavy inference times. You can run these in <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers">web workers</a>, or use other async tricks to make the lag seem ok. But, we’re going to want and expect more. That is why this web API proposal is interesting: <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API">WebGPU API</a>. Additionally, AI models will continue to improve and <a href="https://huggingface.co/docs/optimum/en/concept_guides/quantization">quantization</a> will help give us smaller models.</p><h3>Additional reading</h3><p>There are many other libraries that we haven’t covered that are available in Javascript, and I think they are worth exploring.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*x35Q7YgbJWbQm4eT" /></figure><p>I just wanted to give a taste here of what is possible, and how easily it can be done.</p><p>Additional articles of interest may include:</p><ul><li><a href="https://devhunt.org/blog/ai-with-js-beginners-guide">AI with JS: Beginner’s Guide</a></li><li><a href="https://www.coforge.com/resource-library/white-papers/playing-with-artificial-intelligence-in-the-browser-using-tensorflow-part-2">Playing with Artificial Intelligence in the browser using TensorFlow</a></li><li><a href="https://developer.ibm.com/tutorials/an-introduction-to-ai-in-nodejs/">An introduction to AI in Node.js — IBM Developer</a></li><li><a href="https://hackernoon.com/unleashing-the-power-of-javascript-in-artificial-intelligence">Unleashing the Power of JavaScript in Artificial Intelligence | HackerNoon</a></li><li><a href="https://www.w3schools.com/ai/ai_javascript.asp">Machine Learning in JavaScript</a></li><li><a href="https://blog.tensorflow.org/2020/05/how-hugging-face-achieved-2x-performance-boost-question-answering.html">How Hugging Face achieved a 2x performance boost for Question Answering with DistilBERT in Node.js — The TensorFlow Blog</a></li><li><a href="https://dlabs.ai/blog/the-pros-and-cons-of-using-javascript-for-machine-learning/">The Pros and Cons of Using JavaScript for Machine Learning</a></li><li><a href="https://dlabs.ai/blog/performance-comparison-javascript-vs-python-for-machine-learning/">Performance Comparison: JavaScript vs. Python for Machine Learning</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcb4a8637a45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A practical guide for using AutoGen in software applications]]></title>
            <link>https://clintgoodman27.medium.com/a-practical-guide-for-using-autogen-in-software-applications-8799185d27ee?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8799185d27ee</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mixture-of-experts]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[autogen]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Sat, 06 Jan 2024 22:44:34 GMT</pubDate>
            <atom:updated>2024-05-02T01:30:38.825Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yrraWH6aGNnbx8p-wfQ1OQ.jpeg" /></figure><p><em>Update: While this article was written only 4 months ago, AutoGen has since changed quite a bit. I apologize for some things that may be outdated in my code examples.</em></p><p>If you want to learn about AutoGen, there is <a href="https://microsoft.github.io/autogen/">documentation</a>, <a href="https://microsoft.github.io/autogen/docs/Examples">Colab notebooks</a>, and <a href="https://microsoft.github.io/autogen/blog">a blog</a>. Huge kudos to the AutoGen team for making an AMAZING product, but honestly — after reading all their stuff, I still didn’t know how to use AutoGen outside of a terminal or Jupyter Notebook.</p><p>This article tries to help fill that gap by giving some helpful ways to make AutoGen work in a software application. Here are the topics I’ll go over:</p><ol><li>Agents aren’t limited to communicating just over the terminal</li><li>Registering custom replies</li><li>How to include real humans in the conversation in real ways</li><li>You can (and should) customize who speaks next</li><li>You don’t have to use OpenAI</li><li>Functions can be used instead of executing code</li><li>Use Agents for organization, not just for conversations</li></ol><p>Lastly, I’ll go over why I think you should use AutoGen to begin with. Let’s go!</p><h3>Agents aren’t limited to communicating just over the terminal</h3><p>You’ll see everyone demo AutoGen using a terminal or Jupyter Notebook. That’s nice for a demo, but there are other ways these agents can talk to each other.</p><p>There are 2 basic AutoGen classes: <a href="https://github.com/microsoft/autogen/blob/40dbf31a925c725edb9124f4312c1703bf8744b0/autogen/agentchat/user_proxy_agent.py">UserProxyAgent</a> and <a href="https://github.com/microsoft/autogen/blob/main/autogen/agentchat/assistant_agent.py">AssistantAgent</a> . They inherit the <a href="https://github.com/microsoft/autogen/blob/40dbf31a925c725edb9124f4312c1703bf8744b0/autogen/agentchat/conversable_agent.py">ConversableAgent</a> class, providing just a few different default parameters to the base class.</p><p>When you see this classic code example:</p><pre>assistant = autogen.AssistantAgent(<br>    name=&quot;assistant&quot;,<br>    llm_config=llm_config<br>)<br>user_proxy = autogen.UserProxyAgent(name=&quot;user_proxy&quot;)<br>await user_proxy.a_initiate_chat(<br>    assistant,<br>    message=&quot;&quot;&quot;What date is today? Compare the year-to-date gain for META and TESLA.&quot;&quot;&quot;,<br>)</pre><p>what happens is that the UserProxyAgent will call its own send method, which will call AssistantAgent ‘s <a href="https://github.com/microsoft/autogen/blob/40dbf31a925c725edb9124f4312c1703bf8744b0/autogen/agentchat/conversable_agent.py#L514">receive</a> method, passing along the original message. A reply will be generated (more on that below), and AssistantAgent will now call its <a href="https://github.com/microsoft/autogen/blob/40dbf31a925c725edb9124f4312c1703bf8744b0/autogen/agentchat/conversable_agent.py#L351">send</a> method, which will then call UserProxyAgent ‘s receive method, and so forth, until UserProxyAgent determines the conversation is terminated (which can be customized via the is_termination_msg argument).</p><p>My first “aha” moment was when I realized these agents were classes, and I could create my own custom agent classes that inherit the AutoGen UserProxy/Assistant/Conversable Agent classes, and override any of the default methods. That makes AutoGen very extensible.</p><p>I had a use-case where I needed a human who could type in a message (proxied by UserProxyAgent) using a chat UI on a website, and I wanted an AssistantAgent to respond back to that chat in the UI, and be able to receive more messages from the human user, as though the human was just another agent in this AutoGen conversation.</p><p>I could override the send and receive methods (or a_send and a_receive), and push/pull over http, websockets, etc. I tried this, and it started to work, but doesn’t scale. Let’s learn a better way.</p><h3>Registering custom replies</h3><p>AutoGen has a plugin system that lets you customize how an agent generates a reply. We’re used to seeing examples where AutoGen queries OpenAI for an answer, and uses that as its reply, but you can insert your own methods as well:</p><pre>class WeatherAgent(AssistantAgent):<br>    def __init__(self, *args, **kwargs):<br>        super().__init__(*args, llm_config=False, **kwargs)<br>        self.register_reply(Agent, WeatherAgent.get_weather)<br><br>    async def get_weather(<br>        self,<br>        messages: List[Dict] = [],<br>        sender=None,<br>        config=None,<br>    ) -&gt; Tuple[bool, Union[str, Dict, None]]:<br>        last_message = messages[-1][&quot;content&quot;]<br>        result = await fetch_weather(last_message)<br>        return True, result<br><br>async def fetch_weather(city: str) -&gt; str:<br>    async with httpx.AsyncClient() as client:<br>        result = await client.post(<br>            WEATHER_API_URL,<br>            json={&quot;city&quot;: question},<br>        )<br>        return result.json()<br><br>weather_assistant = WeatherAgent(name=&quot;weather_assistant&quot;)<br>user_proxy = autogen.UserProxyAgent(name=&quot;user_proxy&quot;)<br>await user_proxy.a_initiate_chat(assistant, message=&quot;Lehi&quot;)<br>print(weather_assistant.last_message)</pre><p>Here, register_reply will insert my custom method for getting a reply, and by default, will put this method in position=0, meaning it will be the first reply method attempted. That method should return a tuple, where the first item is a boolean indicating if this reply is the one that should be used or whether to try the next registered_reply (such as the built-in reply generations using OpenAI — see the full order <a href="https://github.com/microsoft/autogen/blob/40dbf31a925c725edb9124f4312c1703bf8744b0/autogen/agentchat/conversable_agent.py#L145-L153">here</a>).</p><p>Knowing about <a href="https://github.com/microsoft/autogen/blob/40dbf31a925c725edb9124f4312c1703bf8744b0/autogen/agentchat/conversable_agent.py#L155">register_reply</a> allows you to customize how replies are retrieved, allow you to start sub multi-agent conversations, etc.</p><h3>How to include real humans in the conversation in real ways</h3><p>Here’s one way to do it:</p><pre># user makes a POST /query { &quot;message&quot;: &quot;What&#39;s the weather?&quot; }<br><br>@query_blueprint.route(&quot;/query&quot;, methods=[&quot;POST&quot;])<br>async def post_query():<br>  message = request.form.get(&quot;message&quot;)<br><br>  assistant = autogen.AssistantAgent(<br>    name=&quot;assistant&quot;,<br>    llm_config=llm_config<br>    system_message=&quot;&quot;&quot;You&#39;re a helpful assistant.<br>    If you need more info, ask the user for anything missing.&quot;&quot;&quot;<br>  )<br>  user_proxy = autogen.UserProxyAgent(<br>    name=&quot;user_proxy&quot;,<br>    human_input_mode=&quot;NEVER&quot;,<br>    code_execution_config=False,<br>    is_termination_msg=lambda message: True # Always True<br>  )<br>  weather_assistant = WeatherAgent(<br>    name=&quot;weather_assistant&quot;,<br>    system_message=&quot;&quot;&quot;You&#39;re a helpful assistant to get the weather.<br>    You fetch weather information, then return it.&quot;&quot;&quot;<br>  )<br><br>  groupchat = autogen.GroupChat(<br>    agents=[assistant, user_proxy, weather_assistant],<br>    messages=[]<br>  )<br>  manager = autogen.GroupChatManager(<br>    name=&quot;Manager&quot;,<br>    groupchat=groupchat,<br>    llm_config=llm_config,<br>  )<br><br>  await user_proxy.a_initiate_chat(manager, message=message)<br><br>  return groupchat.messages[-1]</pre><p>What’s going on here?</p><ol><li>Anytime a message is sent to user_proxy, the conversation will end (we’ll resume it later). Why do this? This means the user_proxy can actually proxy for the user. Rather than try to answer, it will end the current conversation flow and allow the real human user to respond (by resuming the conversation — see below).</li><li>If the assistant needs more info, it’ll ask user_proxy, which will end the current conversation.</li></ol><p>In the above code, what is likely to occur is something like this:</p><ol><li>user_proxy -&gt; manager: “What’s the weather?”</li><li>assistant -&gt; manager: “The user didn’t specify for which city.”</li><li>manager -&gt; user_proxy : conversation will end</li></ol><p>Now, if the user wants to respond and resume the conversation, how would we do that? There’s lots of ways to do this, here’s just a sample flavor:</p><pre># user makes a POST /query { &quot;message&quot;: &quot;What&#39;s the weather?&quot; }<br># above posts returns a `history` array<br># user makes a second POST /query { &quot;message&quot;: &quot;What&#39;s the weather?&quot;, &quot;history&quot;: history }<br><br>class ResumableGroupChatManager(GroupChatManager):<br>    groupchat: GroupChat<br><br>    def __init__(self, groupchat, history, **kwargs):<br>        self.groupchat = groupchat<br>        if history:<br>            self.groupchat.messages = history<br><br>        super().__init__(groupchat, **kwargs)<br><br>        if history:<br>            self.restore_from_history(history)<br><br>    def restore_from_history(self, history) -&gt; None:<br>        for message in history:<br>            # broadcast the message to all agents except the speaker.  This idea is the same way GroupChat is implemented in AutoGen for new messages, this method simply allows us to replay old messages first.<br>            for agent in self.groupchat.agents:<br>                if agent != self:<br>                    self.send(message, agent, request_reply=False, silent=True)<br><br>@query_blueprint.route(&quot;/query&quot;, methods=[&quot;POST&quot;])<br>async def post_query():<br>  message = request.form.get(&quot;message&quot;)<br><br>  assistant = autogen.AssistantAgent(<br>    name=&quot;assistant&quot;,<br>    llm_config=llm_config<br>    system_message=&quot;&quot;&quot;You&#39;re a helpful assistant.<br>    If you need more info, ask the user for anything missing.&quot;&quot;&quot;<br>  )<br>  user_proxy = autogen.UserProxyAgent(<br>    name=&quot;user_proxy&quot;,<br>    human_input_mode=&quot;NEVER&quot;,<br>    code_execution_config=False,<br>    is_termination_msg=lambda message: True # Always True<br>  )<br>  weather_assistant = WeatherAgent(<br>    name=&quot;weather_assistant&quot;,<br>    system_message=&quot;&quot;&quot;You&#39;re a helpful assistant to get the weather.<br>    You fetch weather information, then return it.&quot;&quot;&quot;<br>  )<br><br>  groupchat = autogen.GroupChat(<br>    agents=[assistant, user_proxy, weather_assistant],<br>    messages=[]<br>  )<br>  manager = ResumableGroupChatManager(<br>    name=&quot;Manager&quot;,<br>    groupchat=groupchat,<br>    llm_config=llm_config,<br>  )<br><br>  await user_proxy.a_initiate_chat(manager, message=message)<br><br>  return {<br>    &quot;response&quot;: groupchat.messages[-1],<br>    &quot;history&quot;: groupchat.messages,<br>  }</pre><p>Using this approach, you can now include humans as though they were just another agent in the groupchat. Anytime an assistant agent wants human input, they ask user_proxy, user_proxy then ends the current conversation, allowing the human user to respond with more information, then pick up the conversation where it left off.</p><p>The benefits to this approach are:</p><ul><li>Conversations can include real human input via any means you want (such as over http or websocket).</li><li>The conversation is stopped while getting human input. This frees up the thread for other conversations and computation.</li><li>You can persist these conversations across sessions.</li></ul><h3>You can (and should) customize who speaks next</h3><p>This is subjective, but I think you should always customize the way speakers are selected because:</p><ol><li>You’ll use less tokens (saves both $ and response time)</li><li>You can separate the logic that decides who speaks next from the logic that defines the system instructions for each agent</li></ol><pre>short_role_descriptions = {<br>  &quot;user_proxy&quot;: &quot;A proxy for the user&quot;,<br>  &quot;weather_assistant&quot;: &quot;You can get the weather&quot;,<br>  &quot;planner&quot;: &quot;You help coordinate the plan. Your turn happens when XYZ, but skip your turn when ABC&quot;<br>}<br><br>class CustomGroupChat(GroupChat):<br>    # The default message uses the full system message, which is a long string.  We are overriding this to use a shorter message.<br>    def select_speaker_msg(self, agents: List[Agent]):<br>        message = f&quot;&quot;&quot;You are in a role play game. The following roles are available:<br>        ---<br>        {new_line.join([f&quot;{agent.name}: {short_role_descriptions[agent.name]}&quot; for agent in agents])}<br>        ---<br><br>        The role who plays next depends on the conversation.  User_Proxy will star the conversation, and typically Planner would go next.<br><br>        Here are some examples<br>        ---<br>        ... not shown here ...<br>        ---<br><br>        Read the following conversation.<br>        Then select the next role from {&#39;, &#39;.join([agent.name for agent in agents])} to play. Only return the role.&quot;&quot;&quot;<br>        return message</pre><h3>You don’t have to use OpenAI</h3><p>AutoGen already notes you can use other LLMs, as long as they are “ChatGPT-like”, meaning their API responds with a similar shape and response as ChatGPT API calls.</p><p>But, remember how these agents are classes, and you can override most of the methods?</p><p>Try overriding the method: <a href="https://github.com/microsoft/autogen/blob/40dbf31a925c725edb9124f4312c1703bf8744b0/autogen/agentchat/conversable_agent.py#L678">generate_oai_reply</a>, and you can query any LLM you’d like.</p><h3>Functions can be used instead of executing code</h3><p>When I went to our security team and said “I’d like to use AutoGen for my service in Kubernetes. It needs to be able to execute any arbitrary code produced by an LLM. You’re ok with that, right?”</p><p>Of course, the answer was a definite: NO.</p><p>So, why use AutoGen without the auto-code-execution abilities?</p><p>On top of the reasons stated below, another is that you can use function calling to gain total control over code execution. If you have a set of python functions you want to provide to AutoGen — functions you wrote, control, and can accept some safe parameters — that sounds like a better idea anyway than the wild west of allowing any and all code to be executed in your private infrastructure.</p><h3>Use Agents for organization, not just for conversations</h3><p>Maybe you don’t have a need for an autonomous, multi-agent conversation. Maybe you just need to make a few different calls to an LLM.</p><p>I still like the idea of having different “Agents” just for the sake of organization. Here’s a really crazy idea, but take it for what it’s worth:</p><pre>analyst = autogen.AssistantAgent(<br>    name=&quot;Analyst&quot;,<br>    system_message=&quot;&quot;&quot;Your an analyst.  You do XYZ.&quot;&quot;&quot;,<br>    llm_config=llm_config,<br>)<br><br>summarizer = autogen.AssistantAgent(<br>    name=&quot;Summarizer&quot;,<br>    system_message=&quot;&quot;&quot;Your a summarizer.  You do XYZ.&quot;&quot;&quot;,<br>    llm_config=llm_config,<br>)<br><br>report = &quot;&quot;&quot;Some long report&quot;&quot;&quot;<br><br>analysis = analyst.generate_oai_reply(report)[1]<br>summary = summarizer.generate_oai_reply(report)[1]<br><br>print(f&quot;Analysis: {analysis}&quot;)<br>print(f&quot;Summary: {summary}&quot;)</pre><h3>Why use AutoGen?</h3><ol><li>AutoGen allows multiple agents, with different system prompts and instructions, to solve a problem. Just like in real-life, different perspectives working together will solve a problem better than a single brain.</li><li>AutoGen GroupChat is amazing. It provides routing to the right experts (agents), and it allows a conversation to continue autonomously until the problem is solved. Some conversations will go from agent: a-&gt;b-&gt;c-&gt;d, others will be b-&gt;a-&gt;d-&gt;c. This allows AutoGen to solve a variety of different problems without needing explicit rules for each scenario.</li><li>AutoGen can recover from mistakes. For example, I made an AutoGen-powered service that made API calls to a service. Sometimes, the API calls errored out because it didn’t send the right data at first. The AutoGen GroupChat kept trying different things until it succeeded. Sometimes, it took 4+ attempts, but my Planner agent didn’t give up — just pivoted autonomously to handle the API failures and try new things.</li><li>AutoGen came up with the concept of separating UserProxyAgents from AssistantAgent s from the beginning. This also allows us to let the user proxy actually proxy for the user, as shown above.</li><li>AutoGen is a well maintained library. Every week they’re adding something new.</li><li>AutoGen is very extensible. With the way they’ve built their classes, you can customize anything to your liking.</li><li>AutoGen has other features I don’t use, but others may find them helpful, such as helping you count tokens and cost of conversations, cacheing, etc.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8799185d27ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Latter-day Saint AI applications — Church Handbook summarization]]></title>
            <link>https://clintgoodman27.medium.com/latter-day-saint-ai-applications-church-handbook-summarization-f3534bb7b3e7?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3534bb7b3e7</guid>
            <category><![CDATA[latter-day-saints]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Sun, 08 Oct 2023 16:28:41 GMT</pubDate>
            <atom:updated>2023-10-08T16:28:41.645Z</atom:updated>
            <content:encoded><![CDATA[<h3>Latter-day Saint AI applications — Church Handbook summarization</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5MP5EqRq25GRvIPO81TmgA.jpeg" /></figure><p>One of the top functions Large Language Models (LLMs) do well is to summarize text. There are now many browser extensions that will summarize for you any news article, YouTube movie, PDF, or anything else on the Web.</p><p>So why not summarize chapters from <a href="https://www.churchofjesuschrist.org/study/manual/general-handbook">The Church General Handbook</a>? One of the problems are the token limits of LLMs. As of right now, <a href="https://claude.ai/">Claude.ai</a> has <a href="https://www.anthropic.com/index/100k-context-windows">one of the larger context window sizes</a>.</p><p>So, I went to the Church Handbook’s chapter on <a href="https://www.churchofjesuschrist.org/study/manual/general-handbook/10-aaronic-priesthood">the Aaronic Priesthood</a>. I saved the chapter as a PDF (if you go to print the page, you can then choose “Save as PDF”), uploaded it to <a href="https://claude.ai/">Claude.ai</a>, and asked this question for my prompt:</p><blockquote>I have attached a PDF. It is a PDF containing instructions on how to run a ward’s aaronic priesthood program. It mentions youth leaders (the Deacon Quorum President), his counselors and secretary. It also mentions adult leaders, such as the bishopric counselor, advisors, and specialists.</blockquote><blockquote>I’m having a hard time keeping all of the adult leader positions straight. I would like to see a detailed bullet point list showing all responsibilities of the bishopric counselor, then another list for the responsibilities of an adult advisor, then a list of responsibilities for the deacon quorum president. Can you please provide those detailed lists for me?</blockquote><p>The response was:</p><p>Here are the key responsibilities for each of those Aaronic Priesthood leaders:</p><p>Bishopric Counselor:</p><ul><li>Counsels with the Deacons Quorum president on how to fulfill his duties</li><li>Teaches the deacons about their quorum responsibilities</li><li>Attends deacons quorum presidency meetings</li><li>Attends deacons quorum meetings and activities</li><li>Interviews deacons periodically to discuss their spiritual growth</li><li>Oversees teaching in the deacons quorum</li><li>Helps plan deacons quorum service projects and activities</li></ul><p>Adult Advisor:</p><ul><li>Attends deacons quorum meetings and activities to support the bishopric counselor</li><li>Provides mentoring to deacons and teaches them how to lead</li><li>Helps the quorum president conduct meetings and activities</li><li>Participates in quorum lessons as requested</li><li>Ensures at least 2 adults are present at all quorum events</li></ul><p>Deacons Quorum President:</p><ul><li>Presides over quorum meetings</li><li>Welcomes new quorum members and helps returning members</li><li>Plans and conducts quorum lessons on Sundays</li><li>Plans service projects and activities for the quorum</li><li>Assigns deacons to pass the sacrament</li><li>Interviews prospective deacon quorum members</li><li>Calls 2 counselors and a secretary to serve with him in a presidency</li><li>Meets regularly with the quorum presidency to plan and coordinate quorum work</li></ul><p>Let me know if you would like me to expand or clarify anything in these responsibility lists. I’m happy to provide any other details that would be useful.</p><p>Pretty useful, huh?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3534bb7b3e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Latter-day Saint AI applications — General Conference speaker prediction]]></title>
            <link>https://clintgoodman27.medium.com/latter-day-saint-ai-applications-general-conference-speaker-prediction-cea3ea26b7bb?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cea3ea26b7bb</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[latter-day-saints]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Fri, 29 Sep 2023 01:16:02 GMT</pubDate>
            <atom:updated>2023-09-29T01:16:02.292Z</atom:updated>
            <content:encoded><![CDATA[<h3>Latter-day Saint AI applications — General Conference speaker prediction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fd7SrlFIuvk9aqfZTNRbIA.jpeg" /></figure><p>In my family, we played this game each General Conference where we all guessed which Apostles would speak in which General Conference sessions.</p><p>It was a fun game, till my dad and brother figured out there was a predictable pattern. Using spreadsheets, they could predict fairly accurately the next conference’s session line-up.</p><p>I never made the spreadsheet analysis myself. For the past year, I’ve been interested in using long short-term memory (LSTM) machine-learning models to learn the patterns instead. But then, I thought… can a Large Language Model (LLM) do all the work for me?</p><p>Using LLMs (like ChatGPT) for pattern prediction is ¹not a thoroughly examined topic, but it makes sense — wouldn’t a model that is designed to find patterns in text also be able to see patterns in sequences?</p><p><a href="https://chat.openai.com/share/9e46dd0a-0d0e-41dc-956b-7bdc64ca0d6c">Here is my ChatGPT-3.5 chat</a>. However, note that it did not summarize correctly near the end.</p><p>I also asked <a href="https://bard.google.com/">Google Bard</a> and <a href="https://claude.ai/">Claude.ai</a> as well. Here are the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7RCQAo7omYdESdCJX4YUFg.png" /></figure><p>I’m excited to see which LLM is most accurate in its predictions this week-end! Personally, the intersection of ChatGPT-4 and Claude.ai is the set I’m betting on.</p><p>Want to try this yourself? You can! <a href="https://chat.openai.com/">ChatGPT</a>, <a href="https://bard.google.com/">Google Bard</a> and <a href="https://claude.ai/">Claude.ai</a> are all available for you to use if you make a free account. ChatGPT-4 is not free.</p><p><em>Footnotes</em></p><p>¹ There has been a few articles on pattern prediction using LLMs, which you can read here:</p><ul><li><a href="https://towardsdatascience.com/applying-large-language-models-to-tabular-data-to-identify-drift-54c9fa59255f">https://towardsdatascience.com/applying-large-language-models-to-tabular-data-to-identify-drift-54c9fa59255f</a></li><li><a href="https://arxiv.org/pdf/2210.01848.pdf">https://arxiv.org/pdf/2210.01848.pdf</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cea3ea26b7bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Latter-day Saint AI applications — Part 1]]></title>
            <link>https://clintgoodman27.medium.com/latter-day-saint-ai-applications-part-1-984e5948e374?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/984e5948e374</guid>
            <category><![CDATA[latter-day-saints]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Sun, 24 Sep 2023 16:17:43 GMT</pubDate>
            <atom:updated>2023-09-27T22:55:26.062Z</atom:updated>
            <content:encoded><![CDATA[<h3>Latter-day Saint AI applications — Scripture study assistant</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3I06L-ZR88LX3WLyNsfZtA.jpeg" /></figure><p>I asked ChatGPT to list examples in the bible where Jesus Christ demonstrated the charity attributes listed in <a href="https://www.churchofjesuschrist.org/study/scriptures/bofm/moro/7?lang=eng&amp;id=45#p45">Moroni 7:45</a>.</p><p>Here is how I wrote the prompt to ChatGPT:</p><pre>You are a bible scholar.  You only report facts based on scripture from the King James Bible.  As a scholar, you cite your sources with the verses they come from in the Bible.<br><br>I have a comma separated list of attributes of Charity, which is the pure love of Christ.  I want you to address each attribute, and show examples where Jesus Christ demonstrated or taught about each principle.  List as many examples as you can for each attribute.<br><br>Here is the list:<br><br>```<br>And charity suffereth long, and is kind, and envieth not, and is not puffed up, seeketh not her own, is not easily provoked, thinketh no evil, and rejoiceth not in iniquity but rejoiceth in the truth, beareth all things, believeth all things, hopeth all things, endureth all things.<br>```</pre><p>Here is the response:</p><blockquote>Certainly, I’d be happy to provide examples of how Jesus Christ demonstrated or taught about each attribute of Charity based on the King James Bible.</blockquote><blockquote>1. **Charity suffereth long**:<br> — In Matthew 5:38–42, Jesus teaches about turning the other cheek and going the extra mile, showing patience and endurance in the face of adversity.</blockquote><blockquote>2. **Charity is kind**:<br> — In Luke 7:36–50, Jesus shows kindness to a sinful woman who anoints his feet with expensive ointment and forgives her sins.<br> — In Matthew 14:14, Jesus is moved with compassion and heals the sick who came to him.</blockquote><blockquote>3. **Charity envieth not**:<br> — In Mark 9:38–41, when the disciples tried to stop a man from casting out demons in Jesus’ name because he was not following them, Jesus corrected them, showing that he did not envy the man’s ability to perform miracles.</blockquote><blockquote>4. **Charity is not puffed up**:<br> — In Matthew 23:12, Jesus teaches, “And whosoever shall exalt himself shall be abased; and he that shall humble himself shall be exalted,” emphasizing the importance of humility over pride.</blockquote><blockquote>5. **Charity seeketh not her own**:<br> — In John 6:38, Jesus says, “For I came down from heaven, not to do mine own will, but the will of him that sent me,” indicating his selflessness and obedience to God’s plan.</blockquote><blockquote>6. **Charity is not easily provoked**:<br> — In Luke 23:34, even while being crucified, Jesus prays for forgiveness for those who crucify him, showing remarkable patience and lack of provocation.</blockquote><blockquote>7. **Charity thinketh no evil**:<br> — In Luke 23:34, Jesus prays for forgiveness for those who crucify him, exemplifying a lack of harboring ill thoughts or grudges.</blockquote><blockquote>8. **Charity rejoiceth not in iniquity but rejoiceth in the truth**:<br> — In John 8:1–11, when a woman caught in adultery was brought before Jesus, he did not rejoice in her sin but rather in the opportunity for her to turn away from it, saying, “Neither do I condemn thee: go, and sin no more.” This demonstrates a focus on truth and repentance.</blockquote><blockquote>9. **Charity beareth all things**:<br> — In Matthew 26:36–46, Jesus endures the agony of Gethsemane and willingly accepts his impending crucifixion for the sake of humanity.</blockquote><blockquote>10. **Charity believeth all things**:<br> — Jesus believes in the potential for change and redemption, as demonstrated in his interactions with sinners like Zacchaeus (Luke 19:1–10) and the woman caught in adultery (John 8:1–11).</blockquote><blockquote>11. **Charity hopeth all things**:<br> — In John 14:1–3, Jesus comforts his disciples by assuring them of a future hope, saying, “I go to prepare a place for you.”</blockquote><blockquote>12. **Charity endureth all things**:<br> — As the ultimate example, Jesus endures the crucifixion, bearing the weight of the sins of the world (Matthew 27:32–56).</blockquote><blockquote>These examples from the King James Bible illustrate how Jesus Christ embodied and taught the attributes of Charity, which is the pure love of Christ.</blockquote><p><a href="https://chat.openai.com/share/0f1c52c2-d0f2-4f83-82db-a71d6a88ce7d">You can see the full chat here</a>.</p><p>ChatGPT is free for anyone to use, give it a try!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=984e5948e374" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making sense of Jest v28 ESM support]]></title>
            <link>https://clintgoodman27.medium.com/making-sense-of-jest-v28-esm-support-fa5a2ff4af5a?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa5a2ff4af5a</guid>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[esm]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[import]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 21:40:19 GMT</pubDate>
            <atom:updated>2022-07-20T19:22:03.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*94uA4-MqX7L9yBWm2u3GHg.png" /><figcaption>Image used from jestjs.io</figcaption></figure><p>There is a trend to make NPM modules ESM only. I’ve ran across several today, here are 6 just for example that I ran across today: <a href="https://github.com/sindresorhus/tempy/releases/v2.0.0">tempy</a>, <a href="https://github.com/sindresorhus/pkg-dir/releases/v6.0.0">pkg-dir</a>, <a href="https://github.com/sindresorhus/execa/releases/v6.0.0">execa</a>, <a href="https://github.com/node-fetch/node-fetch/releases/tag/v3.0.0">node-fetch</a>, <a href="https://github.com/TooTallNate/node-data-uri-to-buffer/releases/tag/4.0.0">node-data-uri-to-buffer</a>, <a href="https://github.com/node-fetch/fetch-blob/releases/tag/3.0.0-rc.0">fetch-blob</a>.</p><p>Jest has some <a href="https://jestjs.io/docs/ecmascript-modules">experimental support for loading ESM files</a>. After reading their documentation, I figured what they were asking was not to use Babel with Jest (no transforms).</p><p>Nowadays, with Node supporting so much syntax natively, you can get away with not using a lot of Babel stuff with Jest. So, disabling transforms through Babel sounds achievable, especially if ESM is now supported in Jest.</p><p>With the huge exception of React. &lt;&gt; tags aren’t supported in JavaScript. You need Babel.</p><p>So, I can only think of a few options if your project has React in it:</p><ol><li><strong>Start making exceptions for transforms</strong></li></ol><p>This looks like this:</p><pre>transformIgnorePatterns: [&#39;/node_modules/(?!(node-fetch|fetch-blob|pkg-dir|tempy|execa))&#39;]</pre><p>Not very scalable, in my opinion.</p><p>2. <strong>Transform everything</strong></p><pre>transformIgnorePatterns: []</pre><p>This will make your test suite nice and slow. Not a great option.</p><p>3. <strong>Make sure Babel returns ESM modules</strong></p><p>Jest mentioned this in the ESM documentation:</p><blockquote>…or otherwise configure your transformer to emit ESM rather than the default CommonJS (CJS)</blockquote><p>But I had glanced over that part. Let me see if I can make it more clear.</p><p>If your Babel config transpiles modules into CJS, then it won’t work with this Jest setup. If it doesn’t, you can continue to use Babel.</p><p>@babel/preset-env has options that may be transpiling your code to CJS. In our project, that is the case.</p><p>In summary, for a working example, here is what this solution could look like for you:</p><pre>// babel.config.js<br>const IS_TEST = process.env.NODE_ENV === &quot;test&quot;;</pre><pre>const testConfig = {<br>  presets: [&quot;@babel/preset-react&quot;],<br>};</pre><pre>const prodConfig = {<br>  presets: [&quot;@babel/preset-env&quot;],<br>};</pre><pre>module.exports = IS_TEST ? testConfig : prodConfig;</pre><pre>// jest.config.js<br>// No need to change anything, you can keep Jest&#39;s defaults for transformIgnorePatterns, transform, and everything else</pre><pre>// package.json<br>&quot;scripts&quot;: {<br>  &quot;test&quot;: &quot;yarn node --experimental-vm-modules $(yarn bin jest)&quot;<br>}</pre><p>Another option your babel.config.js may look like is this:</p><pre>// babel.config.js<br>const IS_TEST = process.env.NODE_ENV === &quot;test&quot;;</pre><pre>module.exports = {<br>  presets: [[&quot;@babel/preset-env&quot;, { modules: !IS_TEST }]],<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa5a2ff4af5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A review: “Parenting”, the new startup]]></title>
            <link>https://clintgoodman27.medium.com/a-review-parenting-the-new-startup-982dc3e3aa9?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/982dc3e3aa9</guid>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 13:44:24 GMT</pubDate>
            <atom:updated>2022-04-25T13:44:24.095Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O3IbZsh5yHXS9E2BQGg6LQ.jpeg" /></figure><p>I’m a Dad at this startup people call “Parenting”. I’m CTO, my wife is CMO.</p><p>Our startup culture has some of the things you’d expect, and some differences.</p><p><strong>Project management</strong></p><p>At Parenting, we found waterfall didn’t work. At about the age of 13, customer feedback totally went against what we’d planned out at the beginning.</p><p>Kanban seemed attractive, but we live in Utah, and had a hard time sticking to a reasonable WIP limit of 2 children at a time.</p><p>So we go mainstream with scrum — but our sprint retros are ad hoc, sprint reviews are mostly for grandparents, and (similar to whatever company you work for) no matter how much it doesn’t actually follow the manifesto we call it agile anyway :)</p><p><strong>Extreme programming</strong></p><p>At Parenting, two people pairing on everything is the ideal. Initially we thought it’d be more efficient to use a standard Git flow. But, someone would open up a Pull Request, lots of comments would flow, some people skipped all that and simply merged and force pushed. Merge conflicts were left and not resolved. It was a mess. So, we adhere strictly to paired programming now.</p><p>Pro-tip: don’t let the kids trick you into mob programming.</p><p><strong>Releasing to production</strong></p><p>The release cycle here is much slower — 18 years or so. But, we commit beta stuff to production all the time, as there is no staging environment. Yes, everyone seems to notice the bugs. We put them in a backlog (which means they’ll never get worked on).</p><p>While there is no official QA team here, grandparents seem to do a decent job. Even when Product Owners think they have thought through all the requirements, it’s amazing the amount of edge cases your customers will find.</p><p>We do rely on the cloud via the prayer protocol.</p><p><strong>Culture</strong></p><p>Drawbacks:</p><ul><li>There is no PTO or sick time</li><li>You do work around the clock</li></ul><p>But:</p><ul><li>You’ll be taken care of in retirement</li><li>Small spot-bonuses are given frequently</li><li>You’ll have lots of room to grow and autonomy</li><li>You’ll have significant impact on the full team right away</li></ul><p>Simply put, I love it here. It’s the best startup I’ve ever worked at.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=982dc3e3aa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to mock the tricky things with Jest]]></title>
            <link>https://clintgoodman27.medium.com/how-to-mock-the-tricky-things-with-jest-8aaaa8fbb94c?source=rss-caacac710f6e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aaaa8fbb94c</guid>
            <category><![CDATA[constant]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[mock]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[test]]></category>
            <dc:creator><![CDATA[Clint Goodman]]></dc:creator>
            <pubDate>Thu, 03 Feb 2022 05:03:37 GMT</pubDate>
            <atom:updated>2022-02-03T05:35:02.394Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CM_u8r2g3i2De_rPW34ycg.png" /></figure><p>Here are 3 scenarios that I have found tricky to mock in Jest, and how I solved these problems. This article is about mocking, not about writing meaningful tests, so please don’t get caught up in the arbitrary test cases themselves.</p><p>I will only make a few comments. Most of the power comes from studying these code examples to see what is going on.</p><h3>Example 1 — Mocking imported constants by using lazy getters</h3><p>I’ve been stuck in this situation many times before:</p><pre>// app.js<br>import { someFunction, SOME_CONSTANT } from &#39;./someModule&#39;</pre><pre>export default function doSomething(){<br>  if (SOME_CONSTANT)<br>    someFunction(&#39;abc&#39;)<br>  else<br>    someFunction(&#39;xyz&#39;)<br>}</pre><pre>// app.test.js<br>import doSomething from &#39;./app&#39;</pre><pre>jest.mock(&#39;./someModule&#39;, () =&gt; ({<br>  someFunction: jest.fn(),<br>  SOME_CONSTANT: true,<br>}))</pre><pre>test.todo(&#39;when SOME_CONSTANT is true, this happens&#39;)</pre><pre>// How do we set up this scenario within this same test suite?<br>test.todo(&#39;when SOME_CONSTANT is false, this happens&#39;)</pre><p>We just assigned <strong>SOME_CONSTANT</strong> to be <strong>true</strong> for the whole test suite. How can we test when it is <strong>false</strong>? Most people don’t — they give up, and don’t write the second test case.</p><p>This is where I suggest a study of this simple lazy getter approach:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da63333a86696e011afa28ed89cd7576/href">https://medium.com/media/da63333a86696e011afa28ed89cd7576/href</a></iframe><p>Notes:</p><ul><li>Remember, this article is not about good code practices. These examples should tell your brain that the application code could use dependency injection, and this would eliminate the problem presented — and that is true. However, should you need to write a test of this nature for any reason, this lazy getter approach is helpful.</li></ul><h3>Example 2 — “Mocking” constants by substituting them</h3><p>I want to show an alternate solution to the problem above, and how to get away with mocking something which isn’t even imported:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0324c6749cdaaafdfd9e270798004ef8/href">https://medium.com/media/0324c6749cdaaafdfd9e270798004ef8/href</a></iframe><p>Notes:</p><ul><li>The idea here is that you can change the prop being passed to <strong>Router</strong> simply by catching the <em>real</em> call to <strong>Router</strong>, forwarding along the other props (like <strong>children</strong>), but passing your own prop for <strong>history</strong> instead. In this case, I simply call a mock that can return an object, which allows me to change what object gets passed in each test by changing the mock implementation. I won’t say much more about this, just study it a little closer, and appreciate the simple genius of it.</li></ul><h3>Example 3 — Testing hooks</h3><p>This is nothing fancy or new, but this is a pattern I’ve been using frequently. There are some cool npm packages just for testing hooks, which you can check out if you have advanced cases. But, 9/10 times for me, these few lines of code get the job done:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/693ddf02c3dceae0a1b779c1742c6661/href">https://medium.com/media/693ddf02c3dceae0a1b779c1742c6661/href</a></iframe><p>Notes:</p><ul><li>Notice the 3rd argument of <strong>jest.spyOn</strong>, and how to mock a read-only attribute like an element’s <strong>offsetWidth.</strong></li></ul><h3>Summary</h3><p>These are the answers I wish I would have found when I tried to Google some of the following things:</p><ul><li>“How to mock a constant in Jest”</li><li>“How to mock an element’s offsetHeight, offsetWidth, or other read-only attributes with Jest”</li><li>“How to partially mock with Jest”</li><li>“How to test the return value of a hook”</li></ul><p>If these examples helped you learn a new idea, please share it in a comment!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aaaa8fbb94c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>