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.12.tar.gz (28.0 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.12-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file opty_prompt-0.1.12.tar.gz.

File metadata

  • Download URL: opty_prompt-0.1.12.tar.gz
  • Upload date:
  • Size: 28.0 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.12.tar.gz
Algorithm Hash digest
SHA256 1e48a98a2917e77b5bab6d692eee397a91742a1d20b55b427e840384f7beef0a
MD5 73d073392f0de02461b81453f3947098
BLAKE2b-256 20c1863a12336f7104f1f6b557367b920799791ff588fba3eb21141dd9e3b689

See more details on using hashes here.

Provenance

The following attestation bundles were made for opty_prompt-0.1.12.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.12-py3-none-any.whl.

File metadata

  • Download URL: opty_prompt-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 29.7 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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 7576fee892800513e992706ccc8b8409d8b59ae5c9c237c27922d94c0e365dab
MD5 bbd9f66fb9f0d859ab419482b7049913
BLAKE2b-256 c4260dbca6ad8fe625e5598b4b05f004ccdd28c229b45ece98ae52bb4c845387

See more details on using hashes here.

Provenance

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