Promptify 是一个Python库这款 Python 库通过 prompter、LLM 集成与 pipeline,把原本要反复调试 prompt 的过程简化成几行代码。
Github地址:https://github.com/promptslab/Promptify
本文将通过简单示例,带你了解 Promptify 为什么能成为 NLP 工具链中的“呼吸一口新鲜空气”。

欢迎大家关注公众号:AI大模型观察站,谢谢啦~~~~
Promptify 是什么?
假设你有一段文本,比如一份小说片段,想提取关键词、进行分类、生成问题。
通常你得构造复杂的 prompt,反复尝试才能让 LLM 给出合适结果。
Promptify 彻底改变了这一流程。
它是一个 Python 库,核心由三部分组成:
•✅ Prompter:用于构建 prompt(支持内置或自定义模板)•✅ LLM 接口:支持 OpenAI、PaLM、Hugging Face 等多种模型•✅ Pipeline:自动将文本输入 → prompt → LLM → 输出打通
无论是关键词提取、还是生成读书问题,Promptify 都能轻松搞定。
安装方式
使用 pip 安装:
pip3 install promptify
或安装最新 GitHub 版本:
pip3 install git+https://github.com/promptslab/Promptify.git
使用前需要准备 LLM 的 API Key(如 OpenAI、DeepSeek等)。
使用示例
✅ 示例 1:提取医学实体(NER)
from promptify importPrompter,OpenAI,Pipeline
sentence ="""The patient is a 93-year-old female with a medical history of chronic right hip pain, osteoporosis, hypertension, depression, and chronic atrial fibrillation admitted for evaluation and management of severe nausea and vomiting and urinary tract infection"""
model =OpenAI("your_api_key_here")
prompter =Prompter('ner.jinja')
pipe =Pipeline(prompter, model)
result = pipe.fit(sentence, domain="medical", labels=None)
print(result)
输出结果如下:
[
{"E":"93-year-old","T":"Age"},
{"E":"chronic right hip pain","T":"Medical Condition"},
{"E":"osteoporosis","T":"Medical Condition"},
{"E":"hypertension","T":"Medical Condition"},
{"E":"depression","T":"Medical Condition"},
{"E":"chronic atrial fibrillation","T":"Medical Condition"},
{"E":"severe nausea and vomiting","T":"Symptom"},
{"E":"urinary tract infection","T":"Medical Condition"},
{"Branch":"Internal Medicine","Group":"Geriatrics"}
]
👉 整理干净的结构化输出,准确分类,还能归属到临床科室。节省大量人工标注时间。
✅ 示例 2:多标签医学分类
from promptify importOpenAI,Prompter
sentence ="""The patient is a 93-year-old female with a medical history of chronic right hip pain, osteoporosis, hypertension, depression, and chronic atrial fibrillation admitted for evaluation and management of severe nausea and vomiting and urinary tract infection"""
model =OpenAI("your_api_key_here")
nlp_prompter =Prompter(model)
result = nlp_prompter.fit('multilabel_classification.jinja', domain='medical', text_input=sentence)
print(result)
输出如下:
[
{
'1':'Medicine',
'2':'Osteoporosis',
'3':'Hypertension',
'4':'Depression',
'5':'Atrial fibrillation',
'6':'Nausea and vomiting',
'7':'Urinary tract infection',
'branch':'Health',
'group':'Clinical medicine',
'main class':'Health'
}
]
👉 非常适合做医疗知识图谱、自动病例标签系统等。
✅ 示例 3:生成阅读理解题目
from promptify importOpenAI,Prompter
sentence ="""The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well."""
model =OpenAI("your_api_key_here")
nlp_prompter =Prompter(model)
result = nlp_prompter.fit('qa_gen.jinja', domain='story_writing', text_input=sentence)
print(result)
输出结果:
[
{'A':'Alice found herself falling down a very deep well.','Q':'What happened when Alice went down the rabbit-hole?'},
{'A':'Very deep.','Q':'How deep was the well?'},
{'A':'No, she did not have a moment to think.','Q':'Did Alice have time to think about stopping herself?'},
{'A':'It went straight on like a tunnel.','Q':'What direction did the rabbit-hole go?'},
{'A':'No, she did not expect it.','Q':'Did Alice expect to fall down a well?'}
]
👉 这些问答题可以直接拿去做英文阅读理解测验,省心又省力!
为什么我推荐 Promptify?
作为一个在资深程序员(已经写了十多年的代码),我对工具的要求是“节省脑细胞 + 效果可控”。
Promptify 做到了这几点:
✅ 节省脑力:告别 prompt 拼命调试
✅ 模板灵活:支持自定义任务模版
✅ 多模型兼容:OpenAI、Hugging Face 都能跑
✅ 任务多样:从医学到创意写作都能驾驭
✅ 快速上手:几行代码就能跑结果
结语
Promptify 是所有在 NLP 路上摸索的开发者的贴心助手。无论你做的是实体提取、文本分类、还是生成问题,它都能一站式搞定。
推荐给:
•数据科学家•医疗 NLP 工程师•教育/创作者•AI 初学者
小伙伴们,可以尝试下,按照你工作、生活中所使用的提示词,把这些都管理起来,作为自己的资源。
在使用过程中有问题可以在留言区和笔者交流🚀~~~~~~

(文:PyTorch研习社)