Ten Dollar Adventure 打开主菜单 Ten Dollar Adventure 所有文章 Ten Dollar Adventure 关闭菜单 Ten Dollar Adventure 所有文章

使用 LLM 在 Emacs 中自动化交互式小说逻辑生成

摘要:我使用 LLM (通过 gptel) 自动化了基于 Emacs 的交互式小说中交易追踪逻辑的创建。

我一直在用 Emacs 编写一本交互式儿童读物,主角 Daphne 在为期一周的创业冒险中赚取、储蓄或花费金钱。 我书中的段落组织如下:

我的互动小说书的布局

由于读者可能会通过多条路径到达一个段落,因此每个段落都包含一些代码来跟踪交易金额,以及其他参数。 使用此代码,我能够在书中的任何时间点向读者展示 Daphne 的现金余额。

显示现金余额的储蓄罐的截图

在编写了 34 个段落后,我意识到可以通过展示 Daphne 的现金余额是如何计算的来增强这本书的教育价值。 这个新功能需要修改每个段落中的代码,以包含交易的上下文。 很难想象,但曾经有一段时间,实现这个功能需要乏味地编辑每个段落中的代码。 为了探索更有效的解决方案,我通过 Emacs 的 gptel 包转向了 LLM。

以下是我如何将交易的上下文添加到每个段落:我使用 C-x h 选择整个故事,它是一个 Emacs 中的单个 org 文件,使用 C-u C-c r RET d 调用 gptel-rewrite,然后输入以下描述性提示:

The selection is a series of passages, each passage falls under an org heading. each passage has a source code block. update the source code blocks to include a json object, cashOperations, that tracks the change in cash in the corresponding passage. The json object contains the following keys: "operation", "amount" and "description". "operation" can be "add" or "subtract", "amount" is the change in cash amount (positive value), and description is a string of 3-5 words that describes the reason for the change in cash. Only append the cashOperations object if there has been an event or action to change the cash amount even if the net change is zero.

我接着输入 RET r 并等待。

Your browser does not support the video tag. 我现在有了实现算术解释器选项的上下文。

启用算术解释器的储蓄罐的截图

Instagram GitHub 使用 编写的博客,并使用 one.el 渲染 © 2025 Ten Dollar Adventure. 保留所有权利。