mood-bench 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. mood_bench-0.0.1/.github/workflows/publish.yml +121 -0
  2. mood_bench-0.0.1/.github/workflows/version-check.yml +89 -0
  3. mood_bench-0.0.1/.gitignore +216 -0
  4. mood_bench-0.0.1/PKG-INFO +293 -0
  5. mood_bench-0.0.1/README.md +266 -0
  6. mood_bench-0.0.1/examples/analysis.py +151 -0
  7. mood_bench-0.0.1/examples/guard.py +53 -0
  8. mood_bench-0.0.1/examples/guard_ensemble.py +82 -0
  9. mood_bench-0.0.1/examples/mixture_guard_perplexity.py +99 -0
  10. mood_bench-0.0.1/mood_bench/__init__.py +98 -0
  11. mood_bench-0.0.1/mood_bench/_output.py +93 -0
  12. mood_bench-0.0.1/mood_bench/_prompts.py +27 -0
  13. mood_bench-0.0.1/mood_bench/aggregator.py +173 -0
  14. mood_bench-0.0.1/mood_bench/cli/__init__.py +57 -0
  15. mood_bench-0.0.1/mood_bench/cli/_common.py +103 -0
  16. mood_bench-0.0.1/mood_bench/cli/analyze.py +186 -0
  17. mood_bench-0.0.1/mood_bench/cli/guard.py +102 -0
  18. mood_bench-0.0.1/mood_bench/cli/instruction_tuned.py +105 -0
  19. mood_bench-0.0.1/mood_bench/cli/mahalanobis.py +184 -0
  20. mood_bench-0.0.1/mood_bench/cli/perplexity.py +73 -0
  21. mood_bench-0.0.1/mood_bench/core.py +246 -0
  22. mood_bench-0.0.1/mood_bench/data.py +75 -0
  23. mood_bench-0.0.1/mood_bench/metrics.py +73 -0
  24. mood_bench-0.0.1/mood_bench/pipeline/__init__.py +14 -0
  25. mood_bench-0.0.1/mood_bench/pipeline/base.py +23 -0
  26. mood_bench-0.0.1/mood_bench/pipeline/guard.py +50 -0
  27. mood_bench-0.0.1/mood_bench/pipeline/instruction_tuned.py +316 -0
  28. mood_bench-0.0.1/mood_bench/pipeline/mahalanobis.py +155 -0
  29. mood_bench-0.0.1/mood_bench/pipeline/perplexity.py +126 -0
  30. mood_bench-0.0.1/mood_bench/prompts/constitution.txt +40 -0
  31. mood_bench-0.0.1/mood_bench/prompts/default_chat_template.jinja +1 -0
  32. mood_bench-0.0.1/mood_bench/prompts/instruction_grading_icl.jinja +20 -0
  33. mood_bench-0.0.1/mood_bench/prompts/instruction_grading_no_icl.jinja +14 -0
  34. mood_bench-0.0.1/mood_bench/prompts/scoring_rubric_alignment.jinja +5 -0
  35. mood_bench-0.0.1/mood_bench/prompts/scoring_rubric_uncertainty.jinja +5 -0
  36. mood_bench-0.0.1/mood_bench/py.typed +0 -0
  37. mood_bench-0.0.1/mood_bench/tokenize.py +80 -0
  38. mood_bench-0.0.1/pyproject.toml +61 -0
  39. mood_bench-0.0.1/tests/conftest.py +216 -0
  40. mood_bench-0.0.1/tests/e2e/test_guard.py +61 -0
  41. mood_bench-0.0.1/tests/e2e/test_instruction_tuned.py +138 -0
  42. mood_bench-0.0.1/tests/e2e/test_mahalanobis.py +75 -0
  43. mood_bench-0.0.1/tests/e2e/test_perplexity.py +55 -0
  44. mood_bench-0.0.1/tests/run_tests.sh +24 -0
  45. mood_bench-0.0.1/tests/test_analysis.py +215 -0
  46. mood_bench-0.0.1/tests/test_cli.py +756 -0
  47. mood_bench-0.0.1/uv.lock +2653 -0
