github项目
本文档收集了GitHub上与提示词工程相关的优质开源项目,涵盖框架、工具、模板库、学习资源和应用案例。
提示词框架与工具
1. Langchain - Prompting 模块
项目地址: https://github.com/langchain-ai/langchain
主要特点:
- 提供结构化提示词模板管理
- 支持提示链(Chain)构建与组合
- 内置少样本、思维链等高级提示策略
- 与多种LLM无缝集成
使用示例:
from langchain.prompts import ChatPromptTemplate
from langchain.prompts.few_shot import FewShotPromptTemplate
from langchain.chains import LLMChain
from langchain.llms import OpenAI
# 创建提示模板
prompt = ChatPromptTemplate.from_template(
"你是一名{role}。请{request}:\n\n{input}"
)
# 创建链
chain = LLMChain(
llm=OpenAI(),
prompt=prompt
)
# 执行
result = chain.run(
role="数据分析师",
request="分析以下数据中的趋势",
input="2020年:120,2021年:145,2022年:190"
)
2. LMQL - 提示词查询语言
项目地址: https://github.com/eth-sri/lmql
主要特点:
- 将提示词与编程语言结合的查询语言
- 支持声明式约束和流程控制
- 可以实现复杂交互式提示流
- 优化提示执行效率
使用示例:
import lmql
@lmql.query
def analyze_sentiment(text):
'''
CONTEXT: You are a sentiment analysis expert.
USER: Analyze the sentiment of the following text: "{text}"
ASSISTANT: [ANALYSIS] where len(ANALYSIS) < 100 and "sentiment" in ANALYSIS
'''
return ANALYSIS
result = analyze_sentiment("I really enjoyed the movie, but the ending was disappointing.")
3. Guidance
项目地址: https://github.com/guidance-ai/guidance
主要特点:
- 通过模板控制LLM输出结构
- 支持正则表达式、JSON Schema等约束
- 提供可编程的生成控制流
- 与多种LLM兼容
使用示例:
import guidance
# 定义提示模板
program = guidance('''
{{#system~}}
你是一个专业的产品描述撰写者。
{{~/system}}
{{#user~}}
为以下产品创建简短描述:
产品: {{product}}
特性: {{features}}
{{~/user}}
{{#assistant~}}
{{gen 'description' temperature=0.7 max_tokens=100}}
{{~/assistant}}
''')
# 执行提示
result = program(
product="智能家居控制器",
features=["语音控制", "自动化场景", "移动应用"]
)
print(result['description'])
4. Promptflow
项目地址: https://github.com/microsoft/promptflow
主要特点:
- 可视化提示工程工作流设计
- 支持多步骤提示流程编排
- 集成评估与实验功能
- 适用于复杂LLM应用开发
使用示例: 通过Promptflow UI创建工作流,或使用Python SDK:
from promptflow.core import Promptflow
# 加载提示流
flow = Promptflow("translation_flow")
# 执行提示流
result = flow.execute(
text="今天天气真好",
source_language="Chinese",
target_language="English"
)
提示模板与库
1. Awesome Prompts
项目地址: https://github.com/f/awesome-chatgpt-prompts
主要特点:
- 收集了数百个高质量角色提示
- 按应用场景和功能分类
- 社区持续贡献和改进
- 包含专业领域的专家提 示
2. Prompt Engineering Guide
项目地址: https://github.com/dair-ai/Prompt-Engineering-Guide
主要特点:
- 全面的提示词工程教程
- 包括基础理论和高级技术
- 提供多种语言版本
- 包含实用模板和案例研究
3. PromptPerfect
项目地址: https://github.com/promptslab/promptperfect
主要特点:
- 提示词优化和测试工具
- 自动提示词改进建议
- 支持多种LLM的提示调优
- 提供性能分析和比较
提示词应用与案例
1. GPT-Engineer
项目地址: https://github.com/AntonOsika/gpt-engineer
主要特点:
- 使用高级提示链生成完整项目代码
- 基于自然语言说明构建软件
- 自动化代码生成、测试和文档
- 展示了复杂提示工程的实际应用
使用示例:
# 安装
pip install gpt-engineer
# 使用
mkdir my_new_project
cd my_new_project
echo "创建一个简单的天气查询应用,有搜索框和结果显示面板。" > prompt
gpt-engineer .
2. BabyAGI
项目地址: https://github.com/yoheinakajima/babyagi
主要特点:
- 基于提示链实现的自主任务规划与执行
- 展示了提示词驱动的智能代理设计
- 使用思维链提示实现逐步推理
- 开创性地演示了提示工程应用于AGI研究
3. ChatDev
项目地址: https://github.com/OpenBMB/ChatDev
主要特点:
- 使用提示工程模拟软件开发团队
- 高级角色提示和任务分解
- 完整的软件开发流程自动化
- 展示企业级提示词应用