Promptify Documentation
repository·main·Indexed 26 days ago
https://github.com/promptslab/promptifyA 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.
What's inside promptify
- 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.
Core Features of Promptify
mainPromptify 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.
Install Promptify
mainInstall Promptify using pip. Requires Python 3.9+.
To install the base package:
pip install promptifyTo install from the GitHub repository:
pip install git+https://github.com/promptslab/Promptify.gitTo install with support for evaluation metrics:
pip install promptify[eval]pip install promptifyUse different LLM providers
mainPromptify uses LiteLLM as a backend, allowing you to use any provider by simply changing the
modelstring. 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")Install Promptify via pip
mainInstall the stable version of Promptify using pip. Requires Python 3.7+ and
openai0.25+.$ pip install promptifyConfigure OpenAI API Key for Promptify
mainPromptify uses OpenAI models (defaulting to
text-davinci-003). To use these models, you must provide anOPENAI_API_KEY. You can initialize thePrompterby passing anOpenAIclient instance configured with your API key.$ model = OpenAI(api_key="YOUR_API_KEY") $ nlp_prompter = Prompter(model)Install Promptify from source
mainYou 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.txtto install optional dependencies and tools used for development (e.g., unit testing).
Use the Pipeline API for NLP tasks
mainThe
PipelineAPI 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, orAzure), aPrompterwith a template (e.g.,'ner.jinja'), and then wrap them in aPipelineobject. 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.
Use Hugging Face Inference Endpoints for Production
mainFor 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_keydirectly toHubModel.model = HubModel("https://endpoint-id.region.vendor.endpoints.huggingface.cloud", api_key="hf_***")Initialize a Promptify Pipeline
mainTo create a processing pipeline, importPrompter,OpenAI, andPipelinefrompromptify. You must initialize anOpenAIinstance with your API key, aPrompterwith a Jinja template file, and then wrap them in aPipelineobject. The pipeline combines the prompting logic with the model execution.Initialize OpenAI and Prompter
mainTo use
promptify, first initialize a model provider (e.g.,OpenAI) with your API key, then pass that model instance to aPrompterto enable prompt generation.from promptify import OpenAI from promptify import Prompter model = OpenAI(api_key="") nlp_prompter = Prompter(model)Initialize OpenAI model and Prompter
mainTo use
promptifyfor NLP tasks, import theOpenAImodel class and thePrompterclass. Initialize theOpenAImodel with your API key, then pass that model instance into thePrompterto 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)