Skip to main content

This package refines and optimizes prompts using a large language model (LLM) powered by https://www.aliyun.com/product/bailian

Project description

Prompt Refiner 🗑️

Python License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prompt_refiner_cb-0.0.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prompt_refiner_cb-0.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file prompt_refiner_cb-0.0.1.tar.gz.

File metadata

  • Download URL: prompt_refiner_cb-0.0.1.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

Hashes for prompt_refiner_cb-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9304150f5d72db181a2930514c13080a8cbe0a54db97739b75992c5402de4910
MD5 af519768d078d60c438cf51154fbd728
BLAKE2b-256 564622198ea0e59739ab0008b3d003bed9537516f344b7b41dee1e3e772b8662

See more details on using hashes here.

File details

Details for the file prompt_refiner_cb-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for prompt_refiner_cb-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 411f4ead3018661cbae842ad23860193476a6f23382a4fed2bf1d5d4396c4770
MD5 2da2d9ee354f86724e74bd04dd405e6a
BLAKE2b-256 e332ac649b8adf6febd9daf04b1911f797483f4a0b21cb979d80def75c5f32cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page