Promptify Documentation

repository·main·Indexed 26 days ago

https://github.com/promptslab/promptify

A task-based NLP engine designed for structured, type-safe outputs from LLMs using Pydantic and a LiteLLM backend. It provides a high-level abstraction for common NLP tasks including Named Entity Recognition (NER), Text Classification (binary, multiclass, and multilabel), and Question Answering (QA). Promptify supports a wide range of providers such as OpenAI, Anthropic, Google, and Hugging Face, and includes features for batch processing, async support, and task evaluation using metrics like precision, recall, and F1.

Tokens
6.6K
Snippets
29
Records
47
Agent score
88%

What's inside promptify

  1. Introduction to Promptify

    main
    Promptify is a software tool designed for Prompt Engineering, allowing users to solve Natural Language Processing (NLP) problems by generating tailored prompts for various generative models (e.g., GPT, Claude, Azure, PaLM, Cohere, Anthropic, and Huggingface). It acts as a universal language model adapter, simplifying the process of generating text like product descriptions, summaries, and more.
  2. Core Features of Promptify

    main

    Promptify provides several key capabilities for NLP tasks:

    • Prompt Generation: Tailor prompts for state-of-the-art generative models.
    • Unified Architecture: Utilizes a Prompter, Model, and Pipeline solution.
    • Detailed Output Logs: Generates comprehensive structured JSON output within a log folder.
    • Wider Model Support: Supports models from OpenAI, Azure, Cohere, Anthropic, Huggingface, and more.
    • Robust Parser: Handles incomplete or unstructured JSON outputs from LLMs.
    • Ready-Made Jinja Templates: Includes templates for NER, Text Classification, QA, Relation-Extraction, Tabular data, etc.
    • Rich Customization: Adapt prompts for specific needs like creative writing or summaries.
  3. Install Promptify

    main

    Install Promptify using pip. Requires Python 3.9+.

    To install the base package:

    pip install promptify

    To install from the GitHub repository:

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

    To install with support for evaluation metrics:

    pip install promptify[eval]
    pip install promptify
  4. Use different LLM providers

    main

    Promptify uses LiteLLM as a backend, allowing you to use any provider by simply changing the model string. Supported providers include OpenAI, Anthropic, Google, Ollama, Azure, and 100+ others.

    ner_openai = NER(model="gpt-4o-mini")
    ner_claude = NER(model="claude-sonnet-4-20250514")
    ner_local  = NER(model="ollama/llama3")
  5. Install Promptify from source

    main

    You can install Promptify directly from the GitHub repository or perform an editable installation for development purposes.

    • Direct from GitHub: Installs the package from the repository.
    • Editable Install: Use -e . to allow modifications to the source files.
    • Development Dependencies: Use requirements.txt to install optional dependencies and tools used for development (e.g., unit testing).
  6. Use the Pipeline API for NLP tasks

    main

    The Pipeline API allows you to immediately perform NLP tasks (like Named Entity Recognition) using an LLM model and a prompt template.

    To use it, you need to initialize a model (e.g., OpenAI, HubModel, or Azure), a Prompter with a template (e.g., 'ner.jinja'), and then wrap them in a Pipeline object. Use the .fit() method to run inference on your text.

    Key Parameters for .fit():

    • sentence: The input text string.
    • domain: (Optional) The domain of the text (e.g., "medical").
    • labels: (Optional) A list of labels. If omitted, the model automatically infers labels from the text. If provided, the model uses your specific labels.
  7. Use Hugging Face Inference Endpoints for Production

    main

    For production environments, instead of using the free Inference API, use a dedicated Hugging Face Inference Endpoint URL. You can switch to a production-ready setup by passing the endpoint URL and your api_key directly to HubModel.

    model = HubModel("https://endpoint-id.region.vendor.endpoints.huggingface.cloud", api_key="hf_***")
  8. Initialize a Promptify Pipeline

    main
    To create a processing pipeline, import Prompter, OpenAI, and Pipeline from promptify. You must initialize an OpenAI instance with your API key, a Prompter with a Jinja template file, and then wrap them in a Pipeline object. The pipeline combines the prompting logic with the model execution.
  9. Initialize OpenAI and Prompter

    main

    To use promptify, first initialize a model provider (e.g., OpenAI) with your API key, then pass that model instance to a Prompter to enable prompt generation.

    from promptify import OpenAI
    from promptify import Prompter
    
    model = OpenAI(api_key="")
    nlp_prompter = Prompter(model)
  10. Initialize OpenAI model and Prompter

    main

    To use promptify for NLP tasks, import the OpenAI model class and the Prompter class. Initialize the OpenAI model with your API key, then pass that model instance into the Prompter to create an NLP-capable prompter.

    from promptify.models.nlp.openai_model import OpenAI
    from promptify.prompts.nlp.prompter import Prompter
    
    model = OpenAI(api_key="YOUR_API_KEY")
    nlp_prompter = Prompter(model)