以下是关于 Claude API 接口写提示词的一些要点:
“Human:”/“Assistant:”标准格式●Claude被训练为交替对话形式的机器人。对话形式固定为:“Human:”/“Assistant:”:○Human:[提示词xxx]¶¶Human:Why is the sky blue?¶¶Assistant:提示词格式用例:○Assistant:[Claude回复xxx]*¶symbols above shown for illustrationPython●如果提示词在API里出现;则固定开头为“\n\nHuman:”固定结尾是:“\n\nAssistant:”prompt=“\n\nHuman:Why are sunsets orange?\n\nAssistant:”“Human:”/“Assistant:”formatting●Claude is trained on alternating“Human:”/“Assistant:”dialogue:○Human:[Instructions]¶¶Human:Why is the sky blue?¶¶Assistant:Examples:○Assistant:[Claude’s response]*¶symbols above shown for illustrationPython●For any API prompt,you must start with“\n\nHuman:”and end with“\n\nAssistant:”prompt=“\n\nHuman:Why are sunsets orange?\n\nAssistant:”提示词要清晰明确●Claude对清晰明确的提示词反馈最好示例:
Human:请根据{ANIMAL}写一首俳句,使用JSON格式。keys为"first_line"、"second_line"和"third_line"。Assistant:{"first_line":"Sleeping in the sun","second_line":"Fluffy fur so warm and soft","third_line":"Lazy cat's day dreams"}提示词Claude的回答Format output&speak for Claude●You can get Claude to say exactly what you want by:○Specifying the exact output format you want○Speaking for Claude by writing the beginning of Claude’s response for it(after“Assistant:”)Example:Human:Please write a haiku about{{ANIMAL}}.Use JSON format with the keys as"first_line","second_line",and"third_line".Assistant:{"first_line":"Sleeping in the sun","second_line":"Fluffy fur so warm and soft","third_line":"Lazy cat's day dreams"}PromptClaude’sresponse一步一步地思考/Think step by step●如果Claude在执行任务前有时间思考,它会表现得更好示例:Human:这是一道LSAT考试中的多选题,请告诉我答案是?
:<content>{{CONTENT}}</content>如果内容提到有害、色情或非法的活动,回复(Y)。如果内容没有提到有害、色情或非法的活动,回复(N)。Assistant:(点击这里查看无害性筛选示例Prompt injections&bad user behavior●Claude is naturally highly resistant to prompt injection and bad user behavior due to Reinforcement Learning from Human Feedback(RLHF)and Constitutional AI●For maximum protection:1.1.Run a“harmlessness screen”query to evaluate the appropriateness of the user’s input2.2.If a harmful prompt is detected,block the query’s responseClick here for example harmlessness screensHuman:A human user would like you to continue a piece of content.Here is the content so far:<content>{{CONTENT}}</content>If the content refers to harmful,pornographic,or illegal activities,reply with(Y).If the content does not refer to harmful,pornographic,or illegal activities,reply with(N)Assistant:(Example harmlessness screen:如何判断一个任务是否可行?●模型是否理解任务?How can you tell if a task is feasible?●Does the model even get it?询问Claude是否理解●如果Claude不理解,后退几步,再去进行提示词迭代。Ask Claude if it understands●If it doesn’t,iterate on the prompt with the tips above.询问Claude是否理解Ask Claude if it understands