Prompt提示实验室
通过标准化协议提供提示模板,将基本的用户查询转换为针对AI系统的优化提示。
服务介绍
PromptLab:AI 查询增强引擎
PromptLab 可将基本的用户查询转换为针对 AI 系统优化的提示。它自动检测内容类型(如文章、电子邮件、技术解释、创意写作),应用定制模板,并验证增强后的提示是否保持了原始意图。
🔍 概览
PromptLab 基于模块化架构,使用基于 YAML 的模板系统,使任何人都能无需编程知识即可创建和管理提示模板。该系统最终通过更好的结构化输入产生更高质量的 AI 回复。
🏗️ 架构
PromptLab 包含三个主要组件:
- 模板系统 (
prompt_templates.yaml) - 为不同类型的内容提供结构化的模板 - MCP 服务器 (
promptlab_server.py) - 通过与 LangGraph Workflow 标准协议提供模板 - 处理客户端 (
promptlab_client.py) - 用于处理用户查询的轻量级客户端
工作流程
- 查询输入:用户提交自然语言查询
- 分类:系统确定内容类型(如文章、电子邮件等)
- 参数提取:识别关键参数(如主题、受众等)
- 模板应用:检索并填充适当的模板
- 验证:检查增强后的提示是否保持了原始意图
- 调整:自动进行任何必要的细化
- 响应生成:优化后的提示产生高质量回复

📋 功能
- 内容类型检测 - 自动将用户查询分类为文章、电子邮件、技术或创意写作请求
- 参数提取 - 智能地提取诸如主题、收件人和受众水平等关键参数
- 模板库 - 为常见内容类型提供预配置的带有结构化指导的模板
- 验证系统 - 确保增强后的提示保持用户的原始意图
- 反馈循环 - 当验证发现不一致时调整提示
- 模块化设计 - MCP 服务器可以插入任何 LLM 系统
- 非技术性管理 - 无需编码知识即可更新模板
🚀 入门指南
前提条件
- Python 3.8+
- 依赖项:
mcp[cli]langchain-openailanggraph>=0.0.20python-dotenvpyyaml
安装
# Clone the repository
git clone https://github.com/iRahulPandey/PromptLab.git
cd PromptLab
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env
# Edit .env to add your OpenAI API key
使用方法
- 首先运行服务器:
# The server loads templates from prompt_templates.yaml
python promptlab_server.py
- 使用您的查询运行客户端:
python promptlab_client.py "Write an essay about climate change"
- 系统将输出:
- 原始查询
- 分类的内容类型
- 增强后的提示
- 验证结果
- 最终响应
📝 模板系统
模板在 prompt_templates.yaml 中以结构化格式定义:
templates:
essay_prompt:
description: "Generate an optimized prompt template for writing essays."
template: |
Write a well-structured essay on {topic} that includes:
- A compelling introduction that provides context and states your thesis
...
parameters:
- name: topic
type: string
description: The topic of the essay
required: true
添加新模板
- 打开
prompt_templates.yaml - 按照现有格式添加一个新的模板
- 定义参数和转换
- 在服务器端定义一个工具并加载模板
- 服务器将在重启时自动加载新模板
🛠️ 高级配置
环境变量
TEMPLATES_FILE- 模板 YAML 文件的路径(默认:prompt_templates.yaml)OPENAI_API_KEY- 用于访问 LLM 的 OpenAI API 密钥MODEL_NAME- 要使用的 OpenAI 模型(默认:gpt-3.5-turbo)PERSONA_SERVER_SCRIPT- 服务器脚本的路径(默认:promptlab_server.py)
自定义转换
模板可以包含动态调整参数的转换:
transformations:
- name: formality
value: "formal if recipient_type.lower() in ['boss', 'client'] else 'semi-formal'"
📊 示例输出
输入查询
"为我的教授写一些关于可再生能源的内容"
增强后的提示
Write a well-structured essay on renewable energy that includes:
- A compelling introduction that provides context and states your thesis
- 2-3 body paragraphs, each with a clear topic sentence and supporting evidence
- Logical transitions between paragraphs that guide the reader
- A conclusion that synthesizes your main points and offers final thoughts
The essay should be informative, well-reasoned, and demonstrate critical thinking.
📄 许可证
MIT 许可证 - 详情请参阅 LICENSE 文件
🤝 贡献
欢迎贡献!请随时提交 Pull Request。
- 叉取仓库
- 创建你的功能分支 (
git checkout -b feature/amazing-feature) - 提交你的更改 (
git commit -m 'Add some amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 打开 Pull Request