This package refines and optimizes prompts using a large language model (LLM) powered by https://www.aliyun.com/product/bailian
Project description
Prompt Refiner 🗑️
Prompt Refiner is a Python module to refine and optimize prompts for large language models (LLMs) using Alibaba Cloud Bailian. It helps improve clarity, specificity, and overall effectiveness of prompts effortlessly.
Features
PromptRefiner.refine(prompt)— Refine any user prompt.PromptRefiner.refine_system_prompt()— Refine the internal system prompt.
Quick Install
pip install prompt_refiner_cb
Note: Requires a valid LLM API key (Aliyun Bailian).
Usage
from prompt_refiner import PromptRefiner
# Initialize the refiner
refiner = PromptRefiner(api_key="YOUR_LLM_API_KEY")
# Refine a user prompt
user_prompt = "Write a story about a dragon and a princess."
refined_prompt = refiner.refine(user_prompt)
print(refined_prompt)
# Refine the system prompt itself
refined_system = refiner.refine_system_prompt()
print(refined_system)
Environment Variables
Create a .env file in your project root:
LLM_API_KEY="your_api_key_here"
Pipenv or your environment will automatically load this variable.
API Reference
PromptRefiner(api_key=None, model="deepseek-r1")
Initialize the refiner. Uses the environment variable LLM_API_KEY if api_key is not provided.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str | None |
LLM API key. |
model |
str | "deepseek-r1" |
LLM model to use. |
refine(prompt, system_prompt=None, temperature=0)
Refine a user prompt.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
prompt |
str | - | The text to refine. |
system_prompt |
str | _SYSTEM_PROMPT |
Optional system instructions guiding refinement. |
temperature |
float | 0 | Sampling temperature (controls creativity). |
Returns: str — The refined prompt.
refine_system_prompt(temperature=0)
Refines the internal system prompt itself.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
temperature |
float | 0 | Sampling temperature for refinement. |
Returns: str — The refined system prompt.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prompt_refiner_cb-0.0.2.tar.gz.
File metadata
- Download URL: prompt_refiner_cb-0.0.2.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
443bea5f83d1d998491c56fd463dd78112b77b2ace5af025412fd7080a41f74f
|
|
| MD5 |
504cd4d00145b523a604dec2f8e2ab25
|
|
| BLAKE2b-256 |
297fecd9cd1d58aee34ac0d934c102aa6f3d63e0e4c4f64aa91fb06444435701
|
File details
Details for the file prompt_refiner_cb-0.0.2-py3-none-any.whl.
File metadata
- Download URL: prompt_refiner_cb-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52f94fc6009aec50f1050bde266970be52a62cefc0da98b35883fea4f0b9cae7
|
|
| MD5 |
eb3076d93cae889f97231f4fb3363b0a
|
|
| BLAKE2b-256 |
568eb03b1a7e84f87340b9fd35cdcd76a7d13f6d6f7ec05a986c202b74a74018
|