<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" 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" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title><![CDATA[ChatGPT - Rafael Quintanilha]]></title>
<description><![CDATA[Essays about software engineering, web development, artificial intelligence, quantitative analysis, financial markets, books and tradition.]]></description>
<link>https://rafaelquintanilha.com/topic/chatgpt/</link>
<image><url>https://rafaelquintanilha.com/content/images/2022/12/Logo-Design--2-.png</url><title>ChatGPT - Rafael Quintanilha</title><link>https://rafaelquintanilha.com/topic/chatgpt/</link></image>
<lastBuildDate>Wed, 21 May 2025 23:39:01 GMT</lastBuildDate>
<atom:link href="https://rafaelquintanilha.com/topic/chatgpt/rss/" rel="self" type="application/rss+xml"/>
<ttl>60</ttl>
<item>
<title><![CDATA[Using Codex as a task inbox]]></title>
<description><![CDATA[A proposed workflow to clear your backlog.]]></description>
<link>https://rafaelquintanilha.com/using-codex-as-a-task-inbox/</link>
<guid isPermaLink="false">682e5f188e5e1c000163d75c</guid>
<category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[ChatGPT]]></category>
<dc:creator><![CDATA[Rafael Quintanilha]]></dc:creator>
<pubDate>Wed, 21 May 2025 23:39:02 GMT</pubDate>

