网站开发生命周期,网站系统建设管理制度,wordpress页面显示分类,wordpress社交分享插件推荐#xff1a;使用NSDT场景编辑器助你快速搭建可二次编辑的3D应用场景
为了帮助用户获得最佳输出#xff0c;OpenAI 提供了使用 GPT 模型的最佳实践。这来自体验#xff0c;因为许多用户不断尝试使用此模型并找到了最有效的方法。
在本文中#xff0c;我将总结使用 Ope…推荐使用NSDT场景编辑器助你快速搭建可二次编辑的3D应用场景
为了帮助用户获得最佳输出OpenAI 提供了使用 GPT 模型的最佳实践。这来自体验因为许多用户不断尝试使用此模型并找到了最有效的方法。
在本文中我将总结使用 OpenAI GPT 模型应了解的最佳实践。这些做法是什么让我们进入它。
GPT 最佳做法
GPT 模型输出仅与您的提示一样好。通过对您想要的内容的明确说明它将提供您期望的结果。提高 GPT 输出的一些提示包括
在提示中提供详细信息以获取相关答案。例如我们可以写“通过 Python 中的代码示例为我提供标准分布计算”而不是提示“给我代码来计算正态分布”。在每个部分中放置注释并解释为什么每个代码都以这种方式执行。
给出一个角色或示例并添加输出的长度。 我们可以将角色或示例引入模型以便更清晰。例如我们可以传递系统角色参数以教师向学生解释的方式解释某些内容。通过提供角色GPT 模型将以我们需要的方式带来结果。如果要更改角色下面是一个示例代码。
import openaiopenai.api_key res openai.ChatCompletion.create(modelgpt-3.5-turbo,max_tokens100,temperature0.7,messages[{role: system,content: When I ask to explain something, bring it in a way that teacher would explain it to students in every paragraph.,},{role: user,content: What is golden globe award and what is the criteria for this award? Summarize them in 2 paragraphs.,},],
)
提供示例结果来指导 GPT 模型应如何回答您的问题也很棒。例如在此代码中我传递了如何解释情绪GPT 模型应模仿我的风格。
res openai.ChatCompletion.create(modelgpt-3.5-turbo,max_tokens100,temperature0.7,messages[{role: system,content: Answer in a consistent style.,},{role: user,content: Teach me about Love,},{role: assistant,content: Love can be sweet, can be sour, can be grand, can be low, and can be anything you want to be,},{role: user,content: Teach me about Fear,},],
)
指定完成任务的步骤。 提供有关如何输出以获得最佳输出的详细步骤。详细说明 GPT 模型应如何操作的说明。例如我们在此代码中放置了带有前缀和翻译的两步指令。
res openai.ChatCompletion.create(modelgpt-3.5-turbo,max_tokens100,temperature0.7,messages [{role: system,content: Use the following step-by-step instructions to respond to user inputs.step 1 - Explain the question input by the user in 2 paragraphs or less with the prefix Explanation: .Step 2 - Translate the Step 1 into Indonesian, with a prefix that says Translation: .,},{role: user,content:What is heaven?,},])
提供参考、链接或引用。如果我们已经有各种问题参考我们可以将它们用作 GPT 模型的基础来提供输出。提供您认为与您的问题相关的任何参考文献的列表并将它们传递给系统角色。
给 GPT 时间“思考”。提供一个查询允许 GPT 在急于给出不正确的结果之前详细处理提示。如果我们给助理角色传递错误的结果并且我们希望 GPT 能够自己批判性地思考则尤其如此。例如下面的代码显示了我们如何要求 GPT 模型对用户输入更加严格。
res openai.ChatCompletion.create(modelgpt-3.5-turbo,max_tokens100,temperature0.7,messages [{role: system,content: Work on your solution to the problem, then compare your solution to the user and evaluateif the solution is correct or not. Only decide if the solution is correct once you have done the problem yourself.,}, {role: user,content:1 1 3,},])
使 GPT 使用代码执行来获得精确的结果。 对于更扩展和更复杂的计算GPT 可能无法按预期工作因为模型可能会提供不准确的结果。为了缓解这种情况我们可以要求 GPT 模型编写和运行编码而不是直接计算它们。这样GPT 可以依赖代码而不是其计算。例如我们可以提供如下输入。
res openai.ChatCompletion.create(modelgpt-3.5-turbo,max_tokens100,temperature0.7,messages [{role: system,content: Write and execute Python code by enclosing it in triple backticks,e.g. code goes here. Use this to perform calculations.,}, {role: user,content:Find all real-valued roots of the following polynomial equation: 2*x**5 - 3*x**8- 2*x**3 - 9*x 11.,},])
结论
GPT 模型是目前最好的模型之一以下是改进 GPT 模型输出的一些最佳实践
在提示中提供详细信息以获取相关答案给出一个角色或示例并添加输出的长度指定完成任务的步骤提供参考、链接或引用给 GPT 时间“思考”使 GPT 使用代码执行来获得精确的结果
原文链接使用 OpenAI GPT 模型的最佳实践 (mvrlink.com)