Cap speaker ID transcript length to 2000 tokens
All checks were successful
Publish Library / Build NPM Project (push) Successful in 34s
Publish Library / Tag Version (push) Successful in 6s

This commit is contained in:
2026-02-14 09:48:12 -05:00
parent 4143d00de7
commit 7ef7c3f676
2 changed files with 5 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ztimson/ai-utils", "name": "@ztimson/ai-utils",
"version": "0.7.0", "version": "0.7.1",
"description": "AI Utility library", "description": "AI Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@@ -40,9 +40,11 @@ export class Audio {
if(!this.ai.language.defaultModel) throw new Error('Configure an LLM for advanced ASR speaker detection'); if(!this.ai.language.defaultModel) throw new Error('Configure an LLM for advanced ASR speaker detection');
p = p.then(async transcript => { p = p.then(async transcript => {
if(!transcript) return transcript; if(!transcript) return transcript;
const names = await this.ai.language.json(transcript, '{1: "Detected Name"}', { let chunks = this.ai.language.chunk(transcript, 500, 0);
if(chunks.length > 4) chunks = [...chunks.slice(0, 3), <string>chunks.at(-1)];
const names = await this.ai.language.json(chunks.join('\n'), '{1: "Detected Name"}', {
system: 'Use this following transcript to identify speakers. Only identify speakers you are sure about', system: 'Use this following transcript to identify speakers. Only identify speakers you are sure about',
temperature: 0.2, temperature: 0.1,
}); });
Object.entries(names).forEach(([speaker, name]) => { Object.entries(names).forEach(([speaker, name]) => {
transcript = (<string>transcript).replaceAll(`[Speaker ${speaker}]`, `[${name}]`); transcript = (<string>transcript).replaceAll(`[Speaker ${speaker}]`, `[${name}]`);