<content:encoded><![CDATA[<p>When <a href="https://openai.com/index/introducing-codex/" rel="noopener noreferrer" target="_blank">OpenAI first introduced Codex</a>, I must admit I wasn't very impressed. After all, <a href="https://rafaelquintanilha.com/is-claude-code-worth-the-hype-or-just-expensive-vibe-coding/">I've been a heavy user of Claude Code</a>, an AI model geared toward programming, which seems far superior. Moreover, with so many new tools popping up every other day, it becomes necessary to set boundaries and focus on just one thing.</p>
<p>However, I became slightly curious when they announced Codex was available on mobile. This was genuinely different. Claude Code is a CLI that runs on the terminal, while Cursor is an IDE requiring a reasonably decent computer. What could possibly be done on a phone?</p>
<p>Then I stumbled upon an <a href="https://zackproser.com/blog/openai-codex-review" rel="noopener noreferrer" target="_blank">excellent review of Codex by Zachary Proser</a>, highlighting its strengths and weaknesses. Finally, I was convinced — after all, what kind of hacker would I be if I didn't test all available tools? Besides, managing a blog and a <a href="https://www.youtube.com/c/quantbrasil" rel="noopener noreferrer" target="_blank">YouTube channel</a>, content creation is never too much...</p>
<p>But before diving into the strengths and weaknesses of this new tool, let's clarify: what <em>exactly</em> is Codex?</p>
<p>Let's start with OpenAI's own definition: <strong>Codex is a cloud-based software engineering agent</strong>. In other words, it's an agent capable of replicating the work of a software engineer (SWE).</p>
<p>This is where skepticism peaks. Recently, there have been numerous promises of AI replacing programmers. Despite this, such a scenario still feels distant. Indeed, models have improved significantly, and the speed of development combined with market competition makes optimists see this replacement as just a matter of time. But what does real-world practice tell us?</p>
<p>As mentioned, I've been a heavy user of AI tools. I'm also formally trained as a software engineer, working actively in the field, and thus deal with tasks beyond mere side projects where AI usually excels. Yet AI still doesn’t replace the formal work of a programmer in large-scale software teams.</p>
<p>The truth is, humans’ major advantage over machines is our capacity for abstract thinking — metaphysically speaking — which will always provide us with an edge over AI. Although over the course of its development, many who perform mediocrely — in the literal sense — might get left behind.</p>
<p>Therefore, I approach the promise of a software engineering agent with substantial skepticism. Sure, it can code. But can it abstract problems? Identify stakeholder preferences? Adhere to codebase standards? Suggest alternative approaches? Anticipate issues? The list goes on.</p>
<p>With all these considerations, I decided to test Codex, currently available only on ChatGPT's Pro plan (costing a modest $200/month), and ended up positively surprised. The entire testing process was documented on YouTube.</p>
<p><a href="https://youtu.be/79zBBZ2fLCo?si=npMbfmt6oWy1zkbm" rel="noopener noreferrer" target="_blank"><img alt="" loading="lazy" decoding="async" width="1280" height="720" src="https://rafaelquintanilha.com/_astro/ChatGPT-Codex---Primeiras-Impresso-es.BOIHpB3f_Z1RN3nT.webp"></a></p>
<h2 id="why-use-codex">Why use Codex?</h2>
<p>Straight to the point: what is Codex’s main advantage? In the article mentioned above, the author describes his ideal workday:</p>
<blockquote>
<p>"I'd like to start my morning in an office, launch a bunch of tasks, get some planning out of the way, and then step out for a long walk in nature."</p>
</blockquote>
<p>As a big advocate of reducing cognitive load at work, I completely understand his sentiment. Many everyday programming tasks are dull or mentally taxing: reading documentation, finding the correct file to fix a bug, adhering to unfamiliar standards, etc.</p>
<p>Additionally, anyone working on multiple projects (as I do with <a href="https://quantbrasil.com.br" rel="noopener noreferrer" target="_blank">QuantBrasil</a>, <a href="https://mmatrends.com.br" rel="noopener noreferrer" target="_blank">MMA Trends</a>, <a href="https://portalvasco.com.br" rel="noopener noreferrer" target="_blank">Portal Vasco</a>, and other toy projects) would appreciate being able to switch contexts without mental exhaustion. "<em>Context switching is the productivity killer,"</em> Elon Musk said.</p>
<p>Here's Codex's main advantage: as a <em>frictionless</em> cloud-based agent, you can delegate tasks to AI in parallel across multiple projects with minimal mental effort. With a generous limit of 60 tasks per hour (essentially unlimited), this tool acts as a <strong>brain dump</strong> or a <strong>task inbox</strong>, directly capturing ideas and transforming them immediately into actionable tasks.</p>
<h2 id="the-end-of-backlogs">The end of Backlogs</h2>
<p>Let me explain. When I have an idea for a feature, improvement, or bug fix, I typically need to record it somehow — usually using project management tools like Linear or Jira, or simply jotting it down in Obsidian or Notion. Later, this idea needs to become a task. But what if the act of recording <em>itself</em> became the task? That’s the world Codex promises.</p>
<p>You could dispatch multiple tasks and review them later, approving simpler ones quickly while dedicating more attention to the intricate ones. Obviously, this workflow depends on an AI competent in programming — and Codex’s <em>codex-1</em> model delivers.</p>
<p>However, the model used is fine-tuned to solve problems in one go, meaning iterating on a task isn't the most enjoyable experience. Each new iteration, if tested, becomes a new pull request — even within the same task. This makes the experience somewhat cumbersome, though I expect improvements soon.</p>
<h2 id="where-codex-excels">Where Codex excels</h2>
<p>So, the big question is: <em>where is Codex genuinely useful?</em> In its current form, the best use case is self-contained tasks with clear existing references in the codebase. For instance, adding a "last 90 days" filter to the <a href="https://mmatrends.com.br" rel="noopener noreferrer" target="_blank">MMA Trends</a> leaderboard was as simple as writing "add last 90 days to the leaderboard," and Codex identified and implemented the necessary changes.</p>
<figure class="image"><img alt="You don&#x27;t need to be a prompt master to leverage Codex." loading="lazy" decoding="async" width="1148" height="1432" src="https://rafaelquintanilha.com/_astro/image-2.r1T3nLvL_ZsWNpl.webp"><figcaption>You don't need to be a prompt master to leverage Codex.</figcaption></figure>
<p>Thus, minor additions, especially backend tasks or routine activities like refactoring components, adding unit tests, or making linter corrections, are excellent fits for this new agent.</p>
<h2 id="areas-for-improvement">Areas for improvement</h2>
<p>Naturally, there are many tasks not suitable for Codex. Particularly, elaborate frontend tasks don’t fit well since the agent doesn’t execute code, thus you are unable to see how it <em>looks</em> after the task is done. Consequently, creating PRs, checking out locally, requesting modifications, and iterating back-and-forth is cumbersome (forget about doing this in the woods).</p>
<p>Also, for security reasons, Codex doesn't have internet access after the environment setup, meaning updated documentation or interacting with external tools is out of scope. Thus, prompts must either be <em>precise</em> (which counters the promised practicality) or tasks <em>extremely simple</em> (like adding a button, moving text, or adding a filter).</p>
<h2 id="a-workflow-to-consider">A workflow to consider</h2>
<p>Finally, I'd like to propose a workflow designed to minimize cognitive load and still be practical for larger projects and complex features. Using Codex as a brain dump provides a starting point, albeit imperfect. Most tasks would still require refinement. But at this stage, there’s already existing code, context, and intention, making it easier to leverage a more appropriate model like Claude Code for further refinement.</p>
<p>I envision a scenario where I open Codex to find 5-10 tasks <em>ready for review</em> instead of facing a list of Jira tickets <em>to start from scratch</em>. The cognitive savings here are tremendous — <em>this</em> effectively transforms programmer productivity.</p>
<p>Ultimately, today isn’t the day AI replaces us. Is that day getting closer? Currently, Codex could competently replace an intern, handling small asynchronous tasks without much trouble. Tomorrow, its capabilities might extend to delegating even more complex problems.</p>
<p>Nevertheless, the ability to synthesize and abstract necessary to interact effectively with AI is increasingly valuable. Knowing how to express oneself, identify bottlenecks, and decide correctly when to use such tools remains crucial. Focus on these skills, and there's no need to fear Codex. On the contrary, when the day arrives when we no longer have to code, we can breathe a sigh of relief, finally liberated.</p>
<p><img alt="" loading="lazy" decoding="async" width="1080" height="1102" src="https://rafaelquintanilha.com/_astro/image-3.CQDbgOLA_1s5vLt.webp"></p>
<hr>
<p><a href="https://codecapital.substack.com/p/o-que-aprendi-usando-o-codex-o-agente-de-programacao-da-openai" rel="noopener noreferrer" target="_blank"><em>Originally published in Portuguese at Code Capital.</em></a></p>]]></content:encoded>
</item>
<item>
<title><![CDATA[Reducing churn with Stripe and ChatGPT]]></title>
<description><![CDATA[Leverage ChatGPT to communicate with your customers.]]></description>
<link>https://rafaelquintanilha.com/reducing-churn-with-stripe-and-chatgpt/</link>
<guid isPermaLink="false">670e7da7d8bba20001d2b680</guid>
<category><![CDATA[ChatGPT]]></category><category><![CDATA[Pipedream]]></category><category><![CDATA[Automation]]></category>
<dc:creator><![CDATA[Rafael Quintanilha]]></dc:creator>
<pubDate>Mon, 22 Jul 2024 14:38:00 GMT</pubDate>

