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 (prefill) | { |
Assistant (Claude’s response) | “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 (prefill) | [Sherlock Holmes] |
Assistant (Claude’s response) | 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! |