做选择的网站,电子科技产品网站建设,西部数码网站管理助手ftp,密云建设银行招聘网站1 prompt工程是什么
1.1 什么是Prompt#xff1f;
LLM大语言模型终究也只是一个工具#xff0c;我们不可能每个人都去训一个大模型#xff0c;但是我们可以思考如何利用好大模型#xff0c;让他提升我们的工作效率。就像计算器工具一样#xff0c;要你算10的10倍#x…1 prompt工程是什么
1.1 什么是Prompt
LLM大语言模型终究也只是一个工具我们不可能每个人都去训一个大模型但是我们可以思考如何利用好大模型让他提升我们的工作效率。就像计算器工具一样要你算10的10倍你是按10次“10”还是直接“10*10”如何利用工具决定了你几点下班。。
提示词prompt就是你给大模型下达的指令输入它包含以下任意要素
指令 想要模型执行的特定任务或者指令。
上下文包含外部信息或额外的上下文信息引导语言模型更好地响应。
输入数据 用户输入的内容或问题
输出指示 指定输出的类型或格式。
1.2 什么是prompt工程
提示工程就是开发和优化提示词Prompt一种在大模型中使用的技巧通过提供清晰、简洁的指令或问题充分发挥大模型的能力让模型更好地理解我们的需求从而得到更好的模型输出。
给大模型提示语的时候你就是产品经理
你随便提需求模型也就随口一答
你提出详细的需求给出充分的需求背景给足输出数据定义好输出格式好的模型就像一个好的程序员会给你一个满意的答复的~
2 prompt工程基本原则
我们再回顾下prompt工程课程中的两大基本原则
2.1 给出清晰详细的指令
策略1使用分割符清晰的知识输出的不同部分比如,,\tag等分隔符
策略2指定一个结构化的输出比如json,html等格式
策略3要求模型自检测是否满足条件
策略4提供少量示例
2.2 给模型思考的时间
我们不一定要一步得到答案可以让模型进行一系列的推理给他推理思考的时间再最终给出答案。
策略1指定完成任务需要的步骤
告诉模型完成这个指令需要执行几步每步的详细步骤
策略2明确模型再给出结论之前推理出自己的解决方案
让模型自己推理写出每一步的步骤给足够的时间token-钱边思考边执行。
3 prompt工程迭代思维 迭代思想无处不在提示工程和软件工程算法模型一样都是一个迭代的过程。。
4 prompt工程方法
prompt的原则和方法在吴恩达教授的课程中讲解的很详细 这里我们再介绍一些高阶方法。
4.1 思维链
思维链的概念是在Google的论文Chain-of-Thought Prompting Elicits Reasoning in Large Language Models中被首次提出。思维链是一系列的短句子模仿了人类在回答问题时的思考和可能的推理过程。
作者在文中也指出作为一种促进语言模型推理的方法思维链提示具有几个吸引人的特性
首先思维链允许模型将多步问题进行拆分分解为多个中间步骤。
其次思维链使得模型的回答过程具有较好的可解释性同时这一特性为定位推理错误并修改错误提供了可能。
第三链式思维推理可用于数学单词问题、常识推理和符号操作等任务并且理论上适用于任何可以通过语言解决的任务。
最后只要将思维序列链的例子包含到少样本提示的范例中就可以很容易地在足够大的现成语言模型中引出思维链推理。
下图一次介绍了少样本提示(a),少样本思维链(b),零样本提示©零样本思维链(d) 4.2 思维树
Tree of Thoughts (ToT)是思维链的进一步拓展主要想解决 LM 推理过程存在如下两个问题
不会探索不同的可能选择分支
无法在节点进行前后向的探索
ToT 将问题建模为树状搜索过程包括四个步骤问题分解、想法生成状态评价以及搜索算法的选择。 4.3 用prompt写prompt
以上方法都太麻烦还有一些懒人方法。利用ChatGPT插件或者自己写一个prompt来帮你写prompt用魔法打败魔法。
比如https://github.com/minghaochen/universal-prompt/blob/master/universal-prompt.txt 给出一个优化prompt的模版。
代码语言javascript
**复制
message [{content: I want you to act as an AI prompt engineer. You are expert at writing ChatGPT Prompts to get the best results.To create efficient prompts that yield high-quality responses, consider the following principles and strategies: \1. Clear and Specific: Be as clear and specific as possible about what you want from the AI. If you want a certain type of response, outline that in your prompt. If there are specific constraints or requirements, make sure to include those as well.2. Open-ended vs. Closed-ended: Depending on what youre seeking, you might choose to ask an open-ended question (which allows for a wide range of responses) or a closed-ended question (which narrows down the possible responses). Both have their uses, so choose according to your needs.3. Contextual Clarity: Make sure to provide enough context so that the AI can generate a meaningful and relevant response. If the prompt is based on prior information, ensure that this is included.4. Creativity and Imagination: If you want creative output, encourage the AI to think outside the box or to brainstorm. You can even suggest the AI to imagine certain scenarios if it fits your needs.There is a well-written prompt delimited by for your reference: Your task is to be my brainstorming partner and provide creative ideas and suggestions for a given topic or problem. Your response should include original, unique, and relevant ideas that could help solve the problem or further explore the topic in an interesting way. Please note that your response should also take into account any specific requirements or constraints of the task.Your task is to write an effective ChatGPT Prompt based on given keywords or to modify the given prompts. Answer in the same language as me.,role: system}]
message.append({content: Please help me to write an effective ChatGPT Prompt based on the following keywords or prompt: {}.format(prompt),role: user})
在调用ChatGPT接口时使用如上message就可以优化你的prompt.
代码语言javascript
**复制
Before:
translate the following English content into Chinese, 并润色
After:
Please translate the following English text into Chinese, ensuring not only accuracy in translation but also enhancing the prose to flow naturally and elegantly in Chinese. The translation should read as if originally written by a native speaker, with attention to cultural nuances and idiomatic expressions.
5 实践
上面说了这么多概念和理论方法还有没有更好的方法快速让我知道怎么写好prompt
有用别人的经验
前公司有个同事做过一个分享大佬说过一句话要想写好prompt最好的方法就是知道他的训练数据是什么样子的。可惜很少大模型完全开源他们的数据集。
但是很多大模型都会开放一个平台给大家体验大家也都会将好的用例分享出来。
比如智普清言我们看看程序员灵感 这里面就是一些优秀prompt这些经验我们就可以直接拿来主义。
大致可以总结出模版先给模型一个角色定位你是一名***再给出具体的需求请写一个***需求的代码。
上一个示例
代码语言javascript
**复制
你是一位擅长编写各种程序的资深工程师我需要你根据以下需求为我生成一段Python代码
代码目的设计一个双十一自动抢购脚本
代码功能在双十一当天自动登录购物网站定时抢购预设商品
代码要求使用面向对象编程方式使用selenium库进行网页操作
代码语言javascript
**复制
为了实现这个双十一自动抢购脚本我们可以进行以下步骤
1. 首先需要安装selenium库以及对应浏览器的驱动。
2. 其次需要登录目标购物网站。
3. 然后需要定位到目标商品的抢购按钮。
4. 最后在双十一当天设定一个定时器来点击抢购按钮。
以下是一个简单的示例代码
python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
class DoubleElevenShopper:def __init__(self, website, username, password, item_link):self.website websiteself.username usernameself.password passwordself.item_link item_linkself.driver webdriver.Chrome() # 使用Chrome浏览器def login(self):self.driver.get(self.website)username_field self.driver.find_element_by_name(username) # 这里需要根据目标网站的登录表单进行调整password_field self.driver.find_element_by_name(password)username_field.send_keys(self.username)password_field.send_keys(self.password)password_field.send_keys(Keys.RETURN)time.sleep(5) # 等待登录完成def buy_item(self):self.driver.get(self.item_link)buy_button self.driver.find_element_by_id(buy_button) # 这里需要根据目标商品的购买按钮进行调整buy_button.click()def run(self):self.login()self.buy_item()self.driver.quit()
if __name__ __main__:shopper DoubleElevenShopper(websitehttps://www.example.com,usernameyour_username,passwordyour_password,item_linkhttps://www.example.com/item)shopper.run()注意
需要安装Chrome浏览器和ChromeDriver。登录和购买按钮的元素定位需要根据具体的购物网站进行调整。此代码为简单示例实际使用可能需要处理更多的异常情况。 安装selenium库和ChromeDriver
pip install selenium下载ChromeDriver并将其路径添加到环境变量中。
最后奉上最全prompt指南https://github.com/dair-ai/Prompt-Engineering-Guide
写在最后
感兴趣的小伙伴赠送全套AIGC学习资料包含AI绘画、AI人工智能等前沿科技教程和软件工具具体看这里。
AIGC技术的未来发展前景广阔随着人工智能技术的不断发展AIGC技术也将不断提高。未来AIGC技术将在游戏和计算领域得到更广泛的应用使游戏和计算系统具有更高效、更智能、更灵活的特性。同时AIGC技术也将与人工智能技术紧密结合在更多的领域得到广泛应用对程序员来说影响至关重要。未来AIGC技术将继续得到提高同时也将与人工智能技术紧密结合在更多的领域得到广泛应用。
一、AIGC所有方向的学习路线
AIGC所有方向的技术点做的整理形成各个领域的知识点汇总它的用处就在于你可以按照下面的知识点去找对应的学习资源保证自己学得较为全面。 二、AIGC必备工具
工具都帮大家整理好了安装就可直接上手
三、最新AIGC学习笔记
当我学到一定基础有自己的理解能力的时候会去阅读一些前辈整理的书籍或者手写的笔记资料这些笔记详细记载了他们对一些技术点的理解这些理解是比较独到可以学到不一样的思路。
四、AIGC视频教程合集
观看全面零基础学习视频看视频学习是最快捷也是最有效果的方式跟着视频中老师的思路从基础到深入还是很容易入门的。 五、实战案例
纸上得来终觉浅要学会跟着视频一起敲要动手实操才能将自己的所学运用到实际当中去这时候可以搞点实战案例来学习。