<content:encoded><![CDATA[<p>Managing a SaaS is <em>hard</em>. Not only you need to develop an idea and battle for its adoption, constantly iterate and listen to user feedback, but also handle the back-office aspect of it. In particular, if you receive money in exchange of offered services, there is a plethora of zones to cover.</p>
<p>We tend to overspend efforts to attract new customers, while existing clients often overlooked. I, for one, am guilty of doing so. It may look counter-intuitive, but your existing customers are the ones you should be looking closer! Reducing churn is a guaranteed way to improve your compounded revenue over time.</p>
<p>Even if you have a customer hooked in a subscription model, the battle is not won. For one reason or another payments fail, and if you are not on top of your recurring customers, you are deemed to leave money in the table.</p>
<p>Automation is key for any small, fast-paced team, which is the standard in the SaaS industry. If you are able to offset boring back-office tasks to <a href="https://pipedream.com?via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">Pipedream</a>, you gain precious time to invest on your core product.</p>
<p>Today I want to guide you on how to build a pipeline that:</p>
<ol>
<li>Listens to any failed payment events from Stripe;</li>
<li>Uses ChatGPT to transform the often cryptic messages into friendly, human-readable emails;</li>
<li>Sends the email via Postmark.</li>
</ol>
<p>The goal is to give a personal touch to your customers, warming up the relationship when the unexpected happens, without losing the scalability that only an automated AI system can offer. Let's get to it!</p>
<h2 id="connecting-to-stripe">Connecting to Stripe</h2>
<p>For this guide we'll be connecting to Stripe, which is the leading platform for offering subscription-based products online.</p>
<p>Start by creating a new workflow and searching for <strong>Stripe</strong> as trigger. There are several interesting events that you can listen to, and today we'll select <strong>New Failed Payment.</strong></p>
<p><img alt="" loading="lazy" decoding="async" width="1856" height="998" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-07-15-at-16.49.35@2x.dghR9PGU_23FwT.webp"></p>
<p>Next, you will be prompted to connect your Stripe account. If you don't yet have one, now it's the time to go to the <a href="https://dashboard.stripe.com/apikeys" rel="noopener noreferrer" target="_blank">Developers section and select the API keys tab</a>. I recommend you start by checking the <strong>Test mode</strong> toggle at the top-right corner, so you can test with peace of mind.</p>
<p>Click <strong>Create restricted key</strong> and select the permissions you want to allow. It's always a good practice to make them as restrictive as possible, especially for sensitive matters. <em>Tip: if you are unsure on what to select, allow Read permission for the items on the Permissions column (the one in the left). It's not always clear what is needed for every webhook.</em></p>
<p>After you are done configuring your key, grab its value, add it to Pipedream, and once the connection is configured you will be greeted with a waiting screen.</p>
<p><img alt="" loading="lazy" decoding="async" width="1862" height="1018" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-07-15-at-17.00.02@2x.BWmtsP0g_1mKT6B.webp"></p>
<p>Great! The connection is successful and now Pipedream is listening to failed payment events.</p>
<h2 id="triggering-a-failed-payment">Triggering a failed payment</h2>
<p>There are several ways to trigger a failed payment, and thankfully it doesn't involve using a real card in production. The simplest solution is to configure a <a href="https://stripe.com/en-br/payments/payment-links" rel="noopener noreferrer" target="_blank">Payment Link</a>. Create one and you should see a portal like this:</p>
<p><img alt="" loading="lazy" decoding="async" width="2258" height="1412" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-07-15-at-17.05.46@2x.te6Dm5T5_1udGvf.webp"></p>
<p><em>Fun fact</em>: even OpenAI uses Payment Links to manage ChatGPT subscriptions. You really don't need to build it yourself if you don't want to.</p>
<p>Now, Stripe conveniently provides several test card numbers that are wired to trigger specific errors (<a href="https://docs.stripe.com/testing#declined-payments" rel="noopener noreferrer" target="_blank">see the full list</a>). Make sure you pick a card associated with a payment failure, provide any 3-digit number as CVC and select a valid date (anyone in the future is fine). Try to pay and if all goes well the payment will be declined and you should see it show up in Pipedream.</p>
<p><img alt="" loading="lazy" decoding="async" width="1846" height="1648" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-07-15-at-17.12.05@2x.CRkqGdpr_HeN3.webp"></p>
<p>We have everything we need from Stripe, now onto leveraging AI to extract relevant information from the API.</p>
<h2 id="generating-a-human-friendly-message">Generating a human-friendly message</h2>
<p>Stripe returns a huge JSON with several relevant metadata, including fields like <code>failure_code</code> and <code>failure_message</code>. But it also returns billing details, which holds the user name, email and address.</p>
<p>Technically we could write a code to extract everything needed, but that's a great use-case for an AI model like GPT-4o! Instead of fighting with all possible return cases, we should be able to feed the whole payload to the model and ask for a nicely-formatted JSON output.</p>
<p>In order to do that let's <em>stringify</em> everything in the <code>event</code> object of the trigger step. It's very easy to do it: hook a new step to the trigger and select <strong>Python</strong>. Add the following code:</p>
<figure class="code"><figcaption>python</figcaption><pre class="astro-code linha" style="background-color:#1b1814;color:#ecebe8; overflow-x: auto;" tabindex="0" data-language="python"><code><span class="line"><span style="color:#A1C1E4">def</span><span style="color:#EDCC95"> handler</span><span style="color:#ECEBE8">(pd: </span><span style="color:#97CCAE">"pipedream"</span><span style="color:#ECEBE8">):</span></span>
<span class="line"><span style="color:#A7A49E;font-style:italic">    # Reference data from previous steps</span></span>
<span class="line"><span style="color:#ECEBE8">    event </span><span style="color:#A1C1E4">=</span><span style="color:#ECEBE8"> pd.steps[</span><span style="color:#97CCAE">"trigger"</span><span style="color:#ECEBE8">][</span><span style="color:#97CCAE">"event"</span><span style="color:#ECEBE8">]</span></span>
<span class="line"><span style="color:#A7A49E;font-style:italic">    # Return data for use in future steps</span></span>
<span class="line"><span style="color:#A1C1E4">    return</span><span style="color:#ECEBE8"> {</span><span style="color:#97CCAE">"event"</span><span style="color:#ECEBE8">: </span><span style="color:#A1C1E4">str</span><span style="color:#EDCC95">(event)</span><span style="color:#ECEBE8">}</span></span></code></pre></figure>
<p>This is all we need. The result will be a really long string, hard to parse for humans, but hopefully an easy task for an AI!</p>
<p>Let's move forward by hooking a new step: select <strong>OpenAI (ChatGPT)</strong> from the list and next the <strong>Chat</strong> option. Make sure you have your OpenAI API key at hand if you haven't connected to it already.</p>
<p>As of this writing, the most capable ChatGPT model is the GPT-4o. Select it from the dropdown. Next, in <strong>User Message</strong>, pick the <code>event</code> object returned in the previous step. That's how it should look like <code>{{steps.python.$return_value.event}}</code>.</p>
<p>Now, we want the AI to return 3 values:</p>
<ol>
<li>The <em>email address</em> of the user we will contact;</li>
<li>The <em>subject</em> of the email;</li>
<li>The <em>content</em> of the message.</li>
</ol>
<p>This is a great use-case for using the <code>json_object</code> <strong>Response Format</strong>. By selecting this option we <em>force</em> the AI to return a parseable JSON, which will be handy later on.</p>
<p>The only thing left in this step is to write the <strong>System Instructions</strong>, which will nudge the model to answer the way we want. That's what I came up with:</p>
<figure class="code"><pre class="astro-code linha" style="background-color:#1b1814;color:#ecebe8; overflow-x: auto;" tabindex="0" data-language="plaintext"><code><span class="line"><span>Your job is to receive a JSON string, which happens when a Stripe payment fails, and craft an email that should feel personal, mention the reason the payment failed, suggest ways to fix it.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Extract the user email, create the subject, and the message, as it can be consumed by an API.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>The tone of the message should be friendly, without being too much.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>The response should also be in the JSON format and contain the fields: email, subject, message.</span></span></code></pre></figure>
<p><strong>Important:</strong> you need to <em>explicitly</em> say in the system instructions that you want the response as JSON whenever the response format is set to <code>json_object</code>.</p>
<p>Go ahead and test the integration. If all goes well, you can inspect the content:</p>
<p><img alt="" loading="lazy" decoding="async" width="1840" height="1542" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-07-16-at-10.30.48@2x.DyP5ey1P_23d4CL.webp"></p>
<p>This is a good time for you to adjust the tone of the message to better suit your use-case. You can also experiment with other failures and analyze how the model performs.</p>
<h2 id="parsing-the-ai-generated-json">Parsing the AI-generated JSON</h2>
<p>Once you are happy with the way the AI is crafting the message we are ready to finish the workflow by emailing the user.</p>
<p>Before we connect to <a href="https://pipedream.com/apps/postmark/actions/send-single-email?via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">Postmark</a>, which is my favorite email delivery service, we need to parse the JSON returned by the GPT model.</p>
<p>Add a new Python step (I named <em>python_json</em>) and paste the following code:</p>
<figure class="code"><figcaption>python</figcaption><pre class="astro-code linha" style="background-color:#1b1814;color:#ecebe8; overflow-x: auto;" tabindex="0" data-language="python"><code><span class="line"><span style="color:#A1C1E4">import</span><span style="color:#ECEBE8"> json</span></span>
<span class="line"><span style="color:#A1C1E4">def</span><span style="color:#EDCC95"> handler</span><span style="color:#ECEBE8">(pd: </span><span style="color:#97CCAE">"pipedream"</span><span style="color:#ECEBE8">):</span></span>
<span class="line"><span style="color:#A7A49E;font-style:italic">    # Reference data from previous steps</span></span>
<span class="line"><span style="color:#ECEBE8">    content </span><span style="color:#A1C1E4">=</span><span style="color:#ECEBE8"> pd.steps[</span><span style="color:#97CCAE">"chat"</span><span style="color:#ECEBE8">][</span><span style="color:#97CCAE">"$return_value"</span><span style="color:#ECEBE8">][</span><span style="color:#97CCAE">"original_messages_with_assistant_response"</span><span style="color:#ECEBE8">][</span><span style="color:#97CCAE">2</span><span style="color:#ECEBE8">][</span><span style="color:#97CCAE">"content"</span><span style="color:#ECEBE8">]</span></span>
<span class="line"><span style="color:#A7A49E;font-style:italic">    # Return data for use in future steps</span></span>
<span class="line"><span style="color:#A1C1E4">    return</span><span style="color:#ECEBE8"> json.</span><span style="color:#EDCC95">loads(content)</span></span></code></pre></figure>
<p>And now, as easy as that, the JSON is formatted and ready to be consumed by the email API.</p>
<p><img alt="" loading="lazy" decoding="async" width="1840" height="1210" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-07-16-at-10.36.20@2x.BpXXNAi__1ElvKC.webp"></p>
<h2 id="sending-the-email-with-postmark">Sending the email with Postmark</h2>
<p>Let's wrap up this guide by creating our final step: search for <strong>Postmark</strong> and then select <strong>Send Single Email</strong>. <em>Note: you can also choose Send Email With Template if you already have one configured.</em></p>
<p>The next steps are easy: connect to your Postmark account (you will need an <a href="https://account.postmarkapp.com/api_tokens" rel="noopener noreferrer" target="_blank">API token</a> for a server. It's also a good idea to have a dev server where you can experiment before going live). Finally, all required fields were generated in the previous step, with the exception of the <em>"From" email address</em>, which you should select from your <a href="https://account.postmarkapp.com/signature_domains" rel="noopener noreferrer" target="_blank">Sender Signatures</a> in Postmark.</p>
<p><img alt="" loading="lazy" decoding="async" width="1852" height="1422" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-07-16-at-10.43.00@2x.CbG9O4Dq_ZEmnc0.webp"></p>
<p>Go ahead and test the integration. The email with the custom AI-generated message will be visible in Postmark.</p>
<p><img alt="" loading="lazy" decoding="async" width="2202" height="1772" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-07-16-at-10.45.13@2x.CqhObnL9_2ngYMn.webp"></p>
<h2 id="next-steps">Next steps</h2>
<p>I hope that this guide sparks your creativity. While we barely touched all possible integrations made possible by Pipedream, a few follow-ups include:</p>
<ul>
<li>Use the same principle but do the reverse: <a href="https://pipedream.com/apps/stripe/triggers/new-subscription?via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">contact every new subscriber</a> with a custom AI-generated message;</li>
<li><a href="https://pipedream.com/apps/stripe/triggers/canceled-subscription?via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">Connect with the user whenever a subscription is cancelled</a> offering a deal for them to come back;</li>
<li>If the user phone number is present in the Stripe payment form, <a href="https://pipedream.com/apps/twilio/actions/send-sms?via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">send a SMS message using Twilio</a>.</li>
</ul>]]></content:encoded>
</item>
<item>
<title><![CDATA[Classifying bug reports with ChatGPT]]></title>
<description><![CDATA[Integrate Airtable + ChatGPT + Slack using the power of Pipedream.]]></description>
<link>https://rafaelquintanilha.com/classifying-bug-reports-with-chatgpt/</link>
<guid isPermaLink="false">670e7b27d8bba20001d2b65b</guid>
<category><![CDATA[ChatGPT]]></category><category><![CDATA[Automation]]></category><category><![CDATA[Pipedream]]></category>
<dc:creator><![CDATA[Rafael Quintanilha]]></dc:creator>
<pubDate>Thu, 28 Mar 2024 14:26:00 GMT</pubDate>

<content:encoded><![CDATA[<p>There is nothing dreaded more by programmers than bugs. Well, actually it's probably either <a href="https://martinfowler.com/bliki/TwoHardThings.html" rel="noopener noreferrer" target="_blank">naming things or cache invalidation</a>, but you see my point. Bugs show up at unwelcome times, perhaps when you are deep on a totally different problem.</p>
<p>If not properly handled, bugs can slow down an engineering team considerably. Context switching is expensive for any cognitive task. If you code, you know what I'm talking about. And if you haven't, then listen to Elon Musk.</p>
<figure class="embed embed-twitter" data-url="https://platform.twitter.com/embed/Tweet.html?creatorScreenName=webquintanilha&#x26;dnt=false&#x26;embedId=twitter-widget-0&#x26;features=eyJ0ZndfdGltZWxpbmVfbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&#x26;frame=false&#x26;hideCard=false&#x26;hideThread=false&#x26;id=1728213431201792492&#x26;lang=en&#x26;origin=https%3A%2F%2Fpipedream.com%2Fblog%2Fclassifying-bug-reports-with-chatgpt%2F&#x26;sessionId=d1d5a63c61277d4529493336dc9b58cbee19c41c&#x26;siteScreenName=pipedream&#x26;theme=light&#x26;widgetsVersion=2615f7e52b7e0%3A1702314776716&#x26;width=550px">
<blockquote class="twitter-tweet"><a href="https://twitter.com/i/status/1728213431201792492" rel="noopener noreferrer" target="_blank">https://twitter.com/i/status/1728213431201792492</a></blockquote>
</figure>
<p>So there are two problems to reconcile: 1) context switching kills developer productivity, but 2) bugs happen. How can we deal with this reality?</p>
<p>One way to tackle this is by enforcing proper prioritization. This is certainly easier said than done, but modern tooling and Pipedream can help.</p>
<p>In this post, we'll create an automated workflow that will:</p>
<ol>
<li>Trigger on new bug reports</li>
<li>Use ChatGPT to classify the report based on the user description</li>
<li>Update the priority accordingly</li>
<li>Send a Slack notification <em>if and only if</em> the bug is deemed as <strong>Urgent</strong>.</li>
</ol>
<p>That's a lot of unpack, so let's get started!</p>
<h3 id="configuring-airtable">Configuring Airtable</h3>
<p>For this example we'll use Airtable as our database. Airtable lets us create public forms, shareable with anyone on the Internet. It also provides its own automation framework, which we'll use to trigger the <a href="https://pipedream.com/new?h=tch_1AfMbY&#x26;via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">Pipedream workflow</a>.</p>
<p>Start by creating a new base and a table inside it. I chose the fields <em>Title, Description, Name, Email</em> and <em>Priority</em>. <em>Priority</em> will be a <a href="https://support.airtable.com/docs/single-select-field" rel="noopener noreferrer" target="_blank">Single Select</a> field, holding a set of values that we'll pass to ChatGPT as the options for the classification.</p>
<p><img alt="" loading="lazy" decoding="async" width="3024" height="1868" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-03-23-at-15.17.38@2x-2.Be2tRW58_Z89MsU.webp"></p>
<p>Now, there are two possible approaches for adding new records.</p>
<p>First, you can add a custom <a href="https://support.airtable.com/docs/button-field" rel="noopener noreferrer" target="_blank">Button</a> to the table (see our post on how to <a href="https://pipedream.com/blog/sharp-js-compatibility/?via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">Slice and dice images with Sharp.js</a>). Here, Airtable sends an HTTP <code>GET</code> request to a Pipedream-generated URL, passing the record ID as query parameter. While it works beautifully, this means the workflow can be triggered only from <em>within</em> Airtable. In this post, we want to allow <em>anyone</em> to submit a report, e.g. a user affected by the bug.</p>
<p>You can also create a <a href="https://support.airtable.com/docs/building-and-sharing-forms-in-airtable" rel="noopener noreferrer" target="_blank">Form</a>. This can be shared publicly, sending an event when any user submits a bug.</p>
<p><a href="https://support.airtable.com/docs/building-and-sharing-forms-in-airtable" rel="noopener noreferrer" target="_blank">Create a form in Airtable</a> and adjust it to your use case. Don't forget to hide the <em>Priority</em> field, as it will be filled by the AI. You should end up with something like this:</p>
<p><img alt="" loading="lazy" decoding="async" width="2000" height="1204" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-03-23-at-18.04.30@2x.HKqJzxxK_Z1ujQF8.webp"></p>
<p>Great, now we have a working form storing bug reports. Now, let's configure our trigger.</p>
<h3 id="triggering-the-workflow">Triggering the workflow</h3>
<p>We want form submissions to trigger our workflow. To do that, we need to configure a <em>webhook</em>.</p>
<p>In Pipedream, create a new workflow and select <strong>HTTP / Webhook > HTTP Requests with a Body</strong>. Data from the form sent by Airtable will be available in the body of the HTTP request in Pipedream. You don't need to change anything in the configuration — clicking <strong>Save and continue</strong> and you'll receive a URL like <a href="https://eoqb6ojri6uulck.m.pipedream.net/" rel="noopener noreferrer" target="_blank">https://eoabc123def456.m.pipedream.net</a>.</p>
<p>Head back to Airtable and create a new automation. Similar to Pipedream, Airtable also requires a trigger, which here will be <strong>When a form is submitted</strong>. Next, select the table and the recently-created form.</p>
<p>The next step is the only coding necessary in this tutorial. Click on <strong>Add advanced logic or action > Run script</strong>. On the panel on the left, click on <strong>Add input variable</strong> and name and select all fields submitted via the form. Don't forget to also add the <em>Airtable record ID</em>, once it will be needed later.</p>
<p>Add the following in the code editor, replacing the content of <code>WEBHOOK_URL</code> with the URL provided before:</p>
<figure class="code"><figcaption>javascript</figcaption><pre class="astro-code linha" style="background-color:#1b1814;color:#ecebe8; overflow-x: auto;" tabindex="0" data-language="javascript"><code><span class="line"><span style="color:#A1C1E4">const</span><span style="color:#ECEBE8"> WEBHOOK_URL </span><span style="color:#A1C1E4">=</span><span style="color:#97CCAE"> 'https://your-endpoint.m.pipedream.net'</span></span>
<span class="line"></span>
<span class="line"><span style="color:#EDCC95">fetch</span><span style="color:#ECEBE8">(WEBHOOK_URL, {</span></span>
<span class="line"><span style="color:#ECEBE8">  method: </span><span style="color:#97CCAE">'POST'</span><span style="color:#ECEBE8">,</span></span>
<span class="line"><span style="color:#ECEBE8">  headers: {</span></span>
<span class="line"><span style="color:#97CCAE">    'Content-Type'</span><span style="color:#ECEBE8">: </span><span style="color:#97CCAE">'application/json'</span><span style="color:#ECEBE8">,</span></span>
<span class="line"><span style="color:#ECEBE8">  },</span></span>
<span class="line"><span style="color:#ECEBE8">  body: </span><span style="color:#EDCC95">JSON.stringify</span><span style="color:#ECEBE8">(</span><span style="color:#EDCC95">input.config</span><span style="color:#ECEBE8">()),</span></span>
<span class="line"><span style="color:#ECEBE8">})</span></span></code></pre></figure>
<p>Great! You can click on <strong>Test action</strong>, and, if a record has been previously selected, you'll receive its content in Pipedream.</p>
<p><img alt="" loading="lazy" decoding="async" width="1864" height="1366" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-03-23-at-18.23.32@2x.DNh_RTXA_Z1LQtK4.webp"></p>
<p>Let's recap what we did so far.</p>
<ol>
<li>We created a Pipedream workflow whose trigger is a webhook which provides a unique URL;</li>
<li>We created a form in Airtable that inserts records into a table called <em>Bug Reports;</em></li>
<li>We added an <em>Airtable automation</em> triggered on form submissions;</li>
<li>This automation runs a script that sends a <code>POST</code> request along with the submitted data to the webhook URL generated in step 1.</li>
</ol>
<p><img alt="" loading="lazy" decoding="async" width="1548" height="1055" src="https://rafaelquintanilha.com/_astro/image-1.C5PNpbn4_20D17T.webp"></p>
<h3 id="classifying-the-priority-of-the-bug">Classifying the priority of the bug</h3>
<p>Now we're ready to classify the priority of the bug. Let's remember the goal: we want to classify the content of the bug report and notify the developers only when OpenAI detects urgency.</p>
<p>Back in Pipedream, create a new step in your workflow and select the <strong>OpenAI (ChatGPT)</strong> app. Conveniently, Pipedream has an action to <strong>Classify Items into Categories</strong>, which will work for simple classification use cases. Here, we'll use the <strong>Chat</strong> action instead; this gives us more control over the API request, which is key here.</p>
<p>If you don't have one, you'll need an <a href="https://platform.openai.com/api-keys" rel="noopener noreferrer" target="_blank">OpenAI API key</a>. In Pipedream, click the button to add a new <strong>OpenAI (ChatGPT)</strong> account and add the API key there.</p>
<p>Next, select the <em>Model</em> you want to use for classifications. If bug reports are not <em>so</em> frequent in your application, then we recommend choosing <code>gpt-4-turbo-preview</code>, the most-accurate model for classifications as of this post.</p>
<p>In the <em>User Message</em> field, pick the <code>description</code> sent in the body of the request.</p>
<p>Finally, we'll set the <em>System Instructions</em>. System instructions guide how the AI answers prompts. Add the following:</p>
<figure class="code"><pre class="astro-code linha" style="background-color:#1b1814;color:#ecebe8; overflow-x: auto;" tabindex="0" data-language="plaintext"><code><span class="line"><span>Your tasks is to receive a bug report from a user and classify into ONE of the following categories:</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Urgent</span></span>
<span class="line"><span>High</span></span>
<span class="line"><span>Medium</span></span>
<span class="line"><span>Low</span></span>
<span class="line"><span></span></span>
<span class="line"><span>You should ONLY output the chosen category, and nothing else.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Notice that an "Urgent" report is anything that prevents users from:</span></span>
<span class="line"><span>- Accessing their account;</span></span>
<span class="line"><span>- Paying, subscribing, or generally taking revenue-impacting actions.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>This is the description of the bug reported by the user:</span></span></code></pre></figure>
<p>Notice that the categories provided match the priorities expected in Airtable. The instruction explicitly asks the model to return the category and <em>only</em> the category. We also give examples of urgent requests in order to nudge the AI to our specific use-case. Feel free to adjust the instructions with examples pertinent to your application.</p>
<p><em>Note: the pre-made Classify Items into Categories will instruct the LLM to output a JSON, which is very convenient when parsing the output in a code context, but not necessary here.</em></p>
<p>Because of the stochastic character of any AI, we cannot guarantee it will always return one of the 4 categories, though more powerful models are significantly better at adhering to the prompt. There's an extra trick we can do, too. The <a href="https://platform.openai.com/tokenizer" rel="noopener noreferrer" target="_blank">Tokenizer</a> app allows us to simulate how many tokens a given text is expected to yield. It happens that <em>Urgent</em> takes 3 tokens, while all other categories are successfully encoded with a single one. Hence, we can <em>limit</em> the maximum number of tokens allowed in the completion.</p>
<p>Finally, adjust <strong>Temperature</strong> to 0 (we want as little randomness as possible in the outcome) and <strong>N</strong> to 1, and the step is complete.</p>
<p><img alt="" loading="lazy" decoding="async" width="1264" height="1636" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-03-23-at-19.20.28@2x.BzPjv24S_1cW1yD.webp"></p>
<p>Click on <strong>Test</strong> to run the step, and if all is well, you should see the category selected by the LLM.</p>
<p><img alt="" loading="lazy" decoding="async" width="1776" height="1412" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-03-23-at-19.24.35@2x.DLF9S18j_ZXONXA.webp"></p>
<h3 id="updating-the-airtable-record">Updating the Airtable record</h3>
<p>Now that the classifier works, let's update the record in Airtable.</p>
<p>Add a new step to the workflow, search for "<em>airtable</em>", and select the <strong>Airtable (OAuth)</strong> app. Click the <strong>Update Record</strong> action. The configuration is straightforward – connect your account and select your <em>Base</em> and <em>Table</em>.</p>
<p>For <em>Record ID</em>, we will need the <code>id</code> from the trigger step. The field we want to update is <em>Priority,</em> and the content is the generated message from the previous step.</p>
<p>The <em>update_record</em> step should look like this:</p>
<p><img alt="" loading="lazy" decoding="async" width="1868" height="1392" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-03-25-at-09.00.05@2x.DawIrEZa_1K6d6J.webp"></p>
<h3 id="conditionally-send-slack-message">Conditionally send Slack message</h3>
<p>Finally, we'll send a message to Slack. Recall that we want to send notifications <em>only if</em> on <em>Urgent</em> issues. Luckily, Pipedream makes this process a breeze by providing a <strong>Continue based on condition</strong> step: the workflow will only continue if the configured condition is met, else it ends.</p>
<p>You'll need to configure three fields: <em>Initial value, Condition,</em> and <em>Second value.</em></p>
<p>For <em>Initial value</em>, select the same output used when updating Airtable – this will be the category. The <em>Second value</em> is the target priority, i.e., <em>Urgent</em>. Finally, select <em>TEXT_EQUALS</em> as the condition. In order to prevent unnecessary misclassifications, make sure <em>Case sensitive</em> is False as well.</p>
<p><img alt="" loading="lazy" decoding="async" width="1864" height="1140" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-03-25-at-09.13.21@2x.2xVJJon4_1CXYCh.webp"></p>
<p>Now the workflow will only continue if the AI classifies the report exactly as <em>Urgent</em> (case insensitive). Let's wrap this tutorial up by creating the final step: <strong>Slack > Send Message to a Public Channel</strong>. Connect your account, select the <em>Channel ID</em> from the list, and use the data sent from Airtable to craft a message to your beloved developers.</p>
<p><img alt="" loading="lazy" decoding="async" width="1396" height="698" src="https://rafaelquintanilha.com/_astro/CleanShot-2024-03-25-at-09.17.50@2x.DDhnoAFz_9wdME.webp"></p>
<p>And that's it! Deploy the Pipedream workflow and don't forget to turn on the Airtable automation. Open the publicly-shareable Airtable form and submit a desperate request in order to receive the notification.</p>
<h3 id="next-steps">Next steps</h3>
<p>A great enhancement to this workflow is to send an automatic email to the user, letting them know that the report has been received.</p>
<p>Pipedream has a convenient <a href="https://pipedream.com/apps/gmail?via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">Gmail integration</a> that can be used for this purpose. For a more custom experience, you can leverage the <a href="https://pipedream.com/apps/postmark/actions/send-email-with-template?via=rafael-quintanilha-blog" rel="noopener noreferrer" target="_blank">Postmark</a> integration (my go-to platform for sending templated emails).</p>]]></content:encoded>
</item>
</channel>
</rss>
