Ensure custom Classification Providers can fully work #762
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
We recently went through a refactor of ClassifAI to make it easier to add additional Providers and Features. As part of this process, we more fully merged the two Classification approaches we have: classifying by suggesting new terms and classifying based on existing terms.
I recently was trying to add a new 3rd party Classification Provider and ran into a few issues that prevented this from fully working. We have a few places within ClassifAI that are hardcoded based on the two built-in Classification Providers. This means if you add a custom Provider, this code doesn't ever run. The two areas were:
This PR attempts to fix both of these problems. A new filter is introduced (
classifai_feature_classification_pre_save_results
), that allows you to modify the classification results before they're saved. This can be used by a custom Provider to process and save these results however is needed (can also be used to modify the results before a built-in Provider saves them, if desired).For the previewer, I debated on a few approaches but ended up going pretty simple. If the Provider is IBM Watson, we load some custom code. If the Provider isn't IBM Watson, we load our other code. Previously we were loading this code if the Provider was OpenAI Embeddings. This means for a custom Provider, this second code block will be loaded. As long as the custom Provider follows the approach of our OpenAI Embeddings Provider, this should work fine.
How to test the Change
Not a whole lot to test here but can test that the preview functionality still works for the two built-in Providers.
Changelog Entry
Credits
Props @dkotter
Checklist: