怎么做网站的步骤,专业网站制作电话,做期货在哪个网站看消息,兰州网站建设企业名录提示原则
1.编写明确具体的指令 策略一#xff1a;使用分隔符清晰地表示输入的不同部分#xff0c;分隔符可以是#xff1a;#xff0c;“”#xff0c;#xff0c; 你可以使用任何明显的标点符号将特定的文本部分与提示的其余部分分开。这可以是任何可以使模型…提示原则
1.编写明确具体的指令 策略一使用分隔符清晰地表示输入的不同部分分隔符可以是“” 你可以使用任何明显的标点符号将特定的文本部分与提示的其余部分分开。这可以是任何可以使模型明确知道这是一个单独部分的标记。使用分隔符是一种可以避免提示注入的有用技术。 提示注入是指如果用户将某些输入添加到提示中则可能会向模型提供与您想要执行的操作相冲突的指令从而使其遵循冲突的指令而不是执行您想要的操作。即输入里面可能包含其他指令会覆盖掉你的指令。 策略二要求一个结构化的输出可以是 Json、HTML 等格式 第二个策略是要求生成一个结构化的输出这可以使模型的输出更容易被我们解析
2.给模型时间去思考 策略一指定完成任务所需的步骤
代码示例
安装openai并简单测试 import openai
openai.api_keysk-MMTTj3CC9PwSytklV4bcT3BlbkFJNh4kipV9ILD3Uwnt1eP8
model_engine davinci-002
prompt Hello, ChatGPT!
print(ok)
completions openai.Completion.create(enginemodel_engine,promptprompt,max_tokens1024,n1,stopNone,temperature0.5,
)
print(ok)
message completions.choices[0].text
print(message)调用模型的函数
# 一个封装 OpenAI 接口的函数参数为 Prompt返回对应结果
def get_completion(prompt, modelgpt-3.5-turbo):prompt: 对应的提示model: 调用的模型默认为 gpt-3.5-turbo(ChatGPT)有内测资格的用户可以选择 gpt-4messages [{role: user, content: prompt}]response openai.ChatCompletion.create(modelmodel,messagesmessages,temperature0, # 模型输出的温度系数控制输出的随机程度)# 调用 OpenAI 的 ChatCompletion 接口return response.choices[0].message[content]原则1 策略一 使用分隔符清晰地表示输入的不同部分分隔符可以是“”**
text f
You should express what you want a model to do by \
providing instructions that are as clear and \
specific as you can possibly make them. \
This will guide the model towards the desired output, \
and reduce the chances of receiving irrelevant \
or incorrect responses. Dont confuse writing a \
clear prompt with writing a short prompt. \
In many cases, longer prompts provide more clarity \
and context for the model, which can lead to \
more detailed and relevant outputs.prompt f
Summarize the text delimited by triple backticks \
into a single sentence.
{text}response get_completion(prompt)
print(response)结果
To guide a model towards the desired output and reduce irrelevant or incorrect responses, it is important to provide clear and specific instructions, which can be achieved through longer prompts that offer more clarity and context.原则1 策略二要求一个结构化的输出
prompt f
Generate a list of three made-up book titles along \
with their authors and genres.
Provide them in JSON format with the following keys:
book_id, title, author, genre.{books: [{book_id: 1,title: The Enigma of Elysium,author: Evelyn Sinclair,genre: Mystery},{book_id: 2,title: Whispers in the Wind,author: Nathaniel Blackwood,genre: Fantasy},{book_id: 3,title: Echoes of the Past,author: Amelia Hart,genre: Romance}]
}原则1 策略三要求模型检查是否满足条件
如果任务做出的假设不一定满足我们可以告诉模型先检查这些假设如果不满足指示并停止执行。你还可以考虑潜在的边缘情况以及模型应该如何处理它们以避免意外的错误或结果。
在如下示例中我们将分别给模型两段文本分别是制作茶的步骤以及一段没有明确步骤的文本。我们将要求模型判断其是否包含一系列指令如果包含则按照给定格式重新编写指令不包含则回答未提供步骤。
text_1 f
Making a cup of tea is easy! First, you need to get some \
water boiling. While thats happening, \
grab a cup and put a tea bag in it. Once the water is \
hot enough, just pour it over the tea bag. \
Let it sit for a bit so the tea can steep. After a \
few minutes, take out the tea bag. If you \
like, you can add some sugar or milk to taste. \
And thats it! Youve got yourself a delicious \
cup of tea to enjoy.prompt f
You will be provided with text delimited by triple quotes.
If it contains a sequence of instructions, \
re-write those instructions in the following format:Step 1 - ...
Step 2 - …
…
Step N - …If the text does not contain a sequence of instructions, \
then simply write \No steps provided.\\\\{text_1}\\\response get_completion(prompt)
print(Completion for Text 1:)
print(response)结果
Completion for Text 1:
Step 1 - Get some water boiling.
Step 2 - Grab a cup and put a tea bag in it.
Step 3 - Once the water is hot enough, pour it over the tea bag.
Step 4 - Let it sit for a bit so the tea can steep.
Step 5 - After a few minutes, take out the tea bag.
Step 6 - Add some sugar or milk to taste.
Step 7 - Enjoy your delicious cup of tea!text_2 f
The sun is shining brightly today, and the birds are \
singing. Its a beautiful day to go for a \
walk in the park. The flowers are blooming, and the \
trees are swaying gently in the breeze. People \
are out and about, enjoying the lovely weather. \
Some are having picnics, while others are playing \
games or simply relaxing on the grass. Its a \
perfect day to spend time outdoors and appreciate the \
beauty of nature.prompt fYou will be provided with text delimited by triple quotes.
If it contains a sequence of instructions, \
re-write those instructions in the following format:
Step 1 - ...
Step 2 - …
…
Step N - …If the text does not contain a sequence of instructions, \
then simply write \No steps provided.\\\\{text_2}\\\response get_completion(prompt)
print(Completion for Text 2:)
print(response)结果
Completion for Text 2:
No steps provided.原则1 策略四提供少量示例
即在要求模型执行实际任务之前提供给它少量成功执行任务的示例。
prompt f
Your task is to answer in a consistent style.child: Teach me about patience.grandparent: The river that carves the deepest \
valley flows from a modest spring; the \
grandest symphony originates from a single note; \
the most intricate tapestry begins with a solitary thread.child: Teach me about resilience.原则二 策略一指定完成任务所需的步骤
首先我们描述了杰克和吉尔的故事并给出一个指令。该指令是执行以下操作。首先用一句话概括三个反引号限定的文本。第二将摘要翻译成法语。第三在法语摘要中列出每个名称。第四输出包含以下键的 JSON 对象法语摘要和名称数。然后我们要用换行符分隔答案。
text f
在一个迷人的村庄里兄妹杰克和吉尔出发去一个山顶井里打水。\
他们一边唱着欢乐的歌一边往上爬\
然而不幸降临——杰克绊了一块石头从山上滚了下来吉尔紧随其后。\
虽然略有些摔伤但他们还是回到了温馨的家中。\
尽管出了这样的意外他们的冒险精神依然没有减弱继续充满愉悦地探索。# example 1
prompt_1 f
执行以下操作
1-用一句话概括下面用三个反引号括起来的文本。
2-将摘要翻译成法语。
3-在法语摘要中列出每个人名。
4-输出一个 JSON 对象其中包含以下键French_summarynum_names。请用换行符分隔您的答案。Text:
{text}response get_completion(prompt_1)
print(prompt 1:)
print(response)输出
1-兄妹在山顶井里打水时发生意外但仍然保持冒险精神。
2-Dans un charmant village, les frère et sœur Jack et Jill partent chercher de leau dans un puits au sommet de la montagne. Malheureusement, Jack trébuche sur une pierre et tombe de la montagne, suivi de près par Jill. Bien quils soient légèrement blessés, ils retournent chez eux chaleureusement. Malgré cet accident, leur esprit daventure ne diminue pas et ils continuent à explorer joyeusement.
3-Jack, Jill
4-{French_summary: Dans un charmant village, les frère et sœur Jack et Jill partent chercher de leau dans un puits au sommet de la montagne. Malheureusement, Jack trébuche sur une pierre et tombe de la montagne, suivi de près par Jill. Bien quils soient légèrement blessés, ils retournent chez eux chaleureusement. Malgré cet accident, leur esprit daventure ne diminue pas et ils continuent à explorer joyeusement.,num_names: 2
}原则二 策略二指导模型在下结论之前找出一个自己的解法
明确指导模型在做决策之前要思考解决方案 比如有一个问题和答案 先让模型自己找解决办法 然后与给出的答案进行对比来判断给出的答案是否正确 避免模型错误的将给定的答案认定为正确答案 示例提示词
prompt f
请判断学生的解决方案是否正确请通过如下步骤解决这个问题步骤首先自己解决问题。然后将你的解决方案与学生的解决方案进行比较并评估学生的解决方案是否正确。在自己完成问题之前请勿决定学生的解决方案是否正确。使用以下格式问题问题文本学生的解决方案学生的解决方案文本实际解决方案和步骤实际解决方案和步骤文本学生的解决方案和实际解决方案是否相同是或否学生的成绩正确或不正确问题我正在建造一个太阳能发电站需要帮助计算财务。 - 土地费用为每平方英尺100美元- 我可以以每平方英尺250美元的价格购买太阳能电池板- 我已经谈判好了维护合同每年需要支付固定的10万美元并额外支付每平方英尺10美元作为平方英尺数的函数首年运营的总费用是多少。学生的解决方案设x为发电站的大小单位为平方英尺。费用1. 土地费用100x2. 太阳能电池板费用250x3. 维护费用100,000100x总费用100x250x100,000100x450x100,000实际解决方案和步骤response get_completion(prompt)
print(response)结果
正确的解决方案和步骤1. 计算土地费用100美元/平方英尺 * x平方英尺 100x美元2. 计算太阳能电池板费用250美元/平方英尺 * x平方英尺 250x美元3. 计算维护费用10万美元 10美元/平方英尺 * x平方英尺 10万美元 10x美元4. 计算总费用100x美元 250x美元 10万美元 10x美元 360x 10万美元学生的解决方案和实际解决方案是否相同否学生的成绩不正确局限性
虚假知识模型偶尔会生成一些看似真实实则编造的知识 如果模型在训练过程中接触了大量的知识它并没有完全记住所见的信息因此它并不很清楚自己知识的边界。这意味着它可能会尝试回答有关晦涩主题的问题并编造听起来合理但实际上并不正确的答案。我们称这些编造的想法为幻觉。 减少幻觉的策略要求模型找到文本中的任何相关引用然后要求它使用这些引用来回答问题(追溯原文档) 是否有相关实例