iT邦幫忙

2025 iThome 鐵人賽

DAY 27
0
生成式 AI

我與 AI Pair Programming系列 第 27

我與 Raycast pair:AI Commands Prompt 的設定彈性

  • 分享至 

  • xImage
  •  

昨天我們瞭解到了如何建立 AI Commands,今天我們來一起看看更多進階的設定吧!

高彈性的 Prompt

讓我們先來看看 Prompt 的部分。可以看到 Prompt 輸入匡的右下角有一個 + 的按鈕,點下去會看到三個選項:
https://ithelp.ithome.com.tw/upload/images/20251011/20151635i180v7pvX1.png

這個是 Dynamic Placeholders(動態佔位符),是 AI Commands 的進階功能,讓我們的指令可以根據不同的輸入來源動態調整。

1. Selected Text:{selection}

這是最常用的 Placeholder,會自動抓取你目前選取的文字。如果這樣寫的話:

Translate {selection} to Traditional Chinese

當你選取一段英文文字並執行這個指令時,{selection} 會被替換成你選取的內容,AI 就會自動把文字翻譯成繁體中文。

2. Clipboard Text:{clipboard}

從剪貼簿讀取文字內容:

Format the following JSON data and make it more readable:

{clipboard}

這時候我們就可以複製一段 JSON 資料,然後執行這個指令,AI 就會幫你將 JSON 格式化並加上適當的縮排和說明。Raycast 還支援讀取剪貼簿歷史記錄:

  • {clipboard offset=1}:讀取倒數第二個複製的內容
  • {clipboard offset=2}:讀取倒數第三個複製的內容

如果設定 offset=1 就會讀到第二個內容:
https://ithelp.ithome.com.tw/upload/images/20251011/201516359obXkC0vXN.png

使用 AI format:
https://ithelp.ithome.com.tw/upload/images/20251011/20151635Ib14uxEnOU.png

3. Arguments:{argument}

Arguments 可以在執行時動態輸入參數,可以是單個參數:

Translate {selection} to {argument name="Target Language"}

在使用的時候可以透過 tab 移動到後方的參數區域,輸入內容:
https://ithelp.ithome.com.tw/upload/images/20251011/20151635ZUtcu1lIaS.png

我輸入的是簡體中文,按下 enter 後就會看到翻譯成簡體中文的結果:
https://ithelp.ithome.com.tw/upload/images/20251011/20151635A8oWjtHTn5.png

也可以輸入多個參數:

Write a blog post about {argument name="Topic"} for {argument name="Target Audience"}

另外,也能讓參數有預設值:

Print the input {argument name="Target" default="Default Print"}

https://ithelp.ithome.com.tw/upload/images/20251011/20151635UkxbSwsuHC.png

也可以使用 options 參數可以提供預設的選項清單

Print the input {argument name="Target" options="Default, default, DEFAULT"}

https://ithelp.ithome.com.tw/upload/images/20251011/20151635Fj52uk81l2.png

https://ithelp.ithome.com.tw/upload/images/20251011/20151635LOYs8taMpz.png

設定快捷鍵

Raycast 也有支援 AI Commands 設定快捷鍵的功能。打開設定後選擇 Extensions > Commands,找到你想設定的 command,點選 Record Hockey 就可以囉:
https://ithelp.ithome.com.tw/upload/images/20251011/201516352i8eTAN6Q5.png

加入修飾符

Raycast 還提供了一些修飾符(Modifiers),可以進一步幫我們處理 Placeholder 的內容:

  • {clipboard | uppercase}:將文字轉換為大寫
  • {clipboard | lowercase}:將文字轉換為小寫
  • {clipboard | trim}:移除前後的空白字元
  • {clipboard | percent-encode}:進行 URL 編碼
  • {selection | json-stringify}:將內容轉換為 JSON 字串格式

我們也可以透過 | 來串接多個修飾符:

{clipboard | trim | uppercase}

以上就是今天的分享,你覺得 AI Commans 還可以玩出什麼樣的變化呢?歡迎留言和我分享唷!我們明天見 👋


上一篇
我與 Raycast pair:第一個工具 —— AI Command
系列文
我與 AI Pair Programming27
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言