Skip to content

Commit

Permalink
update to sentencepiece-js 1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Oct 7, 2024
1 parent a0a3cc0 commit 28a749b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
31 changes: 16 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"@fluentui/react-components": "^9.54.17",
"@fluentui/react-icons": "^2.0.260",
"@sctg/ai-sdk": "0.0.3",
"@sctg/sentencepiece-js": "^1.3.1",
"buffer": "^6.0.3",
"@sctg/sentencepiece-js": "^1.3.3",
"core-js": "^3.38.1",
"es6-promise": "^4.2.8",
"react": "^18.3.1",
Expand Down
14 changes: 7 additions & 7 deletions src/aipane/aipane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
import { Groq } from "@sctg/ai-sdk";
import config from "../config.json";
import type { AIModel, AIPrompt, AIProvider } from "./AIPrompt";
import { SentencePieceProcessor, cleanText, llama_3_1_tokeniser_b64 } from "@sctg/sentencepiece-js";
import { Buffer } from "buffer";

// eslint-disable-next-line no-undef
globalThis.Buffer = Buffer;

const TOKEN_MARGIN = 20;
import { SentencePieceProcessor, cleanText, llama_3_1_tokeniser_b64 } from "@sctg/sentencepiece-js";
const TOKEN_MARGIN = 20; // Safety margin for token count
async function countTokens(text: string): Promise<number> {
// Remove invalid characters and normalise whitespace
let cleaned = cleanText(text);
// Create a new SentencePieceProcessor
let spp = new SentencePieceProcessor();
// Load the tokeniser model from a base64 string
await spp.loadFromB64StringModel(llama_3_1_tokeniser_b64);
// Encode the cleaned text into token IDs
let ids = spp.encodeIds(cleaned);
return ids.length;
return ids.length; // Return the number of tokens
}

async function groqRequest(
Expand Down

0 comments on commit 28a749b

Please sign in to comment.