/
githubmirror
/
english-compiler
Обзор
Документация
Войти
/
githubmirror
/
english-compiler
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/openai/getTokenCount.js
14 строк
392 B
Eugene Cheah
Basic openAI integration, with prompt to completion + caching
17 фев 2023, 06:45
17 фев 2023, 06:45
4cb5497
Код
Авторство
О чём код?
// Initialize the tokenizer const GPT3Tokenizer = require('gpt3-tokenizer').default; const tokenizer = new GPT3Tokenizer({ type: 'gpt3' }); /** * Given the input data, encode and get the token count * @param {String} data * * @return token length as int */ module.exports = function getTokenCount( data ) { let tokenObj = tokenizer.encode( data ); return tokenObj.bpe.length; }