スクリプトのシェバング行に大規模言語モデルを使用する
本文の状態
日本語全文を表示中
詳細モードで約2分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Simon Willison Blog
開発者がテキストファイルの先頭にシェバング記述を追加し、LLM を直接実行可能にする実験的パターンを紹介した。
Continue in AI NEW LAB
このニュースを、実務の判断につなげる
AI NEW LABで、試したことや先に確認したい条件を共有できます。まずはログインなしで読めます。
AI NEW LABで論点を見るSource Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
Kim_Bruning 氏 Hacker News で:
でも本気で言えば、今や英語のテキストファイルにもシェバングを記述できるようになりました(十分に勇敢であれば)[...]
これに触発されて、LLM を用いてまさにそれを行うためのパターンを探ってみました。最もシンプルな例がこちらで、LLM フラグメントの機能を利用しています:
#!/usr/bin/env -S llm -f
ペリカンが自転車に乗っている SVG を生成してください
また、-T name_of_tool オプションを使用して ツール呼び出し も組み込むことができます:
#!/usr/bin/env -S llm -T llm_time -f
現在の正確な時刻を言及した俳句を書いてください
あるいは、追加のツールを Python 関数として定義する YAML テンプレートを直接実行することも可能です:
#!/usr/bin/env -S llm -t
model: gpt-5.4-mini
system: |
ツールを使用して計算を実行してください
functions: |
def add(a: int, b: int) -> int:
return a + b
def multiply(a: int, b: int) -> int:
return a * b
その後:
./calc.sh '2344 * 5252 + 134 はいくつですか' --td
と実行すると(この --td ツールデバッグオプションのおかげで)、以下のような出力が得られます:
ツール呼び出し:multiply({'a': 2344, 'b': 5252})
12310688
ツール呼び出し:add({'a': 12310688, 'b': 134})
12310822
2344 × 5252 + 134 = 12,310,822
ブログのコンテンツに関する質問に答えるために Datasette SQL API を使用した、より複雑な例については、こちら の TIL 全文をお読みください。
Tags: llm, llm-tool-use, llms, ai, generative-ai
原文を表示
TIL: Using LLM in the shebang line of a script
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, which takes advantage of LLM fragments:
#!/usr/bin/env -S llm -f
Generate an SVG of a pelican riding a bicycle
But you can also incorporate tool calls using the -T name_of_tool option:
#!/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 * bThen:
./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.
Tags: llm, llm-tool-use, llms, ai, generative-ai
関連記事
News to Guide
ニュースの次に確認する
発表内容を、現在の料金や仕様と照らし合わせられる関連ガイドです。
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み