@@ -0,0 +1,121 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ verify-version-bump:
13
+ name: Verify version was bumped
14
+ runs-on: ubuntu-latest
15
+ outputs:
16
+ version: ${{ steps.check.outputs.version }}
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ with:
20
+ # Need at least HEAD and HEAD~1 to compare versions.
21
+ fetch-depth: 2
22
+
23
+ - uses: actions/setup-python@v5
24
+ with:
25
+ python-version: "3.12"
26
+
27
+ - name: Install version-check dependencies
28
+ run: python -m pip install --upgrade packaging
29
+
30
+ - name: Verify pyproject.toml version was bumped vs previous commit
31
+ id: check
32
+ shell: bash
33
+ run: |
34
+ python <<'PY'
35
+ import os
36
+ import subprocess
37
+ import sys
38
+ import tomllib
39
+ from packaging.version import InvalidVersion, Version
40
+
41
+ def read_version(blob: bytes) -> str | None:
42
+ data = tomllib.loads(blob.decode())
43
+ return data.get("project", {}).get("version")
44
+
45
+ with open("pyproject.toml", "rb") as f:
46
+ new_version_str = read_version(f.read())
47
+ if not new_version_str:
48
+ sys.exit("pyproject.toml is missing [project].version")
49
+
50
+ try:
51
+ new_version = Version(new_version_str)
52
+ except InvalidVersion as e:
53
+ sys.exit(f"Invalid new version {new_version_str!r}: {e}")
54
+
55
+ try:
56
+ prev_blob = subprocess.check_output(
57
+ ["git", "show", "HEAD~1:pyproject.toml"],
58
+ stderr=subprocess.DEVNULL,
59
+ )
60
+ except subprocess.CalledProcessError:
61
+ print(f"No previous pyproject.toml found; treating {new_version} as first publish.")
62
+ prev_version = None
63
+ else:
64
+ prev_version_str = read_version(prev_blob)
65
+ if not prev_version_str:
66
+ print("Previous pyproject.toml had no version; allowing publish.")
67
+ prev_version = None
68
+ else:
69
+ try:
70
+ prev_version = Version(prev_version_str)
71
+ except InvalidVersion as e:
72
+ sys.exit(f"Invalid previous version {prev_version_str!r}: {e}")
73
+
74
+ if prev_version is not None and new_version <= prev_version:
75
+ sys.exit(
76
+ f"::error::Version was not bumped: {prev_version} -> {new_version}. "
77
+ "Update pyproject.toml [project].version before pushing to main."
78
+ )
79
+
80
+ print(f"Version check OK: {prev_version} -> {new_version}")
81
+ with open(os.environ["GITHUB_OUTPUT"], "a") as out:
82
+ out.write(f"version={new_version}\n")
83
+ PY
84
+
85
+ build-and-publish:
86
+ name: Build and publish to PyPI
87
+ needs: verify-version-bump
88
+ runs-on: ubuntu-latest
89
+
90
+ # Required for PyPI trusted publishing (OIDC).
91
+ permissions:
92
+ id-token: write
93
+ contents: read
94
+
95
+ # Tie publishes to a GitHub "pypi" environment so you can add
96
+ # required reviewers / protection rules later.
97
+ environment:
98
+ name: pypi
99
+ url: https://pypi.org/project/mood-bench/${{ needs.verify-version-bump.outputs.version }}/
100
+
101
+ steps:
102
+ - uses: actions/checkout@v4
103
+
104
+ - uses: actions/setup-python@v5
105
+ with:
106
+ python-version: "3.12"
107
+
108
+ - name: Install build tooling
109
+ run: python -m pip install --upgrade build
110
+
111
+ - name: Build sdist and wheel
112
+ run: python -m build
113
+
114
+ - name: Inspect built artifacts
115
+ run: ls -la dist/
116
+
117
+ - name: Publish to PyPI
118
+ uses: pypa/gh-action-pypi-publish@release/v1
119
+ # No `with:` block needed when using trusted publishing.
120
+ # PyPI rejects re-uploads of the same version, so this also
121
+ # acts as a second line of defense against accidental republish.
@@ -0,0 +1,89 @@
1
+ name: Version bump check
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [main]
6
+ paths:
7
+ # Re-run only when something that could affect a publish changes.
8
+ # Keep this broad so the check is a hard gate, not opt-in.
9
+ - "**"
10
+ - "!**/*.md"
11
+ - "!.github/**"
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ verify-version-bump:
18
+ name: Verify pyproject.toml version is bumped
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ with:
23
+ # Need both PR head and the base branch to compare.
24
+ fetch-depth: 0
25
+
26
+ - uses: actions/setup-python@v5
27
+ with:
28
+ python-version: "3.12"
29
+
30
+ - name: Install dependencies
31
+ run: python -m pip install --upgrade packaging
32
+
33
+ - name: Compare versions
34
+ shell: bash
35
+ env:
36
+ BASE_REF: ${{ github.event.pull_request.base.ref }}
37
+ BASE_SHA: ${{ github.event.pull_request.base.sha }}
38
+ run: |
39
+ python <<'PY'
40
+ import os
41
+ import subprocess
42
+ import sys
43
+ import tomllib
44
+ from packaging.version import InvalidVersion, Version
45
+
46
+ base_sha = os.environ["BASE_SHA"]
47
+ base_ref = os.environ["BASE_REF"]
48
+
49
+ def read_version(blob: bytes) -> str | None:
50
+ return tomllib.loads(blob.decode()).get("project", {}).get("version")
51
+
52
+ with open("pyproject.toml", "rb") as f:
53
+ new_version_str = read_version(f.read())
54
+ if not new_version_str:
55
+ sys.exit("pyproject.toml is missing [project].version")
56
+ try:
57
+ new_version = Version(new_version_str)
58
+ except InvalidVersion as e:
59
+ sys.exit(f"Invalid PR-head version {new_version_str!r}: {e}")
60
+
61
+ try:
62
+ base_blob = subprocess.check_output(
63
+ ["git", "show", f"{base_sha}:pyproject.toml"],
64
+ stderr=subprocess.DEVNULL,
65
+ )
66
+ except subprocess.CalledProcessError:
67
+ print(
68
+ f"No pyproject.toml on base {base_ref}@{base_sha[:8]}; "
69
+ f"treating {new_version} as first publish."
70
+ )
71
+ sys.exit(0)
72
+
73
+ base_version_str = read_version(base_blob)
74
+ if not base_version_str:
75
+ print("Base branch has no [project].version; allowing.")
76
+ sys.exit(0)
77
+ try:
78
+ base_version = Version(base_version_str)
79
+ except InvalidVersion as e:
80
+ sys.exit(f"Invalid base version {base_version_str!r}: {e}")
81
+
82
+ if new_version <= base_version:
83
+ sys.exit(
84
+ f"::error file=pyproject.toml::Version was not bumped: "
85
+ f"{base_version} (on {base_ref}) -> {new_version} (PR head). "
86
+ "Bump pyproject.toml [project].version before merging."
87
+ )
88
+ print(f"Version bump OK: {base_version} -> {new_version}")
89
+ PY
@@ -0,0 +1,216 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+
209
+ mood-bench-results*/
210
+ tests/results/
211
+ function-calling-missing-results/
212
+ mahalanobis-stats-cache/
213
+ models/
214
+ old-models/
215
+ scripts/
216
+ old/