Add performance test and minor code refactor #50
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.
First of all, I would like to thank the author for this project❤️ , which really makes my life a lot easier. And I also learnt a lot from the coding style and structure
Here are the changes I made:
Performance Test
tests/perf.js
, which can be run withnpm run test:perf
tiktoken
WASM binding into this project in the future. And before that, I would like to setup more fine-grained performance tests, so that we can test the performance difference betweenjs-tiktoken
andtiktoken
testPerformance(messages)
intest.js
, I set up tests intests/perf.js
that measures the execution time for each of the following operations separately:usageInfo.usedTokens
,usageInfo.promptUsedTokens
,usageInfo.completionUsedTokens
andusageInfo.usedUSD
.GPTTokens
instance is always instantiated and performusageInfo.usedTokens
to cache the encoding inmodelEncodingCache
before the timing starts. So the test results might look different from the originaltestPerformance(messages)
0.019ms
per calls (by 'calls' I mean ops like usageInfo.usedTokens, usageInfo.promptUsedTokens, etc ) on my system (Ubuntu 22.04.3, 5.15.146.1-microsoft-standard-WSL2, x86_64, Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz), with NodeJS v21.2.0Minor refactor
I've moved
modelEncodingCache
andgetEncodingForModelCached
inside GPTTokens and make themprotected static
, so that they are only accessible from with the class and its sub-classes. This also makes our API more encapsulated.NPM registry error
I got the following auth error when running
npm i
with the latestpackage-lock.json
It seems that this npm resigtry requires some sort of authentication, and so I replaced them with the official registry https://registry.npmjs.org
Regression test
Add
process.env.FINE_TUNE_MODEL
->const model = process.env.FINE_TUNE_MODEL || 'ft:gpt-3.5-turbo-1106:opensftp::8IWeqPit'
, so that developers could use their own model for testing (the original fine-tuned model listed there is somehow not accessible to me)The test result (for my latest commit) looks good to me. The
DeprecationWarning
is caused by NodeJS v21, switching to v20 will solve the problem.I suggest setting up a CI/CD pipeline for automated testing to make development and contribution easier