Skip to content

Commit 0a6ce7b

Browse files
chore: developing the package
1 parent 8eeab85 commit 0a6ce7b

8 files changed

Lines changed: 92 additions & 106 deletions

File tree

embedder/index.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,30 @@ const [model, modelData, tokenizerModel] = await Promise.all([
1616
readFile(tokenizerModelPath),
1717
])
1818

19+
const modelBase64Url = JSON.stringify(
20+
toBase64UrlString(await toCompressed(model))
21+
)
22+
const modelDataBase64Url = JSON.stringify(
23+
toBase64UrlString(await toCompressed(modelData))
24+
)
25+
const tokenizerModelBase64 = JSON.stringify(tokenizerModel.toString('base64'))
26+
1927
const ts = js`
2028
import * as ort from 'onnxruntime-web'
21-
import { SentencePieceProcessor } from '@agnai/sentencepiece-js'
29+
import { SentencePieceProcessor } from '@sctg/sentencepiece-js'
2230
import { fromCompressed, fromBase64UrlString } from '@z-base/bytecodec'
2331
2432
export async function createInferenceSession(): Promise<ort.InferenceSession> {
2533
return ort.InferenceSession.create(
2634
await fromCompressed(
27-
fromBase64UrlString(${JSON.stringify(toBase64UrlString(await toCompressed(model)))})
35+
fromBase64UrlString(${modelBase64Url})
2836
),
2937
{
3038
externalData: [
3139
{
3240
path: 'model.int4.onnx.data',
3341
data: await fromCompressed(
34-
fromBase64UrlString(${JSON.stringify(toBase64UrlString(await toCompressed(modelData)))})
42+
fromBase64UrlString(${modelDataBase64Url})
3543
),
3644
},
3745
],
@@ -41,18 +49,7 @@ export async function createInferenceSession(): Promise<ort.InferenceSession> {
4149
4250
export async function createTokenProcessor(): Promise<SentencePieceProcessor> {
4351
const tokenProcessor = new SentencePieceProcessor()
44-
45-
const tokenizerModelBytes = await fromCompressed(
46-
fromBase64UrlString(${JSON.stringify(toBase64UrlString(await toCompressed(tokenizerModel)))})
47-
)
48-
49-
const tokenizerModelBlobBytes = Uint8Array.from(tokenizerModelBytes)
50-
51-
const tokenizerModelUrl = URL.createObjectURL(
52-
new Blob([tokenizerModelBlobBytes], { type: 'application/octet-stream' })
53-
)
54-
55-
await tokenProcessor.load(tokenizerModelUrl)
52+
await tokenProcessor.loadFromB64StringModel(${tokenizerModelBase64})
5653
return tokenProcessor
5754
}
5855
`.trimStart()

package-lock.json

Lines changed: 75 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"typescript": "^5.6.3"
7777
},
7878
"dependencies": {
79-
"@agnai/sentencepiece-js": "^1.1.1",
79+
"@sctg/sentencepiece-js": "^1.3.3",
8080
"@z-base/bytecodec": "^1.1.0",
8181
"@z-base/cryptosuite": "^1.0.1",
8282
"@z-base/zero-knowledge-credentials": "^1.0.2",

src/.types/index.d.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/.types/index.ts

Whitespace-only changes.

src/models/index.ts

Lines changed: 2 additions & 13 deletions
Large diffs are not rendered by default.

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ort from 'onnxruntime-web'
2-
import { cleanText } from '@agnai/sentencepiece-js'
2+
import { cleanText } from '@sctg/sentencepiece-js'
33
import { createInferenceSession, createTokenProcessor } from '../dist/index.js'
44

55
const MAX_INPUT_LENGTH = 256

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"skipLibCheck": true,
1313
"lib": ["es2024", "dom", "dom.iterable", "webworker"]
1414
},
15-
"include": ["src", "src/.types/index.d.ts"]
15+
"include": ["src"]
1616
}

0 commit comments

Comments
 (0)