Skip to content

Commit

Permalink
fix: importing/requiring under certain setups was not working
Browse files Browse the repository at this point in the history
fixes #4
  • Loading branch information
niieani committed May 1, 2023
1 parent 7b9e7fd commit 8b71131
Show file tree
Hide file tree
Showing 13 changed files with 464 additions and 423 deletions.
10 changes: 10 additions & 0 deletions .config/beemo/typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { TypeScriptConfig } from '@beemo/driver-typescript'

const config: TypeScriptConfig = {
compilerOptions: {
allowJs: true,
},
include: ['src'],
}

export default config
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ node_modules/

.DS_Store
*.local

tsconfig.json
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
"./esm/*": {
"import": "./esm/*.js"
},
"./data/*": {
"import": "./data/*",
"require": "./data/*"
},
"./package.json": "./package.json"
},
"main": "esm/main.js",
Expand All @@ -73,7 +77,7 @@
"scripts": {
"build": "yarn build:cjs && yarn build:esm && yarn build:umd",
"build:cjs": "yarn rrun tsc --outDir cjs --module commonjs --target es2022",
"build:esm": "yarn rrun tsc --outDir esm --module esnext --target es2022",
"build:esm": "yarn rrun tsc --outDir esm --module esnext --target es2022 && echo '{\"name\": \"gpt-tokenizer\", \"type\": \"module\"}' > ./esm/package.json",
"build:umd": "beemo webpack --entry='./src/main.ts' --env 'outDir=dist' --env 'moduleTarget=umd' --env 'engineTarget=web' --env 'codeTarget=es2022' --env 'name=GPT3Encoder' --env 'export=default' --env 'filename=gpt3encoder.js'",
"clean": "git clean -dfX --exclude=node_modules src && beemo typescript:sync-project-refs",
"format": "yarn rrun prettier --write \"./{src,tests,.config}/**/!(*.d).{.js,jsx,ts,tsx,json,md}\"",
Expand Down Expand Up @@ -108,7 +112,7 @@
},
"devDependencies": {
"@niieani/scaffold": "^1.6.7",
"tsx": "^3.12.6"
"tsx": "^3.12.7"
},
"packageManager": "[email protected]",
"publishConfig": {
Expand Down
4 changes: 4 additions & 0 deletions src/data/bpeRanks.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/data/encoder.js

Large diffs are not rendered by default.

252 changes: 0 additions & 252 deletions src/encoder.ts

This file was deleted.

15 changes: 13 additions & 2 deletions src/getBpe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ const bpeMerges = lines.slice(1, -1).map((x) =>
)

const bpeRanks = dictZip(bpeMerges, range(0, bpeMerges.length))
const encoder = require('../data/encoder.json')

fs.mkdirSync(path.join(__dirname, 'data'), { recursive: true })
fs.writeFileSync(
path.join(__dirname, '../data/bpeRanks.json'),
JSON.stringify(bpeRanks),
path.join(__dirname, 'data/bpeRanks.js'),
`/* eslint-disable */\n// @ts-nocheck\n// prettier-ignore\nexport default ${JSON.stringify(
bpeRanks,
)}`,
)
fs.writeFileSync(
path.join(__dirname, 'data/encoder.js'),
`/* eslint-disable */\n// @ts-nocheck\n// prettier-ignore\nexport default ${JSON.stringify(
encoder,
)}`,
)

2 changes: 1 addition & 1 deletion src/encoder.test.ts → src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
decodeGenerator,
encode,
isWithinTokenLimit,
} from './encoder'
} from './main'

describe('basic functionality', () => {
it('empty string', () => {
Expand Down
Loading

0 comments on commit 8b71131

Please sign in to comment.