PromptLab是一个智能系统,它利用MLflow提示注册表将基本用户查询转换为优化后的AI系统提示。该系统动态匹配用户请求到最合适的提示模板,并应用提取的参数。
PromptLab结合了MLflow提示注册表与动态提示匹配,创建了一个强大且灵活的提示工程系统:
该系统由三个主要组件组成:
register_prompts.py) - 在MLflow中注册和管理提示的工具promptlab_server.py) - 具有动态提示匹配和LangGraph工作流的服务器promptlab_client.py) - 处理用户查询的轻量级客户端
promptlab/
├── promptlab_server.py # 主服务器,具有LangGraph工作流
├── promptlab_client.py # 查询处理客户端
├── register_prompts.py # MLflow提示管理工具
├── requirements.txt # 项目依赖
├── advanced_prompts.json # 额外的提示模板
└── README.md # 项目文档
register_prompts.pyregister_prompt():注册新提示或版本update_prompt():更新现有提示(归档之前的生产版本)list_prompts():列出所有已注册的提示register_from_file():从JSON文件注册多个提示register_sample_prompts():初始化标准提示promptlab_server.pyload_all_prompts():从MLflow加载提示match_prompt():将查询匹配到适当的模板enhance_query():应用选定的模板validate_query():验证增强后的查询LangGraph工作流:协调查询增强过程promptlab_client.pyrequirements.txt中的依赖项# 克隆仓库
git clone https://github.com/iRahulPandey/PromptLab.git
cd PromptLab
# 安装依赖项
pip install -r requirements.txt
# 设置环境变量
export OPENAI_API_KEY="your-openai-api-key"
在使用PromptLab之前,您需要在MLflow中注册提示:
# 注册示例提示(论文、邮件、技术、创意)
python register_prompts.py register-samples
# 注册额外的提示类型(推荐)
python register_prompts.py register-file --file advanced_prompts.json
# 验证已注册的提示
python register_prompts.py list
# 启动服务器
python promptlab_server.py
# 处理查询
python promptlab_client.py "写一篇关于机器学习的博客文章"
# 列出可用提示
python promptlab_client.py --list
# 启用详细输出
python promptlab_client.py --verbose "创建一份关于气候变化的演示文稿"
PromptLab支持广泛的提示类型:
| 提示类型 | 描述 | 示例用例 |
|---|---|---|
| essay_prompt | 学术写作 | 研究论文、分析 |
| email_prompt | 邮件撰写 | 专业沟通 |
| technical_prompt | 技术解释 | 概念、技术 |
| creative_prompt | 创意写作 | 故事、诗歌、小说 |
| code_prompt | 代码生成 | 函数、算法 |
| summary_prompt | 内容总结 | 文章、文档 |
| analysis_prompt | 批判性分析 | 数据、文本、概念 |
| qa_prompt | 问答 | 基于上下文的答案 |
| social_media_prompt | 社交媒体内容 | 平台特定帖子 |
| blog_prompt | 博客文章撰写 | 在线文章 |
| report_prompt | 正式报告 | 商业、技术报告 |
| letter_prompt | 正式信函 | 覆盖、推荐信 |
| presentation_prompt | 演讲大纲 | 幻灯片、演讲 |
| review_prompt | 评论 | 产品、媒体、服务 |
| comparison_prompt | 对比 | 产品、概念、选项 |
| instruction_prompt | 指南 | 分步指南 |
| custom_prompt | 自定义模板 | 特定用途 |
您可以通过多种方式注册新提示:
python register_prompts.py register \
--name "new_prompt" \
--template "您的模板,包含{{变量}}" \
--message "初始版本" \
--tags '{"type": "custom", "task": "specialized"}'
# 创建一个包含您模板的文本文件
echo "模板内容,包含{{变量}}" > template.txt
# 使用文件注册
python register_prompts.py register \
--name "long_prompt" \
--template template.txt \
--message "复杂模板"
创建一个包含多个提示的JSON文件:
{
"prompts": [
{
"name": "prompt_name",
"template": "模板,包含{{变量}}",
"commit_message": "描述",
"tags": {"type": "类别", "task": "目的"}
}
]
}
然后注册它们:
python register_prompts.py register-file --file your_prompts.json
当您更新现有提示时,系统会自动:
python register_prompts.py update \
--name "essay_prompt" \
--template "改进的新模板,包含{{变量}}" \
--message "增强了清晰度和结构"
# 列出所有提示
python register_prompts.py list
# 查看特定提示的详细信息
python register_prompts.py details --name "essay_prompt"
模板使用{{变量}}格式的变量:
写一封{{formality}}邮件给我的{{recipient_type}}关于{{topic}},其中应包括:
- 清晰的主题行
- 适当的问候语
...
在匹配查询时,系统会自动提取这些变量的值。
每个提示可以有不同的版本别名:
这允许:
对于特定用途,您可以创建高度定制化的提示:
python register_prompts.py register \
--name "specialized_prompt" \
--template "您是一位{{role}},在{{domain}}领域拥有专业知识。创建一份关于{{topic}}的{{document_type}},展示{{quality}}。" \
--message "特定化模板" \
--tags '{"type": "custom", "task": "specialized", "domain": "finance"}'
如果系统无法将查询匹配到任何提示模板,它将:
您可以添加更多多样化的提示模板来提高匹配度。
如果LLM服务不可用,系统将退回到:
这确保即使没有LLM访问,系统仍能正常运行。