gpt-prompt-engineer 使用教程
gpt-prompt-engineer 使用教程gpt-prompt-engineergpt-prompt-engineer - 一个工具,用于自动化生成、测试和排名多种提示,以找到最适合特定任务的提示。项目地址: https://gitcode.com/g...
gpt-prompt-engineer 使用教程
1. 项目介绍
gpt-prompt-engineer 是一个用于生成、测试和优化 GPT 提示的工具。它通过输入任务描述和测试用例,自动生成、测试并排名多个提示,以找到性能最佳的提示。该项目支持多种模型,如 GPT-4、GPT-3.5-Turbo 和 Claude 3 Opus,并且可以自动生成测试用例,支持多输入变量,使其更加强大和灵活。
2. 项目快速启动
2.1 环境准备
首先,确保你已经安装了 Python 和 Jupyter Notebook。然后,克隆项目到本地:
git clone https://github.com/mshumer/gpt-prompt-engineer.git
cd gpt-prompt-engineer
2.2 配置 API 密钥
在项目目录中打开 Jupyter Notebook,找到 gpt_prompt_engineer.ipynb 文件。在文件中找到以下代码行,并添加你的 OpenAI API 密钥:
openai.api_key = "ADD YOUR KEY HERE"
如果你使用的是 Claude 3 版本,还需要添加 Anthropic API 密钥:
ANTHROPIC_API_KEY = "ADD YOUR KEY HERE"
2.3 运行示例
在 Jupyter Notebook 中运行以下代码,生成并测试提示:
description = "Given a prompt, generate a landing page headline"
test_cases = [
{'prompt': 'Promoting an innovative new fitness app, Smartly'},
{'prompt': 'Why a vegan diet is beneficial for your health'},
{'prompt': 'Introducing a new online course on digital marketing'},
{'prompt': 'Launching a new line of eco-friendly clothing'},
{'prompt': 'Promoting a new travel blog focusing on budget travel'},
{'prompt': 'Advertising a new software for efficient project management'},
{'prompt': 'Introducing a new book on mastering Python programming'},
{'prompt': 'Promoting a new online platform for learning languages'},
{'prompt': 'Advertising a new service for personalized meal plans'},
{'prompt': 'Launching a new app for mental health and mindfulness'}
]
generate_optimal_prompt(description, test_cases, number_of_prompts=10)
3. 应用案例和最佳实践
3.1 生成个性化邮件回复
使用 Claude 3 版本,可以生成个性化的邮件回复。定义输入变量和描述:
description = "Given a prompt, generate a personalized email response"
input_variables = [
{"variable": "SENDER_NAME", "description": "The name of the person who sent the email"},
{"variable": "RECIPIENT_NAME", "description": "The name of the person receiving the email"},
{"variable": "TOPIC", "description": "The main topic or subject of the email, One to two sentences"}
]
generate_optimal_prompt(description, input_variables, num_test_cases=5, number_of_prompts=10)
3.2 分类任务
对于分类任务,可以使用分类版本的 gpt_prompt_engineer:
test_cases = [
{'prompt': 'I had a great day', 'output': 'true'},
{'prompt': 'I am feeling gloomy', 'output': 'false'}
]
generate_optimal_prompt(description, test_cases, number_of_prompts=10)
4. 典型生态项目
4.1 Weights & Biases
gpt-prompt-engineer 支持将配置和结果记录到 Weights & Biases,以便更好地跟踪和分析实验结果。
4.2 Portkey
Portkey 是一个用于记录和追踪提示链及其响应的工具,可以帮助你更好地管理和分析提示生成过程。
通过这些工具,你可以更高效地进行提示工程实验,并找到最佳的提示配置。
更多推荐

所有评论(0)