Prompt optimization via chain-of-thought
Project description
opty
Prompt optimization via chain-of-thought.
opty helps you fine-tune your LLM prompts using a judge LLM and iterative chain-of-thought refinement. Provide a description, give one or two input/output examples, and opty will automatically improve your prompt until the target model's output matches your expectations.
How it works
- Describe what you want your prompt to do, or load an existing draft from a file
- opty generates an initial prompt draft (the builder LLM), asking clarifying questions if needed
- Provide one example input and the ideal output you expect
- opty runs your draft prompt against the example input using the refiner LLM, captures its chain-of-thought, and analyzes where the thinking went wrong
- Based on that analysis, the refiner rewrites the prompt to steer the model in the right direction
- Steps 4–5 repeat until the output matches your target or the step limit is reached
- The final optimized prompt is saved to a file of your choice
Installation
pip install opty-prompt
Usage
Create an opty.config.yaml in your working directory, then run:
opty-prompt
Configuration
opty has two independent roles:
- Builder — generates the initial prompt draft from your description. This is a straightforward text generation task, so it works well with smaller, faster models.
- Refiner — evaluates the prompt against your example, reads the model's chain-of-thought, and rewrites the prompt accordingly. This requires stronger reasoning, so it benefits significantly from a more capable model.
Each role is configured independently and can use a different provider and model. You can freely mix and match Gemini and Ollama for either role.
All Gemini
config:
builder:
type: gemini
model: gemini-2.5-flash
api-key: <your-api-key>
refiner:
type: gemini
max-steps: 4
model: gemini-2.5-flash
api-key: <your-api-key>
All Ollama (local)
config:
builder:
type: ollama
model: gemma3:4b-it-qat # smaller model is fine for building
ollama-server: http://127.0.0.1:11434
refiner:
type: ollama
max-steps: 4
model: gemma3:12b-it-qat # use a stronger model for refinement
ollama-server: http://127.0.0.1:11434
Mixed: Ollama builder + Gemini refiner
Run a lightweight local model for drafting and offload the heavier refinement reasoning to Gemini:
config:
builder:
type: ollama
model: gemma3:4b-it-qat
ollama-server: http://127.0.0.1:11434
refiner:
type: gemini
max-steps: 4
model: gemini-2.5-flash
api-key: <your-api-key>
Mixed: Gemini builder + Ollama refiner
config:
builder:
type: gemini
model: gemini-2.5-flash
api-key: <your-api-key>
refiner:
type: ollama
max-steps: 4
model: gemma3:12b-it-qat
ollama-server: http://127.0.0.1:11434
Configuration reference
Shared — all types
These keys apply to both builder and refiner regardless of the provider:
| Key | Required | Description |
|---|---|---|
type |
Yes | Provider to use. One of: gemini, ollama |
Shared — refiner only
| Key | Required | Default | Description |
|---|---|---|---|
max-steps |
No | 4 |
Maximum number of refinement iterations before stopping |
Gemini
| Key | Required | Description |
|---|---|---|
model |
Yes | Gemini model name (e.g. gemini-2.5-flash, gemini-2.5-pro) |
api-key |
Yes | Your Google Gemini API key |
Ollama
| Key | Required | Description |
|---|---|---|
model |
Yes | Ollama model tag (e.g. gemma3:4b-it-qat, llama3.1:8b) |
ollama-server |
Yes | Base URL of your Ollama server (e.g. http://127.0.0.1:11434) |
Model size guidance
| Role | Requirements | Examples |
|---|---|---|
| Builder | Light — basic instruction following | gemma3:4b, gemini-2.5-flash |
| Refiner | Heavy — strong reasoning and chain-of-thought | gemma3:12b+, gemini-2.5-pro |
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 opty_prompt-0.1.11.tar.gz.
File metadata
- Download URL: opty_prompt-0.1.11.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d408bfd616a9f44a8f5d05fd145a818431a010c63bf7496d3df4501cb5071d8
|
|
| MD5 |
8fc6fe9e4c0ecab5b64e456719ae38dc
|
|
| BLAKE2b-256 |
c46565d0c5e2b53665156c4a1bcc9d381bad4dfb073c2cf8c83f6f2901843fbd
|
Provenance
The following attestation bundles were made for opty_prompt-0.1.11.tar.gz:
Publisher:
publish.yml on eliodecolli/opty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opty_prompt-0.1.11.tar.gz -
Subject digest:
0d408bfd616a9f44a8f5d05fd145a818431a010c63bf7496d3df4501cb5071d8 - Sigstore transparency entry: 952267815
- Sigstore integration time:
-
Permalink:
eliodecolli/opty@bbf743a9ce966da8f87757783c2559b45b0fcb0d -
Branch / Tag:
refs/tags/v0.1.11 - Owner: https://github.com/eliodecolli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bbf743a9ce966da8f87757783c2559b45b0fcb0d -
Trigger Event:
push
-
Statement type:
File details
Details for the file opty_prompt-0.1.11-py3-none-any.whl.
File metadata
- Download URL: opty_prompt-0.1.11-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2d932fdc7366b689b2c3cfea4edc3f16b9fe2fcad6c49667ada5f94e880c94d
|
|
| MD5 |
9d0b2e0196c728db017a794bd557d547
|
|
| BLAKE2b-256 |
b111979c89c67f972a25721994648fb49aad9720917fbe8e62101eb90ca90826
|
Provenance
The following attestation bundles were made for opty_prompt-0.1.11-py3-none-any.whl:
Publisher:
publish.yml on eliodecolli/opty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opty_prompt-0.1.11-py3-none-any.whl -
Subject digest:
a2d932fdc7366b689b2c3cfea4edc3f16b9fe2fcad6c49667ada5f94e880c94d - Sigstore transparency entry: 952267817
- Sigstore integration time:
-
Permalink:
eliodecolli/opty@bbf743a9ce966da8f87757783c2559b45b0fcb0d -
Branch / Tag:
refs/tags/v0.1.11 - Owner: https://github.com/eliodecolli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bbf743a9ce966da8f87757783c2559b45b0fcb0d -
Trigger Event:
push
-
Statement type: