Assistant
訊息來引導其回應。這種強大的技術允許您指導 Claude 的行動,跳過前言,強制特定格式如 JSON 或 XML,甚至幫助 Claude 在角色扮演場景中保持角色一致性。
在某些 Claude 表現不如預期的情況下,幾句預填的句子可以極大地改善 Claude 的表現。一點預填就能產生很大的效果!
Assistant
訊息中包含所需的初始文本(Claude 的回應將從 Assistant
訊息結束的地方繼續):
"As an AI assistant, I "
這樣的預填(末尾有空格)將導致錯誤。{
強制 Claude 跳過前言並直接輸出 JSON 對象。這更乾淨、更簡潔,並且更容易被程式解析而無需額外處理。範例:不使用預填的結構化數據提取
角色 | 內容 |
---|---|
User | Extract the name, size, price, and color from this product description as a JSON object: <description> The SmartHome Mini is a compact smart home assistant available in black or white for only $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other connected devices via voice or app—no matter where you place it in your home. This affordable little hub brings convenient hands-free control to your smart devices. </description> |
Assistant | Here’s the extracted information in JSON format: ```json { “name”: “SmartHome Mini”, “size”: “5 inches wide”, “price”: “$49.99”, “colors”: [“black”, “white”] } ``` I’ve extracted the following details from the product description: - Name: SmartHome Mini - Size: 5 inches wide - Price: $49.99 - Colors: Available in black and white The JSON object provides a structured format that’s easy for programs to parse and use. Let me know if you need any modifications or have any other questions! |
範例:使用預填的結構化數據提取
角色 | 內容 |
---|---|
User | Extract the name, size, price, and color from this product description as a JSON object: <description> The SmartHome Mini is a compact smart home assistant available in black or white for only $49.99. At just 5 inches wide, it lets you control lights, thermostats, and other connected devices via voice or app—no matter where you place it in your home. This affordable little hub brings convenient hands-free control to your smart devices. </description> |
Assistant (預填) | { |
Assistant (Claude 的回應) | “name”: “SmartHome Mini”, “size”: “5 inches wide”, “price”: “$49.99”, “colors”: [ “black”, “white” ] } |
[角色名稱]
可以提醒 Claude 保持角色,即使在更長和更複雜的對話中也是如此。當與 system
參數中的角色提示結合使用時,這特別強大。範例:不使用角色提示保持角色
角色 | 內容 |
---|---|
User (與”福爾摩斯”Claude 進行了 50 輪對話) | What do you deduce about the owner of this shoe? <image>muddy_shoe.jpg</image> |
Assistant | As an AI assistant, I would be happy to analyze the image of a muddy shoe as if you had provided it. Here’s my deduction… |
範例:使用角色提示保持角色
角色 | 內容 |
---|---|
User (與”福爾摩斯”Claude 進行了 50 輪對話) | What do you deduce about the owner of this shoe? <image>muddy_shoe.jpg</image> |
Assistant (預填) | [Sherlock Holmes] |
Assistant (Claude 的回應) | Ah, what have we here? A most curious specimen, Watson! Let us examine this shoe with a discerning eye. The mud, you see, is not your common London clay, but rather the distinctive reddish hue of the iron-rich soil found only in the environs of Hampstead Heath. And yet, the wear on the sole suggests a gait more suited to the cobblestones of Whitechapel than the gentle slopes of the Heath. Now, observe the laces! They are tied with a particular knot favored by those in the medical profession—doubtless a habit acquired during years of tying surgical gowns. But the scuff marks on the toe box tell a different tale: they are consistent with the kicking motion one might employ in the martial arts, specifically Baritsu. We may conclude, then, that our absent shoe owner is a doctor, possibly a surgeon, who resides in Whitechapel but frequents Hampstead Heath—perhaps for a secret Baritsu practice, away from prying eyes. A most intriguing case, Watson! We must make haste; the game is afoot! |