# PromptPlanner
## Install
Python >=3.10
```bash
git clone https://github.com/SecretSettler/PromptPlanner.git
cd PromptPlanner
pip install -e .
```
## Data Format:
Currently we only support data with `jsonl` format. Each json should at least contain these attributes:
```json
{
"qid": 0,
"text": "Is the sky blue?",
"answer": ["Yes", "Yes the sky is blue"],
"top_k_doc_id": [2, 8, 1, 10]
}
```
## Quick usage
```python
from promptplanner.offline.clustering import cluster_prompts
from promptplanner.offline.inter_reordering import PromptProcessor
import json
import argparse
def parse_args():
parser = argparse.ArgumentParser(description="Reorder prompt data based on clustering results.")
parser.add_argument('--prompt_path', type=str, required=True, help='Path to the JSONL file containing prompt data.')
return parser.parse_args()
def main():
args = parse_args()
# Load prompts from the specified path
prompt_path = args.prompt_path
with open(prompt_path, 'r') as f:
prompts = [json.loads(line) for line in f]
qids = [prompt['qid'] for prompt in prompts]
questions = [prompt['text'] for prompt in prompts]
answers = [prompt['answer'] for prompt in prompts]
topk_doc_ids = [prompt['top_k_doc_id'] for prompt in prompts]
processer = PromptProcessor(use_gpu=True)
# Perform clustering (Intra-reordering)
result = cluster_prompts(topk_doc_ids, similarity_method="sharp", use_triton=True)
# Perform inter-reordering
organized_reordered_ids, _, final_index_mapping = processer.process_and_reorder(result.reordered_prompts, topk_doc_ids, show_progress=True)
# Results
reorded_qids = [qids[i] for i in final_index_mapping]
reorded_questions = [questions[i] for i in final_index_mapping]
reorded_answers = [answers[i] for i in final_index_mapping]
reorded_topk_doc_ids = organized_reordered_ids
return reorded_qids, reorded_questions, reorded_answers, reorded_topk_doc_ids
if __name__ == "__main__":
reorded_qids, reorded_questions, reorded_answers, reorded_topk_doc_ids = main()
```
The example code is in `examples/planner/example.py`
Raw data
{
"_id": null,
"home_page": null,
"name": "promptplanner",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "feed, reader, tutorial",
"author": "Yinsicheng Jiang, Chivier Humber",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/57/ec/8c98ceb8af36d6de0dcebaf0e5268320071160864daac1df0d1ebc6b510b/promptplanner-0.0.1.tar.gz",
"platform": null,
"description": "# PromptPlanner\n\n## Install\nPython >=3.10\n```bash\ngit clone https://github.com/SecretSettler/PromptPlanner.git\ncd PromptPlanner\npip install -e .\n```\n\n## Data Format:\nCurrently we only support data with `jsonl` format. Each json should at least contain these attributes:\n```json\n{\n \"qid\": 0,\n \"text\": \"Is the sky blue?\",\n \"answer\": [\"Yes\", \"Yes the sky is blue\"],\n \"top_k_doc_id\": [2, 8, 1, 10]\n}\n```\n\n## Quick usage\n```python\nfrom promptplanner.offline.clustering import cluster_prompts\nfrom promptplanner.offline.inter_reordering import PromptProcessor\nimport json\nimport argparse\n\ndef parse_args():\n parser = argparse.ArgumentParser(description=\"Reorder prompt data based on clustering results.\")\n parser.add_argument('--prompt_path', type=str, required=True, help='Path to the JSONL file containing prompt data.')\n return parser.parse_args()\n\ndef main():\n args = parse_args()\n \n # Load prompts from the specified path\n prompt_path = args.prompt_path\n with open(prompt_path, 'r') as f:\n prompts = [json.loads(line) for line in f]\n\n qids = [prompt['qid'] for prompt in prompts]\n questions = [prompt['text'] for prompt in prompts]\n answers = [prompt['answer'] for prompt in prompts]\n topk_doc_ids = [prompt['top_k_doc_id'] for prompt in prompts]\n\n\n processer = PromptProcessor(use_gpu=True)\n # Perform clustering (Intra-reordering)\n result = cluster_prompts(topk_doc_ids, similarity_method=\"sharp\", use_triton=True)\n # Perform inter-reordering\n organized_reordered_ids, _, final_index_mapping = processer.process_and_reorder(result.reordered_prompts, topk_doc_ids, show_progress=True)\n\n # Results\n reorded_qids = [qids[i] for i in final_index_mapping]\n reorded_questions = [questions[i] for i in final_index_mapping]\n reorded_answers = [answers[i] for i in final_index_mapping]\n reorded_topk_doc_ids = organized_reordered_ids\n return reorded_qids, reorded_questions, reorded_answers, reorded_topk_doc_ids\n\nif __name__ == \"__main__\":\n reorded_qids, reorded_questions, reorded_answers, reorded_topk_doc_ids = main()\n```\n\nThe example code is in `examples/planner/example.py`\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Prompt Execution Path Selection in Retrieval-Based LLM Inference Systems",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/SecretSettler/PromptPlanner"
},
"split_keywords": [
"feed",
" reader",
" tutorial"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "b7b2bc0f8f2c4d7e792c2dd2ae34989a688c0dc0a0105971dbfe6601acbd2ea4",
"md5": "c3a40138eb1b0f7c4790341af9cad421",
"sha256": "64a8bf755aa135384e1fe05ec3bbe72841f1ceba87a8b9baa83851efbbebe5d8"
},
"downloads": -1,
"filename": "promptplanner-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c3a40138eb1b0f7c4790341af9cad421",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 38506,
"upload_time": "2025-08-25T22:47:02",
"upload_time_iso_8601": "2025-08-25T22:47:02.405030Z",
"url": "https://files.pythonhosted.org/packages/b7/b2/bc0f8f2c4d7e792c2dd2ae34989a688c0dc0a0105971dbfe6601acbd2ea4/promptplanner-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "57ec8c98ceb8af36d6de0dcebaf0e5268320071160864daac1df0d1ebc6b510b",
"md5": "4df15c8231643ddd73486405ddfaf90c",
"sha256": "b7fb11e8af839ce8a3a1da87e5e0545d2f62018a82f302cec2394fe338daf4b1"
},
"downloads": -1,
"filename": "promptplanner-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "4df15c8231643ddd73486405ddfaf90c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 33481,
"upload_time": "2025-08-25T22:47:03",
"upload_time_iso_8601": "2025-08-25T22:47:03.849757Z",
"url": "https://files.pythonhosted.org/packages/57/ec/8c98ceb8af36d6de0dcebaf0e5268320071160864daac1df0d1ebc6b510b/promptplanner-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-25 22:47:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SecretSettler",
"github_project": "PromptPlanner",
"github_not_found": true,
"lcname": "promptplanner"
}