MCPcopy Index your code
hub / github.com/promptslab/Promptify

github.com/promptslab/Promptify @v2.0.0

repository ↗ · DeepWiki ↗ · release v2.0.0 ↗ · Ask this repo → · + Follow
199 symbols 619 edges 63 files 53 documented · 27% updated 3mo ago★ 4,61848 open issues
README

Promptify

Prompt Engineering, Solve NLP Problems with LLM's & Easily generate different NLP Task prompts for popular generative models like GPT, PaLM, and more with Promptify

Promptify is released under the Apache 2.0 license. PyPI version http://makeapullrequest.com Community colab

Installation

With pip

This repository is tested on Python 3.7+, openai 0.25+.

You should install Promptify using Pip command

pip3 install promptify

or

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

Quick tour

To immediately use a LLM model for your NLP task, we provide the Pipeline API.

from promptify import Prompter,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(api_key) # or `HubModel()` for Huggingface-based inference or 'Azure' etc
prompter     = Prompter('ner.jinja') # select a template or provide custom template
pipe         = Pipeline(prompter , model)


result = pipe.fit(sentence, domain="medical", labels=None)


### Output

[
    {"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"},
]

GPT-3 Example with NER, MultiLabel, Question Generation Task

Features 🎮

  • Perform NLP tasks (such as NER and classification) in just 2 lines of code, with no training data required
  • Easily add one shot, two shot, or few shot examples to the prompt
  • Handling out-of-bounds prediction from LLMS (GPT, t5, etc.)
  • Output always provided as a Python object (e.g. list, dictionary) for easy parsing and filtering. This is a major advantage over LLMs generated output, whose unstructured and raw output makes it difficult to use in business or other applications.
  • Custom examples and samples can be easily added to the prompt
  • 🤗 Run inference on any model stored on the Huggingface Hub (see notebook guide).
  • Optimized prompts to reduce OpenAI token costs (coming soon)
### Supporting wide-range of Prompt-Based NLP tasks : | Task Name | Colab Notebook | Status | |-------------|-------|-------| | Named Entity Recognition | [NER Examples with GPT-3](https://colab.research.google.com/drive/16DUUV72oQPxaZdGMH9xH1WbHYu6Jqk9Q?usp=sharing) | ✅ | | Multi-Label Text Classification | [Classification Examples with GPT-3](https://colab.research.google.com/drive/1gNqDxNyMMUO67DxigzRAOa7C_Tcr2g6M?usp=sharing) | ✅ | | Multi-Class Text Classification | [Classification Examples with GPT-3](https://colab.research.google.com/drive/1gNqDxNyMMUO67DxigzRAOa7C_Tcr2g6M?usp=sharing) | ✅ | | Binary Text Classification | [Classification Examples with GPT-3](https://colab.research.google.com/drive/1gNqDxNyMMUO67DxigzRAOa7C_Tcr2g6M?usp=sharing) | ✅ | | Question-Answering | [QA Task Examples with GPT-3](https://colab.research.google.com/drive/1Yhl7iFb7JF0x89r1L3aDuufydVWX_VrL?usp=sharing) | ✅ | | Question-Answer Generation | [QA Task Examples with GPT-3](https://colab.research.google.com/drive/1Yhl7iFb7JF0x89r1L3aDuufydVWX_VrL?usp=sharing) | ✅ | | Relation-Extraction | [Relation-Extraction Examples with GPT-3](https://colab.research.google.com/drive/1iW4QNjllc8ktaQBWh3_04340V-tap1co?usp=sharing) | ✅ | | Summarization | [Summarization Task Examples with GPT-3](https://colab.research.google.com/drive/1PlXIAMDtrK-RyVdDhiSZy6ztcDWsNPNw?usp=sharing) | ✅ | | Explanation | [Explanation Task Examples with GPT-3](https://colab.research.google.com/drive/1PlXIAMDtrK-RyVdDhiSZy6ztcDWsNPNw?usp=sharing) | ✅ | | SQL Writer | [SQL Writer Example with GPT-3](https://colab.research.google.com/drive/1JNUYCTdqkdeIAxiX-NzR-4dngdmWj0rV?usp=sharing) | ✅ | | Tabular Data | | | | Image Data | | | | More Prompts | | | ## Docs [Promptify Docs](https://promptify.readthedocs.io/) ## Community If you are interested in Prompt-Engineering, LLMs, ChatGPT and other latest research discussions, please consider joining PromptsLab Join us on Discord

@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](contribute.md)

Core symbols most depended-on inside this repo

fit
called by 19
promptify/parser/parser.py
get
called by 10
promptify/prompter/prompt_cache.py
model_output
called by 5
promptify/models/text2text/api/base_model.py
load_template
called by 5
promptify/prompter/template_loader.py
is_valid_json
called by 4
promptify/parser/parser.py
escaped_
called by 4
promptify/parser/parser.py
complete_json_object
called by 4
promptify/parser/parser.py
run
called by 4
promptify/models/text2text/api/base_model.py

Shape

Method 143
Function 41
Class 15

Languages

Python100%

Modules by API surface

promptify/models/text2text/api/openai_models.py18 symbols
promptify/models/text2text/api/azure_openai.py18 symbols
promptify/models/text2text/api/anthropic.py14 symbols
promptify/models/text2text/api/cohere.py13 symbols
promptify/models/text2text/api/base_model.py13 symbols
tests/unit_tests/prompter/test_prompter.py12 symbols
promptify/models/text2text/api/hub_model.py12 symbols
promptify/models/text2text/api/mock_model.py11 symbols
tests/unit_tests/models/test_base_model.py10 symbols
promptify/parser/parser.py10 symbols
tests/unit_tests/models/test_openai_model.py9 symbols
promptify/prompter/template_loader.py9 symbols

Dependencies from manifests, versioned

anthropic0.3.4 · 1×
appdirs1.4.4 · 1×
black22.12.0 · 1×
cohere4.13.1 · 1×
flake86.0.0 · 1×
huggingface_hub0.12 · 1×
isort5.11.4 · 1×
jinja22.11.3 · 1×
markupsafe2.0.1 · 1×
openai0.27.0 · 1×
pytest7.2.2 · 1×
regex2022.10.31 · 1×

For agents

$ claude mcp add Promptify \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact