Promptify

promptslabApache-2.0更新放缓

把自然语言提示词编译成结构化输出的提示工程工具,支持 GPT 等模型,并提供提示词版本管理,省去手写解析逻辑。

Prompt Engineering | Prompt Versioning | Use GPT or other prompt based models to get structured output. Join our discord for Prompt-Engineering, LLMs and other latest research

暂无版本4,647star361fork同步于 2026-11-10 11:37 UTC

怎么上手

由 README 提炼,执行前请确认
pip install promptify
pip install promptify[eval]
硬件要求按 README 说明

README 未说明本地硬件要求;默认调用云端 LLM API,本地模型可走 ollama/llama3 等 LiteLLM 后端,显存需求取决于所选模型。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用几行代码把 LLM 变成结构化 NLP 引擎,输出 Pydantic 对象而非原始字符串

把自然语言提示词编译成结构化输出的提示工程工具,支持 GPT 等模型,并提供提示词版本管理,省去手写解析逻辑。

核心能力

  • 内置 NER、分类、QA、摘要、关系抽取等任务类
  • 用 Pydantic schema 约束输出,结果类型安全
  • 通过 LiteLLM 切换 OpenAI、Anthropic、Ollama 等 100+ 后端
  • 支持 batch 并发与 acall 异步调用
  • 自带 precision、recall、F1、ROUGE 等评估指标

容易踩的坑

需 Python 3.9+;评估指标要额外装 promptify[eval];调用云端模型需自备对应厂商 API Key,本地模型需先自行部署 Ollama 等服务。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Installation

    With pip

    Requires Python 3.9+.

    pip install promptify
    

    or

    pip install git+https://github.com/promptslab/Promptify.git
    

    For evaluation metrics support:

    pip install promptify[eval]
    

    Quick Tour

    3-Line NER

    from promptify import NER
    
    ner = NER(model="gpt-4o-mini", domain="medical")
    result = ner("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")
    

    Output:

    NERResult(entities=[
        Entity(text="93-year-old", label="AGE"),
        Entity(text="chronic right hip pain", label="CONDITION"),
        Entity(text="osteoporosis", label="CONDITION"),
        Entity(text="hypertension", label="CONDITION"),
        Entity(text="depression", label="CONDITION"),
        Entity(text="chronic atrial fibrillation", label="CONDITION"),
        Entity(text="severe nausea and vomiting", label="SYMPTOM"),
        Entity(text="urinary tract infection", label="CONDITION"),
    ])
    

    Classification

    from promptify import Classify
    
    clf = Classify(model="gpt-4o-mini", labels=["positive", "negative", "neutral"])
    result = clf("Amazing product! Best purchase I've ever made.")
    # Classification(label="positive", confidence=0.95)
    

    Question Answering

    from promptify import QA
    
    qa = QA(model="gpt-4o-mini")
    answer = qa("Einstein was born in Ulm in 1879.", question="Where was Einstein born?")
    # Answer(answer="Ulm", evidence="Einstein was born in Ulm", confidence=0.98)
    

    Custom Task with Any Pydantic Schema

    from promptify import Task
    from pydantic import BaseModel
    
    class MovieReview(BaseModel):
        sentiment: str
        rating: float
        key_themes: list[str]
    
    task = Task(model="gpt-4o", output_schema=MovieReview, instruction="Analyze this movie review.")
    review = task("Nolan's best work. Stunning visuals but the plot drags.")
    # MovieReview(sentiment="mostly positive", rating=7.5, key_themes=["visuals", "pacing"])
    

    Any Provider - Just Change the Model String

    ner_openai = NER(model="gpt-4o-mini")
    ner_claude = NER(model="claude-sonnet-4-20250514")
    ner_local  = NER(model="ollama/llama3")
    

    Batch Processing

    results = ner.batch(["text1", "text2", "text3"], max_concurrent=10)
    

    Async Support

    result = await ner.acall("Patient has diabetes")
    

    Built-in Evaluation

    from promptify.eval import evaluate
    
    scores = evaluate(task=ner, dataset=labeled_data, metrics=["precision", "recall", "f1"])
    # {"precision": 0.92, "recall": 0.88, "f1": 0.90}
    

    Features

    • 2-3 lines of code for any NLP task -no training data required
    • Pydantic structured outputs -type-safe results, not raw strings
    • Any LLM provider via LiteLLM -OpenAI, Anthropic, Google, Ollama, Azure, and 100+ more
    • Built-in tasks -NER, Classification (binary/multiclass/multilabel), QA, Summarization, Relation Extraction, SQL Generation, and more
    • Custom tasks -bring your own Pydantic schema for any structured output
    • Few-shot examples -easily add examples to improve accuracy
    • Domain specialization -pass domain="medical" or any domain for context-aware prompts
    • Batch processing -async concurrency under the hood for processing multiple texts
    • Async support -native await support with acall()
    • Evaluation framework -precision, recall, F1, accuracy, exact match, ROUGE metrics
    • Safe parser -fallback JSON completion for providers without native structured outputs (no eval())
    • Cost tracking -built-in token usage and cost monitoring via get_cost_summary()

    Supported NLP Tasks

    TaskClassOutput Schema
    Named Entity RecognitionNERNERResult (list of Entity)
    Binary ClassificationClassifyClassification
    Multiclass ClassificationClassifyClassification
    Multilabel ClassificationClassify(multi_label=True)MultiLabelResult
    Question AnsweringQAAnswer
    SummarizationSummarizeSummary
    Relation ExtractionExtractRelationsExtractionResult
    Tabular ExtractionExtractTableExtractionResult
    Question GenerationGenerateQuestionslist of GeneratedQuestion
    SQL GenerationGenerateSQLSQLQuery
    Text NormalizationNormalizeTextnormalized text
    Topic ModellingExtractTopicslist of topics
    Custom TaskTaskany Pydantic BaseModel

    Community

    
    @misc{Promptify2022,
      title = {Promptify: Structured Output from LLMs},
      author = {Pal, Ankit},
      year = {2022},
      howpublished = {\url{https://github.com/promptslab/Promptify}},
      note = {Prompt-Engineering components for NLP tasks in Python}
    }
    
    

    💁 Contributing

    We welcome any contributions to our open source project, including new features, improvements to infrastructure, and more comprehensive documentation. Please see the contributing guidelines