1
0
Fork 0
mirror of https://github.com/p-e-w/heretic.git synced 2026-12-03 18:42:57 +07:00

[PR #53] [MERGED] feat: generic plugin system #259

Closed
opened 2026-11-01 04:19:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/p-e-w/heretic/pull/53
Author: @red40maxxer
Created: 11/27/2025
Status: ✅ Merged
Merged: 7/7/2026
Merged by: @p-e-w

Base: master ← Head: refusal-plugins


📝 Commits (10+)

  • a4a97c7 style: ruff
  • 7f0562b feat(wip): populate metadata fields and allow plugins to declare what they need
  • d1f1428 refactor: extract metadata logic to separate module
  • 9d9530a style: placate ruff
  • d7964e9 chore: use eos token for inferring finish reason with fallback
  • 81c0913 fix: handle empty responses better
  • db1a3b6 style: ruff
  • 8b62b58 refactor: combine response text and metadata into single object
  • ee3090e refactor: clean up tagger and scorer usage
  • ad69824 style: ruff

📊 Changes

20 files changed (+1177 additions, -389 deletions)

View changed files

📝 README.md (+8 -8)
📝 config.default.toml (+63 -43)
📝 config.nohumor.toml (+19 -18)
📝 config.noslop.toml (+24 -23)
📝 src/heretic/analyzer.py (+2 -2)
📝 src/heretic/config.py (+55 -77)
📝 src/heretic/evaluator.py (+225 -89)
📝 src/heretic/main.py (+101 -64)
📝 src/heretic/model.py (+22 -27)
➕ src/heretic/plugin.py (+289 -0)
➕ src/heretic/scorer.py (+68 -0)
➕ src/heretic/scorers/__init__.py (+0 -0)
➕ src/heretic/scorers/keyword_rate.py (+134 -0)
➕ src/heretic/scorers/kl_divergence.py (+71 -0)
📝 src/heretic/utils.py (+76 -25)
📝 tests/gemma-4e/config.toml (+2 -3)
📝 tests/minicpm5/config.toml (+7 -2)
📝 tests/mistral-3/config.toml (+2 -3)
📝 tests/qwen2.5/config.toml (+7 -2)
📝 tests/qwen3.5-moe/config.toml (+2 -3)

📄 Description

Refactors refusal detection and refusal counting into a modular plugin system. This allows for arbitrary logic (regex, embeddings, external models) to be added without modifying core code.

Plugin system

  • Scorers take in responses and optional response metadata and produce a single Score that Optuna can use for optimization, eg. ["I can't help you with that.", "Certainly!"] -> 0.67. By default, this is the KL divergence and refusal rate.
  • You can add a new plugin by subclassing from Scorer, adding implementations for the abstract methods and add ScorerClassName.property in the config.toml for any user-defined configuration you need. Make sure the config fields are defined in a PluginSettings - look at KeywordRate and KLDivergence for reference.
  • Convenience methods for the Scorer to access important outputs from Model are provided through Context, such as get_responses(), get_logits(), etc.
  • Multiple instances of the same scorer are supported with optional configuration overrides in the config TOML. These are defined at the top level along with the optimization direction and scaling factor (if needed). To configure those instances specifically, create a table with the name ScorerClassName_InstanceName.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/p-e-w/heretic/pull/53 **Author:** [@red40maxxer](https://github.com/red40maxxer) **Created:** 11/27/2025 **Status:** ✅ Merged **Merged:** 7/7/2026 **Merged by:** [@p-e-w](https://github.com/p-e-w) **Base:** `master` ← **Head:** `refusal-plugins` --- ### 📝 Commits (10+) - [`a4a97c7`](https://github.com/p-e-w/heretic/commit/a4a97c731479bf14fb34b89af51c03007e5e487f) style: ruff - [`7f0562b`](https://github.com/p-e-w/heretic/commit/7f0562b7c625ea6daa06dc0b75e112a9ff9998f1) feat(wip): populate metadata fields and allow plugins to declare what they need - [`d1f1428`](https://github.com/p-e-w/heretic/commit/d1f1428a660e0fb07d3d7ae6767ea4d66401a02b) refactor: extract metadata logic to separate module - [`9d9530a`](https://github.com/p-e-w/heretic/commit/9d9530a62cd4dc24da7b642d01c9ec851e29d50c) style: placate ruff - [`d7964e9`](https://github.com/p-e-w/heretic/commit/d7964e97f1d22b4bd779df364ce8b640da4746ee) chore: use eos token for inferring finish reason with fallback - [`81c0913`](https://github.com/p-e-w/heretic/commit/81c091354e9afdd764b3ee33693c403e576a5016) fix: handle empty responses better - [`db1a3b6`](https://github.com/p-e-w/heretic/commit/db1a3b6494f05528d3b66e633e588138cc9173fb) style: ruff - [`8b62b58`](https://github.com/p-e-w/heretic/commit/8b62b58bc771c857f7acdba70a4806af9c822695) refactor: combine response text and metadata into single object - [`ee3090e`](https://github.com/p-e-w/heretic/commit/ee3090e1108414b895ad00b1c22baf4aa3d6378d) refactor: clean up tagger and scorer usage - [`ad69824`](https://github.com/p-e-w/heretic/commit/ad698246b9baceb25279917cf87cb7751447e985) style: ruff ### 📊 Changes **20 files changed** (+1177 additions, -389 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+8 -8) 📝 `config.default.toml` (+63 -43) 📝 `config.nohumor.toml` (+19 -18) 📝 `config.noslop.toml` (+24 -23) 📝 `src/heretic/analyzer.py` (+2 -2) 📝 `src/heretic/config.py` (+55 -77) 📝 `src/heretic/evaluator.py` (+225 -89) 📝 `src/heretic/main.py` (+101 -64) 📝 `src/heretic/model.py` (+22 -27) ➕ `src/heretic/plugin.py` (+289 -0) ➕ `src/heretic/scorer.py` (+68 -0) ➕ `src/heretic/scorers/__init__.py` (+0 -0) ➕ `src/heretic/scorers/keyword_rate.py` (+134 -0) ➕ `src/heretic/scorers/kl_divergence.py` (+71 -0) 📝 `src/heretic/utils.py` (+76 -25) 📝 `tests/gemma-4e/config.toml` (+2 -3) 📝 `tests/minicpm5/config.toml` (+7 -2) 📝 `tests/mistral-3/config.toml` (+2 -3) 📝 `tests/qwen2.5/config.toml` (+7 -2) 📝 `tests/qwen3.5-moe/config.toml` (+2 -3) </details> ### 📄 Description Refactors refusal detection and refusal counting into a modular plugin system. This allows for arbitrary logic (regex, embeddings, external models) to be added without modifying core code. ## Plugin system - `Scorers` take in responses and optional response metadata and produce a single `Score` that Optuna can use for optimization, eg. `["I can't help you with that.", "Certainly!"] -> 0.67`. By default, this is the KL divergence and refusal rate. - You can add a new plugin by subclassing from `Scorer`, adding implementations for the abstract methods and add `ScorerClassName.property` in the `config.toml` for any user-defined configuration you need. Make sure the config fields are defined in a `PluginSettings` - look at `KeywordRate` and `KLDivergence` for reference. - Convenience methods for the `Scorer` to access important outputs from `Model` are provided through `Context`, such as `get_responses()`, `get_logits()`, etc. - Multiple instances of the same scorer are supported with optional configuration overrides in the config TOML. These are defined at the top level along with the optimization direction and scaling factor (if needed). To configure those instances specifically, create a table with the name `ScorerClassName_InstanceName`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 04:19:17 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
p-e-w/heretic#259
No description provided.