This is exposed via on_new_logits callback in the Python API to be consistent with the on_new_... scheme.
Note that currently only the number of tokens so far and the raw logits are exposed. So to be truly compatible with whisper.cpp the other arguments would need to be exposed to Python as well but it is better than nothing.
The logits are mutable so that the callback can indeed influence the decoding process. By using the array_t type this also safes us a copy.
I've added a test but I was not able to run the tests locally:
% ./tools/bazel test tests/... (git)-[feature/logits-callback]
INFO: Running bazel wrapper (see //tools/bazel for details), bazel version 6.0.0 will be used instead of system-wide bazel installation.
ERROR: .../pywhispercpp/tests/BUILD:26:8: no such package '@pypi_pytest_io//': The repository '@pypi_pytest_asyncio' could not be resolved: Repository '@pypi_pytest_asyncio' is not defined and referenced by '//tests:utils'
ERROR: Analysis of target '//tests:utils' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.107s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
ERROR: Couldn't start the build. Unable to run tests
This is exposed via
on_new_logits
callback in the Python API to be consistent with theon_new_...
scheme.Note that currently only the number of tokens so far and the raw logits are exposed. So to be truly compatible with whisper.cpp the other arguments would need to be exposed to Python as well but it is better than nothing.
The logits are mutable so that the callback can indeed influence the decoding process. By using the
array_t
type this also safes us a copy.I've added a test but I was not able to run the tests locally: