generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from InterwebAlchemy/feature/prep-for-release
Prep for Obsidian Community Plugin Release
- Loading branch information
Showing
11 changed files
with
76 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
extends: ['@commitlint/config-conventional'], | ||
rules: { 'body-max-line-length': [0] }, | ||
rules: { 'body-max-line-length': [0] } | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
import GPT3Tokenizer from 'gpt3-tokenizer' | ||
import { encode } from 'gpt-tokenizer' | ||
|
||
import { encode as oldEncoder } from 'gpt-tokenizer/esm/model/text-davinci-003' | ||
|
||
import { DEFAULT_TOKEN_TYPE } from '../constants' | ||
|
||
export type TokenCounterType = 'gpt3' | 'codex' | ||
export type TokenCounterType = 'gpt3' | 'gpt4' | ||
|
||
export interface TokenCounterOptions { | ||
// TODO: figure out what may need to be done to support other adapters and models | ||
type?: TokenCounterType | ||
debug?: boolean | ||
prefix?: string | ||
} | ||
|
||
const tokenCounter = (text: string, options: TokenCounterOptions = {}): number => { | ||
const { type = DEFAULT_TOKEN_TYPE, debug = false } = options | ||
|
||
const tokenizer = new GPT3Tokenizer({ type }) | ||
|
||
const tokens = tokenizer.encode(text) | ||
const tokenCounter = ( | ||
text: string, | ||
options: TokenCounterOptions = {} | ||
): number => { | ||
const { type = DEFAULT_TOKEN_TYPE } = options | ||
|
||
if (debug) { | ||
console.debug('TOKENS:', tokens) | ||
} | ||
const tokens = type === 'gpt3' ? oldEncoder(text) : encode(text) | ||
|
||
return tokens.text.length | ||
return tokens.length | ||
} | ||
|
||
export default tokenCounter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.