技术洞察 1:批处理
我的理解
批处理是 AI 辅助编程最立竿见影的价值:通过向 ChatGPT 用自然语言描述需求、让其生成可运行代码,原本需要逐一手动点击的重复任务(如批量给 JIRA 工单添加评论)可以瞬间完成。这个例子揭示了 API 作为「机器与机器之间的接口」所蕴藏的系统化能力,而 GenAI 正是将自然语言指令翻译为 API 调用的桥梁,从而将这种能力向非开发者开放。批处理思维的本质是:把重复性劳动委托给计算机,解放人的注意力专注于真正需要判断力的事务。
相关链接
- Ch01-L05 技术洞察 2 GUI 与 API — 批处理背后的理论基础:GUI 与 API 的根本区别
- Ch02-L09 自动化的力量 以及生成式 AI 的角色 — 自动化的宏观价值与 GenAI 角色,是批处理的深化版
- Ch03-L02 项目 1 从 CVPR 会议官网抓取数据 — 实战项目:将批处理与编程思维应用于真实数据采集场景
原文
Lesson 4 of 68 技术洞察 1:批处理 / Technical Insight 1: Batch processing
批处理是编程中一个非常神奇的方面。我们每周都可能遇到一些重复性的任务,例如:
给 10 个 JIRA 工单添加评论。
发送 20 封邮件。
从 Tableau 收集 5 张图表并添加到 PowerPoint 幻灯片中。
我们以给 10 个 JIRA 工单添加评论为例。同样的方法也可以轻松应用到其他产品上。如果不借助编程,我们可能需要一位 JIRA 专家带我们一步步找到藏在第 6 级子菜单里的功能。而且我们往往只能寄希望于软件支持这一操作、它没有被隐藏在更高订阅档位之中、也不需要管理员审批。
而借助编程,事情就变得容易得多。到底有多容易?我们来看一个例子。我现在在一个 JIRA 项目中,里面有 5 个 JIRA 工单。
我想给这五个工单都添加一条评论:“Blocked for now. Waiting for approval.”(暂时被阻塞,等待审批。)使用过 JIRA 的人都知道,这有多繁琐。我们需要逐一找到并点击进入每个工单,粘贴或输入评论,点击确定,然后重复操作。这一过程单调、容易出错,还会打断我们的工作流。但现在我们有了另一个选择:编程。
那么,让我们来问问 ChatGPT:
示例提示词:
我有五个 JIRA 工单,TEST-13、TEST-14……TEST-17。如何使用 Python 给每个工单添加评论 “Blocked for now. Waiting for approval.”?
ChatGPT 给我们提供了一段代码并附上了解释。我们将代码复制粘贴到一个名为 comment.py 的文件中,修改 API key(稍后会详细说明),然后执行它。(图中的 URL、用户名和 API token 已做遮蔽处理,你需要填入你自己的信息。)
然后就完成了:
这与传统编程相比是天壤之别。这样的任务对于没有高级编程能力的人来说,可能需要数小时,甚至感觉根本无法完成。
一些补充说明:这种方法确实需要一些一次性的前置配置。其中一步是安装并配置 Python。正如课程要求中所述,我们假设你具备基本的 Python 知识——知道如何执行程序以及安装库。如果你需要复习,Python 的官方入门指南是一个不错的资源。另一项一次性配置是设置 API key。这同样很简单,你也可以让 ChatGPT 指导你如何获取。
我们也会在直播课中完整演示配置 API key 并执行程序的全过程。
这只是 API 强大能力的一次小小预览。API 是我们以系统化方式访问程序的入口——可以把 GUI 理解为面向人类,而 API 则是面向机器的。对于 Builder(创造者)思维而言,学会使用 API 至关重要。我们将在下一课中进一步展开这一话题。
English Original
Batch processing is a magical aspect of programming. Each week, we may encounter repetitive tasks such as:
Adding comments to 10 JIRA tickets.
Sending 20 emails.
Collecting 5 figures from Tableau and adding them to a PowerPoint slide deck.
Let’s take an example of adding a comment to 10 JIRA tickets. The same approach can easily be applied to other products. Without programming, we might need a JIRA expert to guide us to a feature buried in the 6th level submenu. Often, we’re left hoping the software allows us to do it, that it’s not hidden behind a higher-tier subscription, or doesn’t require admin approval.
With the power of programming, things become much easier. How easy? Let’s dive into an example. I’m in a JIRA project with 5 JIRA tickets.
I want to add a comment “Blocked for now. Waiting for approval.” to these five tickets. For those who have used JIRA, you know how tedious this can be. We need to find and click into each ticket, paste or write the comment, click OK, and repeat. It’s monotonous, error-prone, and disrupts our workflow. But now we have another option: programming.
So, let’s ask ChatGPT:
Example prompt:
I have five JIRA issues, TEST-13, TEST-14, …, TEST-17. How can I add a comment “Blocked for now. Waiting for approval.” to each of them using Python?
ChatGPT gives us some code with explanations. Let’s copy and paste the code into a file called comment.py, change the API key (more on that later), and execute it. (The URL, username, and API token in the figure are masked. You need to fill in your own information.)
Then it’s done:
It’s a huge difference compared with traditional programming. Such a task might take someone without advanced coding skills hours or even feel infeasible.
Some additional notes: This approach does require some one-time setup. One of the steps is to install and configure Python. As stated in the course requirements, we assume you have basic Python knowledge—knowing how to execute a program and install libraries. If you need a refresher, Python’s official beginner’s guide is a good resource. Another one-time setup is to configure an API key. This is also straightforward. You could also ask ChatGPT for guidance on obtaining it.
We will also demonstrate the complete process of configuring the API key and executing the program in the live session.
This is a sneak peek into the power of APIs. APIs are the gateways we use to access programs systematically—think of GUIs as being for humans, while APIs are for machines. For the builder mindset, it’s crucial that we learn how to use APIs. Let’s expand on this in the next lesson.