Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Update tokenizer.ts as per the codereviwer ai comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Infracloud-harsh committed Nov 30, 2023
1 parent 44a12fb commit 4cf4e4d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export function splitPrompt(
let remainingPrompt = prompt
while (remainingPrompt.length > 0) {
if (remainingPrompt.length > maxTokens && !remainingPrompt.includes(' ')) {
throw new Error(`Word length exceeds maxTokens: ${maxTokens}`);
const piece = remainingPrompt.substring(0, maxTokens).trim();
promptPieces.push(piece);
remainingPrompt = remainingPrompt.substring(maxTokens).trim();
}
const lastSpaceIndex = remainingPrompt.lastIndexOf(' ', maxTokens)
if (lastSpaceIndex >= 0) {
Expand Down

0 comments on commit 4cf4e4d

Please sign in to comment.