Skip to content

Commit 582292a

Browse files
committed
fix unicode issue for embeddings
1 parent 831c1f6 commit 582292a

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/tools/embeddings.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ async function getBatchEmbeddingsWithRetry(
8484
let retryCount = 0;
8585
let textsToProcess = [...batchTexts].map(item => {
8686
if (typeof item === 'string') {
87-
return trimLeadingSymbols(item);
87+
return trimSymbols(item);
8888
} else {
8989
const key = Object.keys(item)[0];
90-
return key === 'text' ? { text: trimLeadingSymbols(item[key]) } : item;
90+
return key === 'text' ? { text: trimSymbols(item[key]) } : item;
9191
}
9292
}); // Copy the original texts
9393
let indexMap = new Map<number, number>(); // Map to keep track of original indices
@@ -251,7 +251,7 @@ function truncateInputString(input: string | Record<string, string>): string {
251251
}
252252
}
253253

254-
function trimLeadingSymbols(str: string): string {
255-
const regex = /^[\p{S}\p{P}\p{Z}\p{C}\p{Emoji}]+/u;
256-
return str.replace(regex, '');
254+
function trimSymbols(str: string): string {
255+
const regex = /[\p{S}\p{P}\p{Z}\p{C}\p{Emoji}]+/gu;
256+
return str.replace(regex, ' ');
257257
}

0 commit comments

Comments
 (0)