Skip to main content

onpanda: The Companion Python Package for onPanda

Python package for onPanda: Efficient Annotation of On-Policy Alignment Data for LLMs and Agents via Token-Level Correction [project page]

Contents: Features | Install | Example Data | Quick Start | Main Modules | Iterative Correction API | Data Assumptions

▮ Features

  • Parse .panda.json into SFT and preference-pair data (build_legacy_data_v1)
  • Build token-level supervision data (build_token_level_supervision_data_v1/v2)
  • Build Find-and-Replace correction training data (build_far_correction_data_v1)
  • Verify and score Find-and-Replace outputs (FindAndReplaceVerifier)
  • Benchmark Panda-CVL dataset
  • Run iterative correction as a Proxy API (onpanda.server.iterative_correction_api)
  • Build panda battle data from two arena result sets (build_panda_battle)

▮ Install

pip install onpanda -U

# Or want to run demos.
git clone https://github.com/on-panda/on-panda-python.git
pip install -e ./on-panda-python

# Example Data for demo
git clone https://github.com/on-panda/on-panda-example-data.git
ls on-panda-example-data/panda_json/

If you want to use tokenizers, install transformers separately.

▮ Quick Start

import onpanda

panda_path = (
    "../on-panda-example-data/panda_json/"
    "2025-08-19_how-many-1s_tokenizer-Qwen2.5.panda.json"
)
tokenizer=onpanda.utf8_tokenizer
# Use built-in utf8_tokenizer for a minimal runnable flow.
tree = onpanda.PandaTree(panda_path, tokenizer)

# 1) SFT + preference pairs
legacy = tree.build_legacy_data_v1()
print("sfts:", len(legacy["sfts"]))
print("preferences:", len(legacy["preferences"]))

# 2) Token-level supervision
token_level_v1 = tree.build_token_level_supervision_data_v1(
    tokenizer
)
print("token_level_v1:", len(token_level_v1))

# 3) Find-and-Replace correction data
adapter = onpanda.FindAndReplaceCorrectionAdapter(
    tokenizer
)
correction_data = tree.build_far_correction_data_v1(adapter)
print("correction_data:", len(correction_data))

Build from plain chat messages:

import onpanda

messages = [
    {"role": "user", "content": "5+7=?"},
    {"role": "assistant", "content": "12"},
]
panda_json = onpanda.messages_to_panda_tree(messages, uuid="demo")
# dump to xxx.panda.json

▮ Main Modules

  • onpanda/parser.py: PandaTree and data conversion entrypoints
  • onpanda/token_level_supervision_utils.py: token-level patch extraction and masks
  • onpanda/correcting_model/far_correction_utils.py: FAR data builder and apply logic
  • onpanda/correcting_model/verifier.py: FAR parser/locator/reward computation
  • onpanda/correcting_model/panda_score_mixin.py: evaluation correction ability on Panda JSON
  • onpanda/correcting_model/correcting_model.py: iterative correction workflow
  • onpanda/server/iterative_correction_api.py: Flask wrapper for correction service
  • onpanda/arena/panda_battle.py: build battle-style comparison data

▮ Iterative Correction API

Launch a proxy API server that return response using iterative_correction

python -m onpanda.server.iterative_correction_api --help

▮ Data Assumptions

  • PandaTree is a parser for qualified, annotated Panda JSON.
  • PandaTree preprocessing currently assumes:
    • Top-level field dialogs exists
    • Top-level field update_time exists
    • At least one dialog ends with an assistant message
    • If annotate.is_good is missing, latest dialog is treated as default good

Download files

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

Source Distribution

onpanda-0.1.6.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

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

onpanda-0.1.6-py3-none-any.whl (58.0 kB view details)

Uploaded Python 3

File details

Details for the file onpanda-0.1.6.tar.gz.

File metadata

  • Download URL: onpanda-0.1.6.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for onpanda-0.1.6.tar.gz
Algorithm Hash digest
SHA256 b1d38f4dbca156e98d9d2cc3d6a00f8591434deeb92ad91989b86fd39824ad7e
MD5 164187972c201b4780d7add1f9bd10f9
BLAKE2b-256 43d1b58c0125eeac499b925f9e493100abd55155865562e03731c8dd08ce763a

See more details on using hashes here.

File details

Details for the file onpanda-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: onpanda-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 58.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for onpanda-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8917e3db0508e97aec51565f130d1f78f3c5aa53300a314554ee675a11b2e1f0
MD5 1bc7eec8c5adceb9deaafd0420ceda8b
BLAKE2b-256 82bcbbee106f29e0fc308869adccd5b5c746dc5d2372dfa165702aa5b08ed884

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.7

2 files

This release

0.1.6 This release

2 files

0.1.5

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page