Skip to main content

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

  1. Describe what you want your prompt to do, or load an existing draft from a file
  2. opty generates an initial prompt draft (the builder LLM), asking clarifying questions if needed
  3. Provide one example input and the ideal output you expect
  4. 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
  5. Based on that analysis, the refiner rewrites the prompt to steer the model in the right direction
  6. Steps 4–5 repeat until the output matches your target or the step limit is reached
  7. 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


Download files

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

Source Distribution

opty_prompt-0.1.1a0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

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

opty_prompt-0.1.1a0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file opty_prompt-0.1.1a0.tar.gz.

File metadata

  • Download URL: opty_prompt-0.1.1a0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opty_prompt-0.1.1a0.tar.gz
Algorithm Hash digest
SHA256 4ab074eb8fd33d53288157464aca4d2a2110fde7559434897f556abac3aeaf61
MD5 cb6cddc66a4f32b4b7576144517d47c5
BLAKE2b-256 0889c7019468503b140bbda4ed2ee7b8437f007ed1eaddec76338eea5f2f3bf5

See more details on using hashes here.

Provenance

The following attestation bundles were made for opty_prompt-0.1.1a0.tar.gz:

Publisher: publish.yml on eliodecolli/opty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opty_prompt-0.1.1a0-py3-none-any.whl.

File metadata

  • Download URL: opty_prompt-0.1.1a0-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

Hashes for opty_prompt-0.1.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e8c869bbb37f9afbd1fe1e86becdc6fd038f0b767ca0162efed0c71a9af224b
MD5 4d7c49862376624e5cfd2494497a3d2c
BLAKE2b-256 0aac9b7e9f9e468c31fee2d0d9f5383240e1218028940391554ad9595ec01ad0

See more details on using hashes here.

Provenance

The following attestation bundles were made for opty_prompt-0.1.1a0-py3-none-any.whl:

Publisher: publish.yml on eliodecolli/opty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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