aarnphm / whispercpp

Pybind11 bindings for Whisper.cpp
Apache License 2.0
317 stars 54 forks source link

Implement `logits_filter_callback` #193

Open githubnemo opened 7 months ago

githubnemo commented 7 months ago

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