返回 2026-05-12
⚙️ 工程

在脚本的 shebang 行中使用 LLMUsing LLM in the shebang line of a script

simonwillison.net·2026-05-11 节选正文

Simon Willison 探讨了将大型语言模型(LLM)直接嵌入脚本 shebang 行的可能性,这是一种前沿但极具实验性的编程实践。通过特定工具链,开发者现在可以在英文文本文件中设置 shebang 指向 LLM 解释器,实现自然语言驱动的自动化任务处理。该模式仍处于探索阶段,适合具备高度技术勇气的开发者尝试。

Simon Willison

Kim_Bruning on Hacker News:

But seriously, you can put a shebang on an english text file now (if you're sufficiently brave) [...]

This inspired me to look at patterns for doing exactly that with LLM. Here's the simplest:

#!/usr/bin/env -S llm -f
Generate an SVG of a pelican riding a bicycle

But you can also incorporate tool calls:

#!/usr/bin/env -S llm -T llm_time -f
Write a haiku that mentions the exact current time

Or even execute YAML templates directly that define extra tools as Python functions:

#!/usr/bin/env -S llm -t
model: gpt-5.4-mini
system: |
  Use tools to run calculations
functions: |
  def add(a: int, b: int) -> int:
      return a + b
  def multiply(a: int, b: int) -> int:
      return a * b

Then:

./calc.sh 'what is 2344 * 5252 + 134' --td

Which outputs (thanks to that --td tools debug option):

Tool call: multiply({'a': 2344, 'b': 5252})
  12310688

Tool call: add({'a': 12310688, 'b': 134})
  12310822

2344 × 5252 + 134 = **12,310,822**

Read the full TIL for a more complex example that uses the Datasette SQL API to answer questions about content on my blog.

需要完整排版与评论请前往来源站点阅读。