Allow the injection of TokenCountEstimator #705
Merged
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.
This PR resolves #697.
The idea is to allow the injection of the
TokenCountEstimator
interface, which can be used in different ways, for example to know in advance the cost of processing a certain text, or to choose one model or another based on the maximum number of tokens.Today, when I look at the code to see which LLM providers implement this interface, I see
For the azure-openai I found something strange, the
tokenizer
variable is never set, so when creating tests I always get aNullPointerException
(There are some TODOs in the code to understand what the points are).As far as I understand, the correct way to create the tokenizer for
azure-openai
is to use something like:but I'm not able to test this, so what I've done is just put some TODOs in the code.
Is there anyone who can look into this? Does it make sense to have a
TokenCountEstimator
for azure-openai or should I just ignore it for now?