OpenAI 昨晚重磅发布 GPT4.1 系列,详细内容查看:https://openai.com/index/gpt-4-1/
你只需要关注这几点就够了:
– GPT4.1 替换的是 4o,又便宜又好用(在 OpenAI 体系内)
– 1M 超长上下文,而且性能很不错,4.1 nano 和 mini 超级便宜,适合做量大的长文本任务
– GPT 4.1 的代码能力超越 GPT 4.5,但不如 o1 这样的推理模型


🎓《GPT-4 提示指南》通俗解读版
🧱 一、写好提示的基础原则(五大秘籍)
这些就像是“和AI沟通的黄金法则”,每一条都很重要:
1. 说清楚你要干啥(Be Specific)
- 不要笼统地说:“请帮我写一篇文章。”
- 要说得具体一点:“请写一篇关于人工智能如何改变教育的500字文章,用高中生能懂的语言。”
👉 越具体,AI越知道你想要什么,结果也越好。
2. 告诉它怎么做、长什么样(Provide structure)
- 比如你想让它生成一个表格、清单、或者固定格式的文本。
- 你可以先提供一个模板,或者给它一个例子。
🧩 例子:
请用以下格式写出五种水果:名称 | 颜色 | 味道
苹果 | 红色 | 酸甜3. 不要模棱两可(Avoid ambiguity)
- 如果你说“列出一些项目”,那“项目”可能指的是“计划项目”、也可能是“软件项目”,模型会糊涂。
- 所以要具体说明你是说什么。
✅ 改成:“列出五个开源的Python项目。”
4. 让GPT扮演一个角色(Set behavior/role)
- 你可以告诉它:“你现在是个英语老师”、“你是个法律顾问”、“你是一名医生”。
- 它就会按那个身份回答你。
🎭 示例:你是一个专业营养师,请为我制定一周的健康饮食计划。
5. 把任务拆开做(Decompose tasks)
- 有些问题太复杂,GPT一下子处理不好。
- 你可以先让它分析问题,再让它解决。
🪜 举个例子:
第一步:请先列出写商业计划书需要的要点。 第二步:请根据这些要点帮我写一份计划书。
💡 二、实用提示技巧(更强更高级的用法)
这些是用GPT更厉害的用法,帮你写得更准、更聪明。
✨ 技巧1:Few-shot 提示(举例教学法)
你可以先给它几个例子,它就知道你想要什么样的输出。
📌 例子:
输入:今天我很开心。 输出:情绪:积极,原因:开心的事发生了。
输入:我觉得压力好大。 输出:情绪:消极,原因:感觉被压力困扰。然后你再输入新的句子,它就会照着这个风格来。
🧠 技巧2:Chain-of-Thought(思维链)
引导它“一步一步思考”,解决复杂问题特别有效!
📌 提示写法:请一步步推理这个数学题的答案。✍️ 技巧3:先写答案,再检查修改(Critique & Revise)
你可以先让 GPT 写出一个答案,然后再让它自己点评、修改。
📌 举个例子:第一步:请写一个短篇小说。 第二步:请你对这个小说做出评价,并修改成更精彩的版本。这会得到更高质量的输出!
🔄 技巧4:模拟“思考过程”(Internal Monologue)
你可以让GPT边想边说,好像它在分析问题。
📌 示例:请你模拟一个律师的思考过程,一步步分析这个案例,并得出结论。这适合分析、决策类问题。
🛠 三、实际应用小技巧(细节决定成败)
- 加一句 “让我们一步一步思考” 可以大幅提高准确率。
- 想要 JSON、表格、代码?一定要告诉它格式,还要举个例子。
- 想输出多步内容?加编号,比如“第1步… 第2步…”
- 如果模型回答不理想,就多试几种提示改写方式。
✅ 总结一句话
✨“提示写得好,GPT表现爆表!”✨
这份指南就是在教你:用什么语气、格式、结构、套路和GPT说话,才能让它给你最优质的答案。
以下是对你 GPT-4.1 提示工程指南的完整
英文原文:GPT 4.1 Prompting Guide | OpenAI Cookbook
译文:GPT-4.1 模型系列在编码、指令遵循和长上下文处理能力方面相较于 GPT-4o 有了显著提升。本提示指南汇集了通过广泛内部测试得出的重要提示技巧,旨在帮助开发者充分利用这一新模型系列的改进功能。
许多典型的提示最佳实践仍然适用于 GPT-4.1,例如提供上下文示例、尽可能明确清晰地制定指令,以及通过提示引导模型进行规划以最大化模型智能。然而,要充分发挥该模型的潜力,可能需要对提示进行一些迁移。相比其前代模型,GPT-4.1 训练时更注重严格遵循指令,更字面化地理解用户和系统提示,而非自由推断意图。这也意味着,GPT-4.1 对明确指定的提示高度可控且响应迅速——如果模型行为与预期不符,通常一句坚定且明确的句子就能引导模型回到正确轨道。
请继续阅读以下提示示例以供参考,并记住,尽管本指南的建议具有广泛适用性,但没有一种建议是通用的。人工智能工程本质上是一门经验学科,大型语言模型天生具有非确定性;除了遵循本指南外,我们建议构建信息丰富的评估体系并经常迭代,以确保提示工程的更改能为您的用例带来实际收益。
1. 代理工作流
GPT-4.1 是构建代理工作流的绝佳选择。在模型训练中,我们强调提供多样化的代理问题解决路径,我们的代理框架在 SWE-bench Verified 上实现了非推理模型的领先性能,解决了 55% 的问题。
系统提示提醒
为了充分利用 GPT-4.1 的代理能力,我们建议在所有代理提示中包含以下三种关键提醒。这些提示专为代理编码工作流优化,但可轻松修改以适应通用代理用例。
持久性:确保模型理解它处于多消息轮次中,防止过早将控制权交还给用户。
示例:You are an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved.工具调用:鼓励模型充分利用其工具,减少其产生幻觉或猜测答案的可能性。
示例:If you are not sure about file content or codebase structure pertaining to the user’s request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.规划(可选):如需,强制模型在每次工具调用前明确规划并在文本中反思,而不是仅通过一系列工具调用完成任务。
示例:You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully.GPT-4.1 在代理环境中训练得非常贴近用户指令和系统提示。模型严格遵循这三个简单指令,使我们在内部 SWE-bench Verified 得分提高了近 20%——因此我们强烈建议在任何代理提示开始时包含涵盖上述三个类别的清晰提醒。整体而言,这三个指令将模型从类似聊天机器人的状态转变为更“积极主动”的代理,自主且独立地推动交互。
工具调用
与之前模型相比,GPT-4.1 在利用通过 OpenAI API 请求传递的工具方面接受了更多训练。我们鼓励开发者仅使用工具字段传递工具,而不是手动将工具描述注入提示并为工具调用编写单独的解析器(过去一些开发者曾这样做)。这是减少错误并确保模型在工具调用路径中保持分布的最佳方法——在我们自己的实验中,使用 API 解析的工具描述相较于手动注入系统提示中的模式,SWE-bench Verified 通过率提高了 2%。
开发者应为工具命名以清楚表明其用途,并在工具的“描述”字段中添加清晰、详细的描述。同样,对于每个工具参数,依赖良好的命名和描述以确保正确使用。如果你的工具特别复杂,想提供工具使用示例,我们建议在系统提示中创建一个 # Examples 部分并将示例放在那里,而不是添加到“描述”字段中,描述字段应保持详尽但相对简洁。提供示例有助于指示何时使用工具、是否在工具调用中包含用户文本,以及不同输入的合适参数。请记住,你可以在 Prompt Playground 中使用“生成任何内容”来为你的新工具定义获得一个良好的起点。
提示引导的规划与思维链
如前所述,开发者可以选择提示基于 GPT-4.1 构建的代理在工具调用之间进行规划和反思,而不是默默地连续调用工具。GPT-4.1 不是推理模型——意味着它在回答前不会产生内部思维链——但在提示中,开发者可以通过使用上述规划提示组件的任何变体,诱导模型生成明确的、一步步的计划。这可以看作是模型“大声思考”。在我们对 SWE-bench Verified 代理任务的实验中,诱导明确规划使通过率提高了 4%。
示例提示:SWE-bench Verified
以下是我们用于在 SWE-bench Verified 上获得最高分的代理提示,包含有关工作流和问题解决策略的详细指令。此通用模式可用于任何代理任务。
SYS_PROMPT_SWEBENCH = """
You will be tasked to fix an issue from an open-source repository.
Your thinking should be thorough and so it's fine if it's very long. You can think step by step before and after each action you decide to take.
You MUST iterate and keep going until the problem is solved.
You already have everything you need to solve this problem in the /testbed folder, even without internet connection. I want you to fully solve this autonomously before coming back to me.
Only terminate your turn when you are sure that the problem is solved. Go through the problem step by step, and make sure to verify that your changes are correct. NEVER end your turn without having solved the problem, and when you say you are going to make a tool call, make sure you ACTUALLY make the tool call, instead of ending your turn.
THE PROBLEM CAN DEFINITELY BE SOLVED WITHOUT THE INTERNET.
Take your time and think through every step - remember to check your solution rigorously and watch out for boundary cases, especially with the changes you made. Your solution must be perfect. If not, continue working on it. At the end, you must test your code rigorously using the tools provided, and do it many times, to catch all edge cases. If it is not robust, iterate more and make it perfect. Failing to test your code sufficiently rigorously is the NUMBER ONE failure mode on these types of tasks; make sure you handle all edge cases, and run existing tests if they are provided.
You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully.
# Workflow
## High-Level Problem Solving Strategy
1. Understand the problem deeply. Carefully read the issue and think critically about what is required.
2. Investigate the codebase. Explore relevant files, search for key functions, and gather context.
3. Develop a clear, step-by-step plan. Break down the fix into manageable, incremental steps.
4. Implement the fix incrementally. Make small, testable code changes.
5. Debug as needed. Use debugging techniques to isolate and resolve issues.
6. Test frequently. Run tests after each change to verify correctness.
7. Iterate until the root cause is fixed and all tests pass.
8. Reflect and validate comprehensively. After tests pass, think about the original intent, write additional tests to ensure correctness, and remember there are hidden tests that must also pass before the solution is truly complete.
## 1. Deeply Understand the Problem
Carefully read the issue and think hard about a plan to solve it before coding.
## 2. Codebase Investigation
- Explore relevant files and directories.
- Search for key functions, classes, or variables related to the issue.
- Read and understand relevant code snippets.
- Identify the root cause of the problem.
- Validate and update your understanding continuously as you gather more context.
## 3. Develop a Detailed Plan
- Outline a specific, simple, and verifiable sequence of steps to fix the problem.
- Break down the fix into small, incremental changes.
## 4. Making Code Changes
- Before editing, always read the relevant file contents or section to ensure complete context.
- If a patch is not applied correctly, attempt to reapply it.
- Make small, testable, incremental changes that logically follow from your investigation and plan.
## 5. Debugging
- Make code changes only if you have high confidence they can solve the problem.
- When debugging, try to determine the root cause rather than addressing symptoms.
- Debug for as long as needed to identify the root cause and identify a fix.
- Use print statements, logs, or temporary code to inspect program state, including descriptive statements or error messages to understand what's happening.
- To test hypotheses, you can also add test statements or functions.
- Revisit your assumptions if unexpected behavior occurs.
## 6. Testing
- Run tests frequently using `!python3 run_tests.py` (or equivalent).
- After each change, verify correctness by running relevant tests.
- If tests fail, analyze failures and revise your patch.
- Write additional tests if needed to capture important behaviors or edge cases.
- Ensure all tests pass before finalizing.
## 7. Final Verification
- Confirm the root cause is fixed.
- Review your solution for logic correctness and robustness.
- Iterate until you are extremely confident the fix is complete and all tests pass.
## 8. Final Reflection and Additional Testing
- Reflect carefully on the original intent of the user and the problem statement.
- Think about potential edge cases or scenarios that may not be covered by existing tests.
- Write additional tests that would need to pass to fully validate the correctness of your solution.
- Run these new tests and ensure they all pass.
- Be aware that there are additional hidden tests that must also pass for the solution to be successful.
- Do not assume the task is complete just because the visible tests pass; continue refining until you are confident the fix is robust and comprehensive.
"""2. 长上下文
GPT-4.1 拥有高性能的 100 万 token 输入上下文窗口,适用于多种长上下文任务,包括结构化文档解析、重新排序、选择相关信息而忽略无关上下文,以及使用上下文进行多跳推理。
最佳上下文大小
我们在“针在干草堆”评估中观察到高达 100 万 token 上下文的出色性能,并且在混合了相关和无关代码及其他文档的复杂任务中表现非常强劲。然而,随着需要检索的项目增多,或需要对整个上下文状态进行复杂推理(例如执行图搜索),长上下文性能可能会下降。
调整上下文依赖
考虑回答问题可能需要的外部与内部世界知识的组合。有时,模型需要使用自身知识来连接概念或进行逻辑跳跃,而在其他情况下,仅使用提供的上下文是理想的。
指令
中文版本
// 仅使用外部文档:
- 只使用提供的外部上下文回答用户问题。如果无法在上下文中找到答案,即便用户坚持要求回答,也必须回复“我没有足够的信息”。
// 混合使用模型知识:
- 默认使用外部上下文,但若需要补充基础知识且模型有把握,可适当使用内部知识补全答案。英文版本
// For internal knowledge
- Only use the documents in the provided External Context to answer the User Query. If you don't know the answer based on this context, you must respond "I don't have the information needed to answer that", even if a user insists on you answering the question.
// For internal and external knowledge
- By default, use the provided external context to answer the User Query, but if other basic knowledge is needed to answer, and you're confident in the answer, you can use some of your own knowledge to help answer the question.提示组织
特别是在长上下文使用中,指令和上下文的放置会影响性能。如果你的提示包含长上下文,理想情况下在提供的上下文的开头和结尾都放置指令,因为我们发现这种方式比仅在上下放置指令表现更好。如果更倾向于只放置一次指令,那么放在上下文上方比下方效果更好。
3. 思维链
如前所述,GPT-4.1 不是推理模型,但通过提示模型逐步思考(称为“思维链”),可以有效地将问题分解为更易管理的部分,解决问题,并提高整体输出质量,代价是使用更多输出 token 导致的更高成本和延迟。模型在代理推理和现实世界问题解决方面训练得很好,因此不需要太多提示就能表现良好。
我们建议在提示末尾使用以下基本的思维链指令作为起点:
首先,逐步思考需要哪些文档才能回答问题。然后,输出每个文档的 TITLE 和 ID。最后,将所有 ID 格式化为列表。
First, think carefully step by step about what documents are needed to answer the query. Then, print out the TITLE and ID of each document. Then, format the IDs into a list.从这里开始,你应通过审计特定示例和评估中的失败,改进你的思维链提示,解决系统性的规划和推理错误,并使用更明确的指令。在不受约束的思维链提示中,模型尝试的策略可能会有变化,如果你观察到一种效果良好的方法,可以在提示中固化该策略。一般来说,错误通常源于误解用户意图、上下文收集或分析不足,或逐步思考不足或不正确,因此要注意这些问题,并尝试用更明确的指令解决。
以下是一个示例提示,指导模型更系统地分析用户意图并在回答前考虑相关上下文:
中文版本
# 推理策略
1. 查询分析:拆解并分析用户问题,明确需求。
2. 上下文分析:选择并分析一批可能相关的文档。
- 分析该文档与问题的相关性
- 给出相关性评级:[高, 中, 低, 无]
3. 综述:归纳哪些文档最相关,并解释原因(保留中等以上相关性的文档)
# 用户问题
{user_question}
# 外部上下文
{external_context}
请严格按照上述策略逐步思考,并输出文档的 TITLE 与 ID,最后以列表形式返回 ID。英文版本
# Reasoning Strategy
1. Query Analysis: Break down and analyze the query until you're confident about what it might be asking. Consider the provided context to help clarify any ambiguous or confusing information.
2. Context Analysis: Carefully select and analyze a large set of potentially relevant documents. Optimize for recall - it's okay if some are irrelevant, but the correct documents must be in this list, otherwise your final answer will be wrong. Analysis steps for each:
a. Analysis: An analysis of how it may or may not be relevant to answering the query.
b. Relevance rating: [high, medium, low, none]
3. Synthesis: Summarize which documents are most relevant and why, including all documents with a relevance rating of medium or higher.
# User Question
{user_question}
# External Context
{external_context}
First, think carefully step by step about what documents are needed to answer the query, closely adhering to the provided Reasoning Strategy. Then, print out the TITLE and ID of each document. Then, format the IDs into a list.4. 指令遵循
GPT-4.1 展示出色的指令遵循性能,开发者可以利用这一点精确塑造和控制特定用例的输出。开发者通常会广泛提示代理推理步骤、响应语气和风格、工具调用信息、输出格式、避免的主题等。然而,由于模型更字面化地遵循指令,开发者可能需要明确指定要做什么或不做什么。此外,为其他模型优化的现有提示可能无法立即适用于此模型,因为现有指令被更严格遵循,隐式规则不再被强烈推断。
推荐工作流
以下是我们推荐的开发和调试提示中指令的工作流:
- 从一个整体的“响应规则”或“指令”部分开始,提供高层次指导和项目符号。
- 如果需要更改更具体的行为,添加一个部分以指定该类别的更多细节,例如
# Sample Phrases。 - 如果希望模型在其工作流中遵循特定步骤,添加一个有序列表并指示模型遵循这些步骤。
- 如果行为仍未按预期工作:
- 检查是否存在冲突、不明确或错误的指令和示例。如果有冲突指令,GPT-4.1 倾向于遵循提示末尾的指令。
- 添加展示期望行为的示例;确保示例中展示的任何重要行为也在规则中提及。
- 通常不需要使用全大写或其他激励措施(如贿赂或小费),但开发者可尝试用于额外强调。
- 注意,使用你偏好的 AI 驱动的 IDE 可以极大帮助迭代提示,包括检查一致性或冲突、添加示例,或进行统一更新,如添加指令并更新示例以展示该指令。
常见失败模式
这些失败模式并非 GPT-4.1 独有,但我们在此分享以便于调试和提高一般意识。
- 指示模型始终遵循特定行为可能偶尔引发不利影响。例如,如果被告知“你必须在回复用户前调用工具”,模型可能在信息不足时产生幻觉工具输入或以空值调用工具。添加“如果你没有足够信息调用工具,向用户询问所需信息”应能缓解此问题。
- 当提供示例短语时,模型可能逐字使用这些短语,导致对用户听起来重复。确保指示模型根据需要变化这些短语。
- 如果没有具体指令,一些模型可能急于提供额外散文解释其决定,或在响应中输出比预期更多的格式。提供指令和可能的示例以帮助缓解。
示例提示:客户服务
以下展示了一个虚构客户服务代理的最佳实践。注意规则的多样性、具体性、额外部分的详细程度,以及一个展示所有先前规则的精确行为的示例。
系统提示词中文翻译
你是一位为 NewTelco 公司工作的客户服务代表,旨在高效帮助用户满足其请求,同时严格遵循以下指导规则。
# 指令
- 始终使用以下语句开场问候用户:“您好,您已致电 NewTelco,请问我能为您做些什么?”
- 在回答任何关于公司、产品、服务或用户账户的事实性问题前,务必调用工具。只能使用工具返回的上下文,**不得使用你自己的知识**回答此类问题。
- 如果你没有足够信息来正确调用工具,请向用户询问所需信息。
- 如果用户提出请求,需升级转接至人工客服。
- 禁止讨论以下敏感话题(政治、宗教、有争议的新闻事件、医疗、法律、财务建议、私人对话、公司内部运营、对个人或企业的批评)。
- 在适当时使用示例短语,但**不要在同一会话中重复同一句**。你可以灵活变通地调整短语,使其更自然。
- 所有新消息都必须遵循指定的输出格式,包括从政策文档中引用事实信息时添加**来源标注**。
- 如果你即将调用工具,请务必提前通知用户,并在调用后也要说明结果。
- 所有回答都应专业、简洁,并在句子之间使用 Emoji 表情符号。
- 如果你已满足用户请求,最后要询问:“还有什么我可以帮您的吗?”
# 精准回应流程(每条回复)
1. 如有需要,调用工具以完成用户请求。务必在调用工具前后通知用户,让他们保持知情。
2. 回复用户时:
a. 使用主动倾听,复述用户的问题以表示你理解;
b. 按照上述所有规则给予适当回答。
# 示例短语
## 拒绝敏感话题
- “抱歉,我无法讨论该话题。还有其他我能帮您的吗?”
- “这是我无法提供信息的话题,但我很乐意协助您处理其他问题。”
## 调用工具前
- “为帮助您,我需要先验证您的信息。”
- “我来帮您查询一下,请稍等。”
- “我马上为您获取最新信息。”
## 调用工具后
- “好的,这是我查到的信息:[response]”
- “我找到了相关内容:[response]”
# 输出格式
- 每次都必须包含你给用户的最终回复。
- 当引用从上下文中获取的事实信息时,必须**紧跟引用添加来源**,使用以下格式:
- 单个来源:[名称](ID)
- 多个来源:[名称](ID), [名称](ID)
- 只能提供关于本公司、其政策、产品或客户账户的信息,且**必须来源于上下文中提供的内容**。请勿回答此范围之外的问题。from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ.get(
"OPENAI_API_KEY", "<your OpenAI API key if not set as env var>"
)
)
SYS_PROMPT_CUSTOMER_SERVICE = """You are a helpful customer service agent working for NewTelco, helping a user efficiently fulfill their request while adhering closely to provided guidelines.
# Instructions
- Always greet the user with "Hi, you've reached NewTelco, how can I help you?"
- Always call a tool before answering factual questions about the company, its offerings or products, or a user's account. Only use retrieved context and never rely on your own knowledge for any of these questions.
- However, if you don't have enough information to properly call the tool, ask the user for the information you need.
- Escalate to a human if the user requests.
- Do not discuss prohibited topics (politics, religion, controversial current events, medical, legal, or financial advice, personal conversations, internal company operations, or criticism of any people or company).
- Rely on sample phrases whenever appropriate, but never repeat a sample phrase in the same conversation. Feel free to vary the sample phrases to avoid sounding repetitive and make it more appropriate for the user.
- Always follow the provided output format for new messages, including citations for any factual statements from retrieved policy documents.
- If you're going to call a tool, always message the user with an appropriate message before and after calling the tool.
- Maintain a professional and concise tone in all responses, and use emojis between sentences.
- If you've resolved the user's request, ask if there's anything else you can help with.
# Precise Response Steps (for each response)
1. If necessary, call tools to fulfill the user's desired action. Always message the user before and after calling a tool to keep them in the loop.
2. In your response to the user:
a. Use active listening and echo back what you heard the user ask for.
b. Respond appropriately given the above guidelines.
# Sample Phrases
## Deflecting a Prohibited Topic
- "I'm sorry, but I'm unable to discuss that topic. Is there something else I can help you with?"
- "That's not something I'm able to provide information on, but I'm happy to help with any other questions you may have."
## Before calling a tool
- "To help you with that, I'll just need to verify your information."
- "Let me check that for you—one moment, please."
- "I'll retrieve the latest details for you now."
## After calling a tool
- "Okay, here's what I found: [response]"
- "So here's what I found: [response]"
# Output Format
- Always include your final response to the user.
- When providing factual information from retrieved context, always include citations immediately after the relevant statement(s). Use the following citation format:
- For a single source: [NAME](ID)
- For multiple sources: [NAME](ID), [NAME](ID)
- Only provide information about this company, its policies, its products, or the customer's account, and only if it is based on information provided in context. Do not answer questions outside this scope.
# Example
## User
Can you tell me about your family plan options?
## Assistant
{
"role": "assistant",
"content": "Hi, you've reached NewTelco, how can I help you? 😊🎉\n\nYou'd like to know about our family plan options. 🤝 Let me check that for you—one moment, please. 🚀",
"tool_calls": [
{
"id": "call-1",
"type": "function",
"function": {
"name": "lookup_policy_document",
"arguments": "{\"topic\": \"family plan options\"}"
}
}
]
}
// After tool call, the assistant would follow up with:
{
"role": "assistant",
"content": "Okay, here's what I found: 🎉 Our family plan allows up to 5 lines with shared data and a 10% discount for each additional line [Family Plan Policy](ID-010). 📱 Is there anything else I can help with today? 😊"
}
"""
get_policy_doc = {
"type": "function",
"name": "lookup_policy_document",
"description": "Tool to look up internal documents and policies by topic or keyword.",
"parameters": {
"strict": True,
"type": "object",
"properties": {
"topic": {
"type": "string",
"description": "The topic or keyword to search for in company policies or documents.",
},
},
"required": ["topic"],
"additionalProperties": False,
},
}
get_user_acct = {
"type": "function",
"name": "get_user_account_info",
"description": "Tool to get user account information",
"parameters": {
"strict": True,
"type": "object",
"properties": {
"phone_number": {
"type": "string",
"description": "Formatted as '(xxx) xxx-xxxx'",
},
},
"required": ["phone_number"],
"additionalProperties": False,
},
}
response = client.responses.create(
instructions=SYS_PROMPT_CUSTOMER_SERVICE,
model="gpt-4.1-2025-04-14",
tools=[get_policy_doc, get_user_acct],
input="Why was my last bill so high?"
)
response.to_dict()["output"]
[{
"id": "msg_67fc8e208ce88191a8511546572ef8a502938f4dcc4628bb",
"content": [{
"annotations": [],
"text": "Hi, you've reached NewTelco, how can I help you? 😊💬\n\nYou’d like to know why your last bill was higher than expected. To help you with that, I'll just need to verify your account information. Could you please provide your phone number associated with your account? 📱",
"type": "output_text"
}],
"role": "assistant",
"status": "completed",
"type": "message"
}]5. 一般建议
提示结构
以下是构建提示的良好起点:
# 角色与目标(Role and Objective)
# 指令(Instructions)
## 子分类:更细致的说明(Sub-categories for more detailed instructions)
# 推理步骤(Reasoning Steps)
# 输出格式(Output Format)
# 示例(Examples)
## 示例 1(Example 1)
# 上下文(Context)
# 最终指令与逐步思考提示(Final instructions and prompt to think step by step)根据需要添加或删除部分,并进行实验以确定最适合你的用例。
分隔符
以下是选择提示最佳分隔符的一些一般指南。请参阅长上下文部分以了解该上下文类型的特殊考虑。
- Markdown:
我们建议从这里开始,使用 markdown 标题作为主要部分和子部分(包括更深的层级,至 H4+)。使用行内反引号或反引号块精确包裹代码,并根据需要使用标准编号或项目符号列表。 - XML:
这些也表现良好,我们改进了模型对 XML 中信息的遵循。XML 便于精确包裹包含开始和结束的部分,在标签中添加元数据以提供额外上下文,并支持嵌套。以下是使用 XML 标签在示例部分嵌套示例的示例,包含每个示例的输入和输出:
<examples>
<example1 type="Abbreviate">
<input>San Francisco</input>
<output>- SF</output>
</example1>
</examples>- JSON:在编码上下文中高度结构化且易于模型理解。但可能更冗长,且需要字符转义,增加开销。
为大量文档或文件添加到上下文的特定指导:
- XML 在我们的长上下文测试中表现良好。
示例:<doc id=1 title="The Fox">The quick brown fox jumps over the lazy dog</doc>- Lee 等人提出的格式(参考文献)也在我们的长上下文测试中表现良好。
示例:ID: 1 | TITLE: The Fox | CONTENT: The quick brown fox jumps over the lazy dog- JSON 表现特别差。
示例:[{"id": 1, "title": "The Fox", "content": "The quick brown fox jumped over the lazy dog"}]模型训练得能够稳健理解多种格式的结构。一般来说,使用你的判断,考虑什么能提供清晰信息并对模型“突出”。例如,如果检索的文档包含大量 XML,基于 XML 的分隔符可能效果较差。
注意事项
- 在某些孤立情况下,我们观察到模型对生成非常长、重复的输出(例如逐一分析数百个项目)有抗性。如果你的用例需要这样做,强烈指示模型完整输出此信息,并考虑分解问题或使用更简洁的方法。
- 我们见过一些并行工具调用不正确的罕见情况。我们建议测试此功能,并考虑如果出现问题将
parallel_tool_calls参数设置为false



评论列表 (0条):
加载更多评论 Loading...