Metadata-Version: 2.4
Name: leo-prompt-optimizer
Version: 0.1.2
Summary: A Python library to optimize prompt drafts using LLMs
Author: Léonard Baesen-Wagner
Author-email: Leonard Baesen-Wagner <lr.baesen@gmail.com>
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: groq
Requires-Dist: python-dotenv
Dynamic: author
Dynamic: requires-python

# 🧠 leo-prompt-optimizer

**leo-prompt-optimizer** is a Python library that helps developers **optimize raw LLM prompts** into structured, high-performance instructions using real LLM intelligence.

It leverages **open-source models via [Groq API](https://console.groq.com/)** (like Mixtral or LLaMA 3), making it fast, affordable, and production-ready.

---

## 🚀 Features

- 🛠️ Refines vague, messy, or unstructured prompts
- 🧠 Follows a 9-step prompt engineering framework
- 🧩 Supports contextual optimization (with user input & LLM output)
- ⚡ Runs on blazing-fast open-source LLMs via Groq
- 🔐 Secure API key management with `.env` or helper function

---

## 📦 Installation

```bash
pip install leo-prompt-optimizer
````

---

## 🔧 Setup: API Key

You can provide your [Groq API key](https://console.groq.com/) in two ways:

### ✅ Option A: `.env` file (recommended)

At the root of your project:

```env
GROQ_API_KEY=sk-your-api-key-here
```

Then use as-is:

```python
from leo_prompt_optimizer import optimize_prompt
```

### ✅ Option B: Set programmatically

Useful in notebooks, scripts, or cloud functions:

```python
from leo_prompt_optimizer import set_groq_api_key, optimize_prompt

set_groq_api_key("sk-your-api-key")
```

---

## ✍️ Usage Example

```python
from leo_prompt_optimizer import optimize_prompt, set_groq_api_key

set_groq_api_key("sk-your-api-key")

draft = "I want to generate a structured planning for a GenAI course with communication adapted to enrolled members."

optimized = optimize_prompt(draft)
print(optimized)
```

---

## 📘 Output Format

The returned optimized prompt follows a structured format:

```text
Role:
[Define the LLM's persona]

Task:
[Clearly state the specific objective]

Instructions:
* Step-by-step subtasks

Context:
[Any relevant background, constraints, domain]

Output Format:
[e.g., bullet list, JSON, summary]

User Input:
[Original user input or example]
```

---

## 🧪 Quick Test (Optional)

You can run a built-in test script after installation to validate that everything works:

```bash
python3 test_import.py
```

This will check:

* Import is working ✅
* API key is detected ✅
* LLM call returns a result ✅

---

## 🧯 Common Errors & Fixes

| Error                  | Solution                                                                                               |
| ---------------------- | ------------------------------------------------------------------------------------------------------ |
| `Missing GROQ_API_KEY` | Make sure it's in `.env` or set with `set_groq_api_key()`                                              |
| `Invalid model` or 403 | The default model might be deprecated. Check Groq’s [model list](https://console.groq.com/docs/models) |
| `ModuleNotFoundError`  | Ensure `leo-prompt-optimizer` is installed in the current environment                                  |

---

## 💡 Why Use It?

Prompt quality is critical when building with LLMs.

**leo-prompt-optimizer** helps you:

* ✅ Make prompts explicit and structured
* 🚫 Reduce hallucinations
* 🔁 Increase consistency and repeatability
* 🧱 Standardize prompt formats across your stack

---

## 📄 License

MIT © 2025 \[Léonard Baesen-Wagner]
