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.11.tar.gz (25.9 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.11-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

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

Hashes for opty_prompt-0.1.11.tar.gz
Algorithm Hash digest
SHA256 0d408bfd616a9f44a8f5d05fd145a818431a010c63bf7496d3df4501cb5071d8
MD5 8fc6fe9e4c0ecab5b64e456719ae38dc
BLAKE2b-256 c46565d0c5e2b53665156c4a1bcc9d381bad4dfb073c2cf8c83f6f2901843fbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for opty_prompt-0.1.11.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.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

Hashes for opty_prompt-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 a2d932fdc7366b689b2c3cfea4edc3f16b9fe2fcad6c49667ada5f94e880c94d
MD5 9d0b2e0196c728db017a794bd557d547
BLAKE2b-256 b111979c89c67f972a25721994648fb49aad9720917fbe8e62101eb90ca90826

See more details on using hashes here.

Provenance

The following attestation bundles were made for opty_prompt-0.1.11-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