ai-compare-candidates 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -10,5 +10,5 @@ Candidates:
10
10
  `+t.join(`
11
11
 
12
12
  `)}regexIndexOf(e,t,n){let r=e.slice(n).search(t);return r<0?r:r+n}defaultExtractIdentifierFromCandidateDocument({candidateDocument:e,candidateIdentifierField:t}={}){this.DEBUG&&console.log(e,t);let n=d.default.startCase(t),r=e.indexOf(n);if(r<0&&(r=e.toLowerCase().indexOf(n.toLowerCase())),this.DEBUG&&console.log(r),r>=0&&(r+=n.length),r<0&&(r=e.toLowerCase().indexOf(t.toLowerCase()),r>=0&&(r+=t.length)),this.DEBUG)console.log(r);else return``;if(r=e.indexOf(`:`,r),this.DEBUG&&console.log(r),r<0&&(r=this.regexIndexOf(e,/\s+/,r)),this.DEBUG&&console.log(r),r<0)return``;let i=e.indexOf(`
13
- `,r);return i<0&&(i=e.length),this.DEBUG&&console.log(i),e.substring(r,i).trim()}defaultExtractIdentifiersFromRationale(e){let t=/^\d+?\s*?\p{P}\s*?(.+?)\s*?(-|\.|;|\n)/gmu,n=[];for(let r;Array.isArray(r=t.exec(e));)r[1]&&n.push(r[1]);return n}defaultFindCandidateFromIdentifier({identifier:e,candidateIdentifierField:t,candidates:n}={}){(!e||typeof e!=`string`)&&(e=String(e)),console.log(`identifier`,e);let r=n.find(n=>String(n[t])===e);if(r||(r=n.find(n=>String(n[t]).toLowerCase()===e.toLowerCase()),r)||(r=n.find(n=>String(n[t]).toLowerCase().includes(e.toLowerCase())),r)||(r=n.find(n=>e.toLowerCase().includes(String(n[t]).toLowerCase())),r))return this.DEBUG&&console.log(`Candidate found based on case-sensitive match`,r[t]),r;let i=e.split(/\s+/g).filter(e=>/\w/.test(e));this.DEBUG&&console.log(`Identifier words`,i);let a=n.map(e=>({identifierWordIndices:i.map(n=>String(e[t]).indexOf(n)),candidate:e})).filter(e=>e.identifierWordIndices.some(e=>e>=0));return a.length>1&&a.sort((e,t)=>{let n=d.default.sumBy(e.identifierWordIndices,e=>e<0?0:1),r=d.default.sumBy(t.identifierWordIndices,e=>e<0?0:1);if(this.DEBUG&&(console.log(`a`,e),console.log(`b`,t),console.log(`a.identifierWordIndices`,e.identifierWordIndices),console.log(`b.identifierWordIndices`,t.identifierWordIndices),console.log(`aCount`,n),console.log(`bCount`,r)),n!==r)return r-n;if(n===0&&r===0)return 0;n=0,r=0;for(let t=0;t<e.identifierWordIndices.length-1;++t)for(let r=t+1;r<e.identifierWordIndices.length;++r)e.identifierWordIndices[t]<0||e.identifierWordIndices[r]<0||e.identifierWordIndices[t]<e.identifierWordIndices[r]&&(this.DEBUG&&(console.log(`i`,t),console.log(`j`,r),console.log(`a.identifierWordIndices[i]`,e.identifierWordIndices[t]),console.log(`a.identifierWordIndices[j]`,e.identifierWordIndices[r])),++n);for(let e=0;e<t.identifierWordIndices.length-1;++e)for(let n=e+1;n<t.identifierWordIndices.length;++n)t.identifierWordIndices[e]<0||t.identifierWordIndices[n]<0||t.identifierWordIndices[e]<t.identifierWordIndices[n]&&(this.DEBUG&&(console.log(`i`,e),console.log(`j`,n),console.log(`b.identifierWordIndices[i]`,t.identifierWordIndices[e]),console.log(`b.identifierWordIndices[j]`,t.identifierWordIndices[n])),++r);return this.DEBUG&&(console.log(`aCount`,n),console.log(`bCount`,r)),r-n}),a.length>=1&&a[0].candidate?a[0].candidate:null}defaultParseSearchAreasResponse(e){let t=String(e).indexOf(`### Response:`);return t>=0?t+=13:t=0,String(e).substring(t).trim()}errorMessage(e){return typeof e?.response?.data==`string`?e.response.data:e?.response?.data?f.default.stringify(e.response.data):typeof e?.message==`string`?e.message:e?.message?f.default.stringify(e.message):typeof e==`string`?e:f.default.stringify(e)}async compareCandidates({candidates:e,problemDescription:t=``,performGeneration:n=this.defaultPerformGeneration.bind(this),generateSearchAreasInstruction:r=this.defaultGenerateSearchAreasInstruction.bind(this),parseSearchAreasResponse:i=this.defaultParseSearchAreasResponse.bind(this),convertCandidateToDocument:a=this.defaultConvertCandidateToDocument.bind(this),candidatesForInitialSelection:o=2,candidatesForFinalSelection:s=1,generateRankingInstruction:c=this.defaultGenerateRankingInstruction.bind(this),extractIdentifiersFromRationale:u=this.defaultExtractIdentifiersFromRationale.bind(this),extractIdentifierFromCandidateDocument:f=this.defaultExtractIdentifierFromCandidateDocument.bind(this),candidateIdentifierField:p=void 0,findCandidateFromIdentifier:m=this.defaultFindCandidateFromIdentifier.bind(this),getSummarisableSubstringIndices:h,generatePromptTemplate:g=this.defaultGeneratePromptTemplate.bind(this),skipRationale:_=!1}={}){if(!Array.isArray(e)||e.length<=0)throw Error(`No candidates provided`);if(o=d.default.toSafeInteger(o),o<=0||(s=d.default.toSafeInteger(s),s<=0))throw Error(`Candidates for initial selection must be a positive integer bigger than 0`);if(o<s)throw Error(`Candidates for initial selection must be equal or more than candidates for final selection`);if(o>e.length)throw Error(`There are `+o+`candidates for initial selection which is more than the total number of candidates of `+e.length);if(s>e.length)throw Error(`There are `+s+`candidates for initial selection which is more than the total number of candidates of `+e.length);if(!p&&(p=Object.keys(e[0])[0],!p))throw Error(`No candidate identifier field`);let v=``,y=[];if(await this.checkEmbedderLoaded(),!this.embedder)return;let b=e.map((e,t)=>a({candidate:e,index:t})),x=await l.MemoryVectorStore.fromTexts(d.default.cloneDeep(b),b.map((e,t)=>t),this),S=g(r(t));if(this.DEBUG&&console.log(`Formatted search areas prompt: `+S),await this.checkTokeniserLoaded(),!this.tokeniser)return;if(this.tokeniser.encode(S).length>this.tokeniser.model_max_length)throw Error(`Search areas instruction prompt is too long for the tokeniser model`);if(await this.checkGeneratorLoaded(),!this.generator)return;let C=await n({generator:this.generator,tokeniser:this.tokeniser,prompt:S,textGenerationConfig:{max_new_tokens:this.generateSearchAreasMaxNewTokens,temperature:this.generateSearchAreasTemperature,repetition_penalty:this.generateSearchAreasRepetitionPenalty}});this.DEBUG&&console.log(`Generated search areas response: `+C);let w=i(C);this.DEBUG&&console.log(`Vector search query: `+w);let T=await x.similaritySearch(w,o);this.DEBUG&&console.log(`Vector search results: `,T);let E=[];if(T.some(e=>e.pageContent.trim().split(/\s+/).length>this.targetSummarisedStringTokenCount)){if(await this.checkSummariserLoaded(),!this.summariser)return;E=(await Promise.allSettled(T.map(async e=>{if(!e.pageContent||typeof e.pageContent!=`string`)return``;if(e.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount)return e.pageContent;let t={start:0,end:e.pageContent.length};h&&Object.assign(t,h(e.pageContent)),t.start=d.default.clamp(d.default.toSafeInteger(t.start),0,e.pageContent.length),t.end=d.default.clamp(d.default.toSafeInteger(t.end),0,e.pageContent.length),this.DEBUG&&console.log(t);let n=e.pageContent.substring(t.start,t.end);this.DEBUG&&console.log(n);let r=e.pageContent.substring(0,t.start),i=e.pageContent.substring(t.end),a=r.split(/\s+/).length+i.split(/\s+/).length,o=Math.max(1,this.targetSummarisedStringTokenCount-a);this.DEBUG&&console.log(a,o);let s=await this.summariser?.(n,{max_length:o}),c=Array.isArray(s?.[0])?s?.[0]?.[0]:s?.[0];this.DEBUG&&console.log(s,c,c?.summary_text??``,(c?.summary_text??``).split(/\s+/).slice(0,o).join(` `));let l=r+(c?.summary_text??``).split(/\s+/).slice(0,o).join(` `).trim()+i;return this.DEBUG&&console.log(`Summarised candidate: `+l),l}))).filter(e=>e.status===`fulfilled`&&e.value).map(e=>e.value)}else E=T.map(e=>e.pageContent);let D=``;if(!_){let e=g(c({problemDescription:t,summaries:E,candidatesForFinalSelection:s,candidateIdentifierField:String(p)}));this.DEBUG&&console.log(`Formatted ranking prompt: `+e);let r=this.tokeniser.encode(e);if(this.DEBUG&&console.log(r.length,this.tokeniser.model_max_length),r.length>this.tokeniser.model_max_length)throw Error(`Ranking instruction prompt is too long for the tokeniser model`);try{v=(await n({generator:this.generator,tokeniser:this.tokeniser,prompt:e,textGenerationConfig:{max_new_tokens:this.rankingMaxNewTokens,temperature:this.rankingTemperature,repetition_penalty:this.rankingRepetitionPenalty}})).trim().replace(/(\*\*)|(<\/?s>)|(\[.*?\])\s*/g,``),this.DEBUG&&console.log(`Generated rationale: `+v);let t=v.indexOf(`### Response:`);t>=0?t+=13:t=0,v=v.substring(t)}catch(e){console.log(e),D=this.errorMessage(e),v=``}}if(v){let t=u(v);this.DEBUG&&console.log(`Extracted identifiers from rationale: `+t),t.length>s&&(t=t.slice(0,s)),y=d.default.compact(t.map(t=>m({identifier:t,candidateIdentifierField:p,candidates:e})))}if(!Array.isArray(y)||y.length<s){Array.isArray(y)||(y=[]);let t=d.default.compact(T.map(t=>{let n=f({candidateDocument:t.pageContent,candidateIdentifierField:String(p)});return this.DEBUG&&console.log(`Extracted identifier from candidate document: `+n),m({identifier:n,candidateIdentifierField:p,candidates:e})}));y.splice(y.length,0,...t),y=d.default.uniq(y).slice(0,s)}return this.DEBUG&&console.log(`Selected candidates`,y),{rationale:v,summaries:E,...D?{rationaleError:D}:{},selectedCandidates:y}}};(function(e){})(p||={});var m=p;Object.defineProperty(exports,`AICompareCandidates`,{enumerable:!0,get:function(){return p}}),exports.default=m;
13
+ `,r);return i<0&&(i=e.length),this.DEBUG&&console.log(i),e.substring(r,i).trim()}defaultExtractIdentifiersFromRationale(e){let t=/^\d+?\s*?\p{P}\s*?(.+?)\s*?(-|\.|;|\n)/gmu,n=[];for(let r;Array.isArray(r=t.exec(e));)r[1]&&n.push(r[1]);return n}defaultFindCandidateFromIdentifier({identifier:e,candidateIdentifierField:t,candidates:n}={}){(!e||typeof e!=`string`)&&(e=String(e)),console.log(`identifier`,e);let r=n.find(n=>String(n[t])===e);if(r||(r=n.find(n=>String(n[t]).toLowerCase()===e.toLowerCase()),r)||(r=n.find(n=>String(n[t]).toLowerCase().includes(e.toLowerCase())),r)||(r=n.find(n=>e.toLowerCase().includes(String(n[t]).toLowerCase())),r))return this.DEBUG&&console.log(`Candidate found based on case-sensitive match`,r[t]),r;let i=e.split(/\s+/g).filter(e=>/\w/.test(e));this.DEBUG&&console.log(`Identifier words`,i);let a=n.map(e=>({identifierWordIndices:i.map(n=>String(e[t]).indexOf(n)),candidate:e})).filter(e=>e.identifierWordIndices.some(e=>e>=0));return a.length>1&&a.sort((e,t)=>{let n=d.default.sumBy(e.identifierWordIndices,e=>e<0?0:1),r=d.default.sumBy(t.identifierWordIndices,e=>e<0?0:1);if(this.DEBUG&&(console.log(`a`,e),console.log(`b`,t),console.log(`a.identifierWordIndices`,e.identifierWordIndices),console.log(`b.identifierWordIndices`,t.identifierWordIndices),console.log(`aCount`,n),console.log(`bCount`,r)),n!==r)return r-n;if(n===0&&r===0)return 0;n=0,r=0;for(let t=0;t<e.identifierWordIndices.length-1;++t)for(let r=t+1;r<e.identifierWordIndices.length;++r)e.identifierWordIndices[t]<0||e.identifierWordIndices[r]<0||e.identifierWordIndices[t]<e.identifierWordIndices[r]&&(this.DEBUG&&(console.log(`i`,t),console.log(`j`,r),console.log(`a.identifierWordIndices[i]`,e.identifierWordIndices[t]),console.log(`a.identifierWordIndices[j]`,e.identifierWordIndices[r])),++n);for(let e=0;e<t.identifierWordIndices.length-1;++e)for(let n=e+1;n<t.identifierWordIndices.length;++n)t.identifierWordIndices[e]<0||t.identifierWordIndices[n]<0||t.identifierWordIndices[e]<t.identifierWordIndices[n]&&(this.DEBUG&&(console.log(`i`,e),console.log(`j`,n),console.log(`b.identifierWordIndices[i]`,t.identifierWordIndices[e]),console.log(`b.identifierWordIndices[j]`,t.identifierWordIndices[n])),++r);return this.DEBUG&&(console.log(`aCount`,n),console.log(`bCount`,r)),r-n}),a.length>=1&&a[0].candidate?a[0].candidate:null}defaultParseSearchAreasResponse(e){let t=String(e).indexOf(`### Response:`);return t>=0?t+=13:t=0,String(e).substring(t).trim()}errorMessage(e){return typeof e?.response?.data==`string`?e.response.data:e?.response?.data?f.default.stringify(e.response.data):typeof e?.message==`string`?e.message:e?.message?f.default.stringify(e.message):typeof e==`string`?e:f.default.stringify(e)}async compareCandidates({candidates:e,problemDescription:t=``,performGeneration:n=this.defaultPerformGeneration.bind(this),generateSearchAreasInstruction:r=this.defaultGenerateSearchAreasInstruction.bind(this),parseSearchAreasResponse:i=this.defaultParseSearchAreasResponse.bind(this),convertCandidateToDocument:a=this.defaultConvertCandidateToDocument.bind(this),candidatesForInitialSelection:o=2,candidatesForFinalSelection:s=1,generateRankingInstruction:c=this.defaultGenerateRankingInstruction.bind(this),extractIdentifiersFromRationale:u=this.defaultExtractIdentifiersFromRationale.bind(this),extractIdentifierFromCandidateDocument:f=this.defaultExtractIdentifierFromCandidateDocument.bind(this),candidateIdentifierField:p=void 0,findCandidateFromIdentifier:m=this.defaultFindCandidateFromIdentifier.bind(this),getSummarisableSubstringIndices:h,generatePromptTemplate:g=this.defaultGeneratePromptTemplate.bind(this),skipRationale:_=!1,parallelSummarisation:v=!0}={}){if(!Array.isArray(e)||e.length<=0)throw Error(`No candidates provided`);if(o=d.default.toSafeInteger(o),o<=0||(s=d.default.toSafeInteger(s),s<=0))throw Error(`Candidates for initial selection must be a positive integer bigger than 0`);if(o<s)throw Error(`Candidates for initial selection must be equal or more than candidates for final selection`);if(o>e.length)throw Error(`There are `+o+`candidates for initial selection which is more than the total number of candidates of `+e.length);if(s>e.length)throw Error(`There are `+s+`candidates for initial selection which is more than the total number of candidates of `+e.length);if(!p&&(p=Object.keys(e[0])[0],!p))throw Error(`No candidate identifier field`);let y=``,b=[];if(await this.checkEmbedderLoaded(),!this.embedder)return;let x=e.map((e,t)=>a({candidate:e,index:t})),S=await l.MemoryVectorStore.fromTexts(d.default.cloneDeep(x),x.map((e,t)=>t),this),C=g(r(t));if(this.DEBUG&&console.log(`Formatted search areas prompt: `+C),await this.checkTokeniserLoaded(),!this.tokeniser)return;if(this.tokeniser.encode(C).length>this.tokeniser.model_max_length)throw Error(`Search areas instruction prompt is too long for the tokeniser model`);if(await this.checkGeneratorLoaded(),!this.generator)return;let w=await n({generator:this.generator,tokeniser:this.tokeniser,prompt:C,textGenerationConfig:{max_new_tokens:this.generateSearchAreasMaxNewTokens,temperature:this.generateSearchAreasTemperature,repetition_penalty:this.generateSearchAreasRepetitionPenalty}});this.DEBUG&&console.log(`Generated search areas response: `+w);let T=i(w);this.DEBUG&&console.log(`Vector search query: `+T);let E=await S.similaritySearch(T,o);this.DEBUG&&console.log(`Vector search results: `,E);let D=[];if(E.some(e=>e.pageContent.trim().split(/\s+/).length>this.targetSummarisedStringTokenCount)){if(await this.checkSummariserLoaded(),!this.summariser)return;if(v)D=(await Promise.allSettled(E.map(async e=>{if(!e.pageContent||typeof e.pageContent!=`string`)return``;if(e.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount)return e.pageContent;let t={start:0,end:e.pageContent.length};h&&Object.assign(t,h(e.pageContent)),t.start=d.default.clamp(d.default.toSafeInteger(t.start),0,e.pageContent.length),t.end=d.default.clamp(d.default.toSafeInteger(t.end),0,e.pageContent.length),this.DEBUG&&console.log(t);let n=e.pageContent.substring(t.start,t.end);this.DEBUG&&console.log(n);let r=e.pageContent.substring(0,t.start),i=e.pageContent.substring(t.end),a=r.split(/\s+/).length+i.split(/\s+/).length,o=Math.max(1,this.targetSummarisedStringTokenCount-a);this.DEBUG&&console.log(a,o);let s=await this.summariser?.(n,{max_length:o}),c=Array.isArray(s?.[0])?s?.[0]?.[0]:s?.[0];this.DEBUG&&console.log(s,c,c?.summary_text??``,(c?.summary_text??``).split(/\s+/).slice(0,o).join(` `));let l=r+(c?.summary_text??``).split(/\s+/).slice(0,o).join(` `).trim()+i;return this.DEBUG&&console.log(`Summarised candidate: `+l),l}))).filter(e=>e.status===`fulfilled`&&e.value).map(e=>e.value);else for(let e of E)try{if(!e.pageContent||typeof e.pageContent!=`string`)continue;if(e.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount){D.push(e.pageContent);continue}let t={start:0,end:e.pageContent.length};h&&Object.assign(t,h(e.pageContent)),t.start=d.default.clamp(d.default.toSafeInteger(t.start),0,e.pageContent.length),t.end=d.default.clamp(d.default.toSafeInteger(t.end),0,e.pageContent.length),this.DEBUG&&console.log(t);let n=e.pageContent.substring(t.start,t.end);this.DEBUG&&console.log(n);let r=e.pageContent.substring(0,t.start),i=e.pageContent.substring(t.end),a=r.split(/\s+/).length+i.split(/\s+/).length,o=Math.max(1,this.targetSummarisedStringTokenCount-a);this.DEBUG&&console.log(a,o);let s=await this.summariser?.(n,{max_length:o}),c=Array.isArray(s?.[0])?s?.[0]?.[0]:s?.[0];this.DEBUG&&console.log(s,c,c?.summary_text??``,(c?.summary_text??``).split(/\s+/).slice(0,o).join(` `));let l=r+(c?.summary_text??``).split(/\s+/).slice(0,o).join(` `).trim()+i;this.DEBUG&&console.log(`Summarised candidate: `+l),D.push(l)}catch(e){console.log(e)}}else D=E.map(e=>e.pageContent);let O=``;if(!_){let e=g(c({problemDescription:t,summaries:D,candidatesForFinalSelection:s,candidateIdentifierField:String(p)}));this.DEBUG&&console.log(`Formatted ranking prompt: `+e);let r=this.tokeniser.encode(e);if(this.DEBUG&&console.log(r.length,this.tokeniser.model_max_length),r.length>this.tokeniser.model_max_length)throw Error(`Ranking instruction prompt is too long for the tokeniser model`);try{y=(await n({generator:this.generator,tokeniser:this.tokeniser,prompt:e,textGenerationConfig:{max_new_tokens:this.rankingMaxNewTokens,temperature:this.rankingTemperature,repetition_penalty:this.rankingRepetitionPenalty}})).trim().replace(/(\*\*)|(<\/?s>)|(\[.*?\])\s*/g,``),this.DEBUG&&console.log(`Generated rationale: `+y);let t=y.indexOf(`### Response:`);t>=0?t+=13:t=0,y=y.substring(t)}catch(e){console.log(e),O=this.errorMessage(e),y=``}}if(y){let t=u(y);this.DEBUG&&console.log(`Extracted identifiers from rationale: `+t),t.length>s&&(t=t.slice(0,s)),b=d.default.compact(t.map(t=>m({identifier:t,candidateIdentifierField:p,candidates:e})))}if(!Array.isArray(b)||b.length<s){Array.isArray(b)||(b=[]);let t=d.default.compact(E.map(t=>{let n=f({candidateDocument:t.pageContent,candidateIdentifierField:String(p)});return this.DEBUG&&console.log(`Extracted identifier from candidate document: `+n),m({identifier:n,candidateIdentifierField:p,candidates:e})}));b.splice(b.length,0,...t),b=d.default.uniq(b).slice(0,s)}return this.DEBUG&&console.log(`Selected candidates`,b),{rationale:y,summaries:D,...O?{rationaleError:O}:{},selectedCandidates:b}}};(function(e){})(p||={});var m=p;Object.defineProperty(exports,`AICompareCandidates`,{enumerable:!0,get:function(){return p}}),exports.default=m;
14
14
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["Embeddings","env","AutoTokenizer","TextStreamer","matches:string[]","match:RegExpExecArray|null","selectedCandidates:Candidate[]","MemoryVectorStore","summaries:string[]","summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices"],"sources":["../src/index.ts"],"sourcesContent":["import{\n\tenv,\n\tpipeline,\n\tAutoTokenizer,\n\tTextGenerationPipeline,\n\tProgressInfo,\n\tProgressCallback,\n\tSummarizationPipeline,\n\tFeatureExtractionPipeline,\n\tPreTrainedTokenizer,\n\tTextGenerationConfig,\n\tTextGenerationSingle,\n\tTextStreamer\n}from '@sroussey/transformers';\nimport {MemoryVectorStore} from '@langchain/classic/vectorstores/memory';\nimport {Embeddings} from '@langchain/core/embeddings';\nimport lodash from 'lodash';\nimport jsan from 'jsan';\n\nexport class AICompareCandidates extends Embeddings{\n\treadonly env=env;\n\tDEBUG=true;\n\n\tgenerator:TextGenerationPipeline|null=null;\n\tgeneratorModelName='Xenova/Phi-3-mini-4k-instruct';\n\tgeneratorPromise:Promise<TextGenerationPipeline>|null=null;\n\tgeneratorProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tgeneratorProgressCallback:ProgressCallback|null=null;\n\tgeneratorAbortController=new AbortController();\n\n\tsummariser:SummarizationPipeline|null=null;\n\tsummariserModelName='Xenova/distilbart-cnn-12-6';\n\tsummariserPromise:Promise<SummarizationPipeline>|null=null;\n\tsummariserProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tsummariserProgressCallback:ProgressCallback|null=null;\n\tsummariserAbortController=new AbortController();\n\n\tembedder:FeatureExtractionPipeline|null=null;\n\tembedderModelName='Xenova/all-MiniLM-L12-v2';\n\tembedderPromise:Promise<FeatureExtractionPipeline>|null=null;\n\tembedderProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tembedderProgressCallback:ProgressCallback|null=null;\n\tembedderAbortController=new AbortController();\n\n\ttokeniser:PreTrainedTokenizer|null=null;\n\ttokeniserModelName=this.generatorModelName;\n\ttokeniserPromise:Promise<PreTrainedTokenizer>|null=null;\n\ttokeniserProgressInfo:ProgressInfo=<ProgressInfo>{};\n\ttokeniserProgressCallback:ProgressCallback|null=null;\n\ttokeniserAbortController=new AbortController();\n\n\tgenerateSearchAreasMaxNewTokens=64;\n\tgenerateSearchAreasTemperature=0.35;\n\tgenerateSearchAreasRepetitionPenalty=1.5;\n\n\trankingMaxNewTokens=64;\n\trankingTemperature=0.35;\n\trankingRepetitionPenalty=1.5;\n\n\ttargetSummarisedStringTokenCount=300;\n\n\tstatic{\n\t\tenv.localModelPath='';\n\t\tenv.allowRemoteModels=true;\n\t\tenv.allowLocalModels=false;\n\t}\n\n\tconstructor(){\n\t\tsuper({});\n\t}\n\t\n\tasync loadGenerator({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.generatorModelName=modelName;\n\t\tif(!this.generatorModelName)throw new Error('Invalid generator model name');\n\t\tif(progressCallback)this.generatorProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.generatorPromise=pipeline('text-generation',this.generatorModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.generatorProgressInfo,progressInfo);\n\t\t\t\treturn this.generatorProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.generatorAbortController.signal\n\t\t});\n\t\tthis.generator=await this.generatorPromise;\n\t\treturn this.generator;\n\t}\n\n\tasync checkGeneratorLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.generatorPromise)this.loadGenerator({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.generator){\n\t\t\ttry{\n\t\t\t\tawait this.generatorPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.generatorPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.generator){\n\t\t\tthis.generatorPromise=null;\n\t\t\tthrow new Error('Unable to load generator');\n\t\t}\n\t}\n\n\tasync abortLoadGenerator(reason?:any){\n\t\tthis.generatorAbortController.abort(reason);\n\t\tthis.generatorAbortController=new AbortController();\n\t}\n\n\tasync loadSummariser({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.summariserModelName=modelName;\n\t\tif(!this.summariserModelName)throw new Error('Invalid summariser model name');\n\t\tif(progressCallback)this.summariserProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.summariserPromise=pipeline('summarization',this.summariserModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.summariserProgressInfo,progressInfo);\n\t\t\t\treturn this.summariserProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.summariserAbortController.signal\n\t\t});\n\t\tthis.summariser=await this.summariserPromise;\n\t\treturn this.summariser;\n\t}\n\n\tasync checkSummariserLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.summariserPromise)this.loadSummariser({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.summariser){\n\t\t\ttry{\n\t\t\t\tawait this.summariserPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.summariserPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.summariser){\n\t\t\tthis.summariserPromise=null;\n\t\t\tthrow new Error('Unable to load summariser');\n\t\t}\n\t}\n\n\tasync abortLoadSummariser(){\n\t\tthis.summariserAbortController.abort();\n\t\tthis.summariserAbortController=new AbortController();\n\t}\n\n\tasync loadEmbedder({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.embedderModelName=modelName;\n\t\tif(!this.embedderModelName)throw new Error('Invalid embedder model name');\n\t\tif(progressCallback)this.embedderProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.embedderPromise=pipeline('feature-extraction',this.embedderModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.embedderProgressInfo,progressInfo);\n\t\t\t\treturn this.embedderProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.embedderAbortController.signal\n\t\t});\n\t\tthis.embedder=await this.embedderPromise;\n\t\treturn this.embedder;\n\t}\n\n\tasync checkEmbedderLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.embedderPromise)this.loadEmbedder({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.embedder){\n\t\t\ttry{\n\t\t\t\tawait this.embedderPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.embedderPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.embedder){\n\t\t\tthis.embedderPromise=null;\n\t\t\tthrow new Error('Unable to load embedder');\n\t\t}\n\t}\n\n\tasync abortLoadEmbedder(){\n\t\tthis.embedderAbortController.abort();\n\t\tthis.embedderAbortController=new AbortController();\n\t}\n\n\tasync loadTokeniser({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.tokeniserModelName=modelName;\n\t\tif(!this.tokeniserModelName)throw new Error('Invalid tokeniser model name');\n\t\tif(progressCallback)this.tokeniserProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.tokeniserPromise=AutoTokenizer.from_pretrained(this.tokeniserModelName,{\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.tokeniserProgressInfo,progressInfo);\n\t\t\t\treturn this.tokeniserProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.tokeniserAbortController.signal\n\t\t});\n\t\tthis.tokeniser=await this.tokeniserPromise;\n\t\treturn this.tokeniser;\n\t}\n\n\tasync checkTokeniserLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.tokeniserPromise)this.loadTokeniser({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.tokeniser){\n\t\t\ttry{\n\t\t\t\tawait this.tokeniserPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.tokeniserPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.tokeniser){\n\t\t\tthis.tokeniserPromise=null;\n\t\t\tthrow new Error('Unable to load tokeniser');\n\t\t}\n\t}\n\n\tasync abortLoadTokeniser(){\n\t\tthis.tokeniserAbortController.abort();\n\t\tthis.tokeniserAbortController=new AbortController();\n\t}\n\n\tasync embedQuery(text:string):Promise<number[]>{\n\t\tawait this.checkEmbedderLoaded();\n\t\tif(typeof this.embedder==='function')return Array.from((await this.embedder(text,{\n\t\t\tpooling:'mean',\n\t\t\tnormalize:true\n\t\t}))?.data);\n\t\treturn [];\n\t}\n\n\tasync embedDocuments(texts:string[]):Promise<number[][]>{\n\t\treturn Promise.all(texts.map(text=>this.embedQuery(text)));\n\t}\n\n\tdefaultGeneratePromptTemplate(prompt:string){\n\t\treturn prompt;\n\t}\n\n\tasync defaultPerformGeneration({\n\t\tgenerator,\n\t\ttokeniser,\n\t\tprompt='',\n\t\ttextGenerationConfig={}\n\t}:AICompareCandidates.PerformGenerationArguments=<AICompareCandidates.PerformGenerationArguments>{}){\n\t\tlet errors='';\n\t\tif(!generator)errors+='No generator provided.';\n\t\tif(!tokeniser)errors+=(errors?'\\n':'')+'No tokeniser provided.';\n\t\tif(typeof prompt!=='string'||!prompt)errors+=(errors?'\\n':'')+'No valid prompt provided.';\n\t\tif(errors)throw new Error(errors);\n\t\tlet messages=[{\n\t\t\trole:'user',\n\t\t\tcontent:prompt\n\t\t}];\n\t\tlet streamer=new TextStreamer(tokeniser,{\n\t\t\tskip_prompt:true\n\t\t});\n\t\tif(!textGenerationConfig.pad_token_id)textGenerationConfig.pad_token_id=tokeniser.pad_token_id??tokeniser.sep_token_id??0;\n\t\tif(!textGenerationConfig.eos_token_id)textGenerationConfig.eos_token_id=tokeniser.sep_token_id??2;\n\t\tlet output=await generator(messages,textGenerationConfig);\n\t\tif(this.DEBUG)console.log(output);\n\t\tlet outputObject=Array.isArray(output?.[0])?output?.[0]?.[0]:output?.[0];\n\t\tif(!outputObject.generated_text)throw new Error('No generated text');\n\t\tif(typeof outputObject.generated_text==='string')return outputObject.generated_text;\n\t\tlet content=outputObject.generated_text?.at(-1)?.content;\n\t\tif(typeof content!=='string'||!content)throw new Error('No content in generated text');\n\t\treturn content;\n\t}\n\n\tdefaultGenerateSearchAreasInstruction(problemDescription:string){\n\t\treturn 'List the relevant subject areas for the following issues. Limit your response to 100 words.\\nIssues: \"'+problemDescription+'\"';\n\t}\n\n\tdefaultConvertCandidateToDocument<Candidate>({\n\t\tcandidate,\n\t\tindex\n\t}:AICompareCandidates.ConvertCandidateToDocumentArguments<Candidate>=<AICompareCandidates.ConvertCandidateToDocumentArguments<Candidate>>{}){\n\t\tlet document='Start of Candidate #'+index;\n\t\tfor(let i in candidate)document+='\\n'+lodash.startCase(i)+': '+(typeof candidate[i]==='object'?jsan.stringify(candidate[i]):String(candidate[i]));\n\t\tdocument+='\\nEnd of Candidate #'+index;\n\t\treturn document;\n\t}\n\n\tdefaultGenerateRankingInstruction({\n\t\tproblemDescription,\n\t\tsummaries,\n\t\tcandidatesForFinalSelection,\n\t\tcandidateIdentifierField\n\t}:AICompareCandidates.GenerateRankingInstructionArguments=<AICompareCandidates.GenerateRankingInstructionArguments>{}){\n\t\treturn 'Rank only the top '+candidatesForFinalSelection+' candidates by connecting them to \"'+problemDescription+'\" stating # followed by the candidate number and the full '+lodash.startCase(candidateIdentifierField)+' followed by a 15-word explanation for each ranking. Stop generating text immediately thereafter.\\n\\nCandidates:\\n\\n'+summaries.join('\\n\\n');\n\t}\n\n\tregexIndexOf(text:string,regex:RegExp,startIndex:number){\n \tlet indexInSuffix=text.slice(startIndex).search(regex);\n \treturn indexInSuffix<0?indexInSuffix:indexInSuffix+startIndex;\n\t}\n\n\tdefaultExtractIdentifierFromCandidateDocument({\n\t\tcandidateDocument,\n\t\tcandidateIdentifierField\n\t}:AICompareCandidates.ExtractIdentifierFromCandidateDocumentArguments=<AICompareCandidates.ExtractIdentifierFromCandidateDocumentArguments>{}){\n\t\tif(this.DEBUG)console.log(candidateDocument,candidateIdentifierField);\n\t\tlet startCase=lodash.startCase(candidateIdentifierField);\n\t\tlet startIndex=candidateDocument.indexOf(startCase);\n\t\tif(startIndex<0)startIndex=candidateDocument.toLowerCase().indexOf(startCase.toLowerCase());\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex>=0)startIndex+=startCase.length;\n\t\tif(startIndex<0){\n\t\t\tstartIndex=candidateDocument.toLowerCase().indexOf(candidateIdentifierField.toLowerCase());\n\t\t\tif(startIndex>=0)startIndex+=candidateIdentifierField.length;\n\t\t}\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\telse return '';\n\t\tstartIndex=candidateDocument.indexOf(':',startIndex);\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex<0)startIndex=this.regexIndexOf(candidateDocument,/\\s+/,startIndex);\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex<0)return '';\n\t\tlet endIndex=candidateDocument.indexOf('\\n',startIndex);\n\t\tif(endIndex<0)endIndex=candidateDocument.length;\n\t\tif(this.DEBUG)console.log(endIndex);\n\t\treturn candidateDocument.substring(startIndex,endIndex).trim();\n\t}\n\n\tdefaultExtractIdentifiersFromRationale(rationale:string){\n\t\tlet regex=/^\\d+?\\s*?\\p{P}\\s*?(.+?)\\s*?(-|\\.|;|\\n)/gmu;\n\t\tlet matches:string[]=[];\n\t\tfor(let match:RegExpExecArray|null;Array.isArray(match=regex.exec(rationale));)if(match[1])matches.push(match[1]);\n\t\treturn matches;\n\t}\n\n\tdefaultFindCandidateFromIdentifier<Candidate>({\n\t\tidentifier,\n\t\tcandidateIdentifierField,\n\t\tcandidates\n\t}:AICompareCandidates.FindCandidateFromIdentifierArguments<Candidate>=<AICompareCandidates.FindCandidateFromIdentifierArguments<Candidate>>{}){\n\t\tif(!identifier||typeof identifier!=='string')identifier=String(identifier);\n\t\tconsole.log('identifier',identifier);\n\t\tlet selectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField])===identifier);\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField]).toLowerCase()===identifier.toLowerCase());\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField]).toLowerCase().includes(identifier.toLowerCase()));\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>identifier.toLowerCase().includes(String(candidate[candidateIdentifierField]).toLowerCase()));\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\t//split by space and find highest number of matches (tie break if it is in same order)\n\t\tlet identifierWords=identifier.split(/\\s+/g).filter(identifierWord=>/\\w/.test(identifierWord));\n\t\tif(this.DEBUG)console.log('Identifier words',identifierWords);\n\t\tlet selectedCandidates=candidates.map(candidate=>({\n\t\t\tidentifierWordIndices:identifierWords.map(identifierWord=>String(candidate[candidateIdentifierField]).indexOf(identifierWord)),\n\t\t\tcandidate\n\t\t})).filter(candidate=>candidate.identifierWordIndices.some(index=>index>=0));\n\t\tif(selectedCandidates.length>1){\n\t\t\tselectedCandidates.sort((a,b)=>{\n\t\t\t\tlet aCount=lodash.sumBy(a.identifierWordIndices,aElement=>aElement<0?0:1);\n\t\t\t\tlet bCount=lodash.sumBy(b.identifierWordIndices,bElement=>bElement<0?0:1);\n\t\t\t\tif(this.DEBUG){\n\t\t\t\t\tconsole.log('a',a);\n\t\t\t\t\tconsole.log('b',b);\n\t\t\t\t\tconsole.log('a.identifierWordIndices',a.identifierWordIndices);\n\t\t\t\t\tconsole.log('b.identifierWordIndices',b.identifierWordIndices);\n\t\t\t\t\tconsole.log('aCount',aCount);\n\t\t\t\t\tconsole.log('bCount',bCount);\n\t\t\t\t}\n\t\t\t\tif(aCount!==bCount)return bCount-aCount;\n\t\t\t\tif(aCount===0&&bCount===0)return 0;\n\t\t\t\taCount=0;\n\t\t\t\tbCount=0;\n\t\t\t\tfor(let i=0;i<a.identifierWordIndices.length-1;++i){\n\t\t\t\t\tfor(let j=i+1;j<a.identifierWordIndices.length;++j){\n\t\t\t\t\t\tif(a.identifierWordIndices[i]<0||a.identifierWordIndices[j]<0)continue;\n\t\t\t\t\t\tif(a.identifierWordIndices[i]<a.identifierWordIndices[j]){\n\t\t\t\t\t\t\tif(this.DEBUG){\n\t\t\t\t\t\t\t\tconsole.log('i',i);\n\t\t\t\t\t\t\t\tconsole.log('j',j);\n\t\t\t\t\t\t\t\tconsole.log('a.identifierWordIndices[i]',a.identifierWordIndices[i]);\n\t\t\t\t\t\t\t\tconsole.log('a.identifierWordIndices[j]',a.identifierWordIndices[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t++aCount;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(let i=0;i<b.identifierWordIndices.length-1;++i){\n\t\t\t\t\tfor(let j=i+1;j<b.identifierWordIndices.length;++j){\n\t\t\t\t\t\tif(b.identifierWordIndices[i]<0||b.identifierWordIndices[j]<0)continue;\n\t\t\t\t\t\tif(b.identifierWordIndices[i]<b.identifierWordIndices[j]){\n\t\t\t\t\t\t\tif(this.DEBUG){\n\t\t\t\t\t\t\t\tconsole.log('i',i);\n\t\t\t\t\t\t\t\tconsole.log('j',j);\n\t\t\t\t\t\t\t\tconsole.log('b.identifierWordIndices[i]',b.identifierWordIndices[i]);\n\t\t\t\t\t\t\t\tconsole.log('b.identifierWordIndices[j]',b.identifierWordIndices[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t++bCount;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(this.DEBUG){\n\t\t\t\t\tconsole.log('aCount',aCount);\n\t\t\t\t\tconsole.log('bCount',bCount);\n\t\t\t\t}\n\t\t\t\treturn bCount-aCount;\n\t\t\t});\n\t\t}\n\t\tif(selectedCandidates.length>=1&&selectedCandidates[0].candidate)return selectedCandidates[0].candidate;\n\t\treturn null;\n\t}\n\n\tdefaultParseSearchAreasResponse(searchAreasResponse:string){\n\t\tlet searchAreasResponseIndex=String(searchAreasResponse).indexOf('### Response:');\n\t\tif(searchAreasResponseIndex>=0)searchAreasResponseIndex+='### Response:'.length;\n\t\telse searchAreasResponseIndex=0;\n\t\treturn String(searchAreasResponse).substring(searchAreasResponseIndex).trim();\n\t}\n\n\terrorMessage(error:any){\n\t\treturn typeof error?.response?.data==='string'?error.response.data:error?.response?.data?jsan.stringify(error.response.data):typeof error?.message==='string'?error.message:error?.message?jsan.stringify(error.message):typeof error==='string'?error:jsan.stringify(error);\n\t}\n\n\tasync compareCandidates<Candidate>({\n\t\tcandidates,\n\t\tproblemDescription='',\n\t\tperformGeneration=this.defaultPerformGeneration.bind(this),\n\t\tgenerateSearchAreasInstruction=this.defaultGenerateSearchAreasInstruction.bind(this),\n\t\tparseSearchAreasResponse=this.defaultParseSearchAreasResponse.bind(this),\n\t\tconvertCandidateToDocument=this.defaultConvertCandidateToDocument.bind(this),\n\t\tcandidatesForInitialSelection=2,\n\t\tcandidatesForFinalSelection=1,\n\t\tgenerateRankingInstruction=this.defaultGenerateRankingInstruction.bind(this),\n\t\textractIdentifiersFromRationale=this.defaultExtractIdentifiersFromRationale.bind(this),\n\t\textractIdentifierFromCandidateDocument=this.defaultExtractIdentifierFromCandidateDocument.bind(this),\n\t\tcandidateIdentifierField=undefined,\n\t\tfindCandidateFromIdentifier=this.defaultFindCandidateFromIdentifier.bind(this),\n\t\tgetSummarisableSubstringIndices,\n\t\tgeneratePromptTemplate=this.defaultGeneratePromptTemplate.bind(this),\n\t\tskipRationale=false\n\t}:AICompareCandidates.CompareArguments<Candidate>=<AICompareCandidates.CompareArguments<Candidate>>{}):Promise<AICompareCandidates.CompareCandidatesReturn<Candidate>|void>{\n\t\tif(!Array.isArray(candidates)||candidates.length<=0)throw new Error('No candidates provided');\n\t\tcandidatesForInitialSelection=lodash.toSafeInteger(candidatesForInitialSelection);\n\t\tif(candidatesForInitialSelection<=0)throw new Error('Candidates for initial selection must be a positive integer bigger than 0');\n\t\tcandidatesForFinalSelection=lodash.toSafeInteger(candidatesForFinalSelection);\n\t\tif(candidatesForFinalSelection<=0)throw new Error('Candidates for initial selection must be a positive integer bigger than 0');\n\t\tif(candidatesForInitialSelection<candidatesForFinalSelection)throw new Error('Candidates for initial selection must be equal or more than candidates for final selection');\n\t\tif(candidatesForInitialSelection>candidates.length)throw new Error('There are '+candidatesForInitialSelection+'candidates for initial selection which is more than the total number of candidates of '+candidates.length);\n\t\tif(candidatesForFinalSelection>candidates.length)throw new Error('There are '+candidatesForFinalSelection+'candidates for initial selection which is more than the total number of candidates of '+candidates.length);\n\t\tif(!candidateIdentifierField){\n\t\t\tcandidateIdentifierField=Object.keys(candidates[0] as object)[0] as keyof Candidate;\n\t\t\tif(!candidateIdentifierField)throw new Error('No candidate identifier field');\n\t\t}\n\n\t\tlet rationale='';\n\t\tlet selectedCandidates:Candidate[]=[];\n\n\t\tawait this.checkEmbedderLoaded();\n\t\tif(!this.embedder)return;\n\t\tlet candidateDocuments=candidates.map((candidate,index)=>convertCandidateToDocument({\n\t\t\tcandidate,\n\t\t\tindex\n\t\t}));\n\t\tlet vectorStore=await MemoryVectorStore.fromTexts(\n\t\t\tlodash.cloneDeep(candidateDocuments),\n\t\t\tcandidateDocuments.map((document,index)=>index),\n\t\t\tthis\n\t\t);\n\n\t\tlet searchAreasPromptTemplate=generatePromptTemplate(generateSearchAreasInstruction(problemDescription));\n\t\tif(this.DEBUG)console.log('Formatted search areas prompt: '+searchAreasPromptTemplate);\n\t\tawait this.checkTokeniserLoaded();\n\t\tif(!this.tokeniser)return;\n\t\tlet searchAreasPromptTokens=this.tokeniser.encode(searchAreasPromptTemplate);\n\t\tif(searchAreasPromptTokens.length>this.tokeniser.model_max_length)throw new Error('Search areas instruction prompt is too long for the tokeniser model');\n\n\t\tawait this.checkGeneratorLoaded();\n\t\tif(!this.generator)return;\n\t\tlet generatedText=await performGeneration({\n\t\t\tgenerator:this.generator,\n\t\t\ttokeniser:this.tokeniser,\n\t\t\tprompt:searchAreasPromptTemplate,\n\t\t\ttextGenerationConfig:{\n\t\t\t\tmax_new_tokens:this.generateSearchAreasMaxNewTokens,\n\t\t\t\ttemperature:this.generateSearchAreasTemperature,\n\t\t\t\trepetition_penalty:this.generateSearchAreasRepetitionPenalty\n\t\t\t}\n\t\t});\n\t\tif(this.DEBUG)console.log('Generated search areas response: '+generatedText);\n\t\tlet vectorSearchQuery=parseSearchAreasResponse(generatedText);\n\t\t//generally the first sentence has the greatest relevance to the actual prompt\n\t\t//if(vectorSearchQuery.includes('.'))vectorSearchQuery=vectorSearchQuery.split('.')[0].trim();\n\t\tif(this.DEBUG)console.log('Vector search query: '+vectorSearchQuery);\n\t\tlet queryResult=await vectorStore.similaritySearch(vectorSearchQuery,candidatesForInitialSelection);\n\t\tif(this.DEBUG)console.log('Vector search results: ',queryResult);\n\n\t\tlet summaries:string[]=[];\n\t\t//only bother doing summarisation if there are candidates which exceed the token count\n\t\tif(queryResult.some(result=>result.pageContent.trim().split(/\\s+/).length>this.targetSummarisedStringTokenCount)){\n\t\t\tawait this.checkSummariserLoaded();\n\t\t\tif(!this.summariser)return;\n\t\t\tsummaries=(await Promise.allSettled(queryResult.map(async result=>{\n\t\t\t\tif(!result.pageContent||typeof result.pageContent!=='string')return '';\n\t\t\t\tif(result.pageContent.trim().split(/\\s+/).length<=this.targetSummarisedStringTokenCount)return result.pageContent;\n\t\t\t\tlet summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={\n\t\t\t\t\tstart:0,\n\t\t\t\t\tend:result.pageContent.length\n\t\t\t\t};\n\t\t\t\tif(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));\n\t\t\t\tsummarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);\n\t\t\t\tsummarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);\n\t\t\t\tif(this.DEBUG)console.log(summarisableSubstringIndices);\n\t\t\t\tlet summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);\n\t\t\t\tif(this.DEBUG)console.log(summarisableSubstring);\n\t\t\t\tlet contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);\n\t\t\t\tlet contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);\n\t\t\t\tlet wordsWithoutSummarisable=contentBefore.split(/\\s+/).length+contentAfter.split(/\\s+/).length;\n\t\t\t\tlet targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);\n\t\t\t\tif(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);\n\t\t\t\tlet summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{\n\t\t\t\t\tmax_length:targetSummarisedSubstringTokenCount\n\t\t\t\t});\n\t\t\t\tlet summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];\n\t\t\t\tif(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));\n\t\t\t\tlet summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;\n\t\t\t\tif(this.DEBUG)console.log('Summarised candidate: '+summarisedString);\n\t\t\t\treturn summarisedString;\n\t\t\t}))).filter(result=>result.status==='fulfilled'&&result.value).map(result=>(result as PromiseFulfilledResult<string>).value);\n\t\t}else{\n\t\t\tsummaries=queryResult.map(result=>result.pageContent);\n\t\t}\n\t\t\n\t\tlet rationaleError='';\n\n\t\tif(!skipRationale){\n\t\t\tlet rankingPromptTemplate=generatePromptTemplate(generateRankingInstruction({\n\t\t\t\tproblemDescription,\n\t\t\t\tsummaries,\n\t\t\t\tcandidatesForFinalSelection,\n\t\t\t\tcandidateIdentifierField:String(candidateIdentifierField)\n\t\t\t}));\n\t\t\tif(this.DEBUG)console.log('Formatted ranking prompt: '+rankingPromptTemplate);\n\t\t\tlet rankingPromptTokens=this.tokeniser.encode(rankingPromptTemplate);\n\t\t\tif(this.DEBUG)console.log(rankingPromptTokens.length,this.tokeniser.model_max_length);\n\t\t\tif(rankingPromptTokens.length>this.tokeniser.model_max_length)throw new Error('Ranking instruction prompt is too long for the tokeniser model');\n\t\t\ttry{\n\t\t\t\tlet ranking=await performGeneration({\n\t\t\t\t\tgenerator:this.generator,\n\t\t\t\t\ttokeniser:this.tokeniser,\n\t\t\t\t\tprompt:rankingPromptTemplate,\n\t\t\t\t\ttextGenerationConfig:{\n\t\t\t\t\t\tmax_new_tokens:this.rankingMaxNewTokens,\n\t\t\t\t\t\ttemperature:this.rankingTemperature,\n\t\t\t\t\t\trepetition_penalty:this.rankingRepetitionPenalty\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\trationale=ranking.trim().replace(/(\\*\\*)|(<\\/?s>)|(\\[.*?\\])\\s*/g, '');\n\t\t\t\tif(this.DEBUG)console.log('Generated rationale: '+rationale);\n\t\t\t\tlet rationaleResponseIndex=rationale.indexOf('### Response:');\n\t\t\t\tif(rationaleResponseIndex>=0)rationaleResponseIndex+='### Response:'.length;\n\t\t\t\telse rationaleResponseIndex=0;\n\t\t\t\trationale=rationale.substring(rationaleResponseIndex);\n\t\t\t\t//if(!rationale)throw new Error('No rationale generated');\n\t\t\t}catch(error){\n\t\t\t\tconsole.log(error);\n\t\t\t\trationaleError=this.errorMessage(error);\n\t\t\t\trationale='';\n\t\t\t}\n\t\t}\n\n\t\tif(rationale){\n\t\t\tlet identifiers=extractIdentifiersFromRationale(rationale);\n\t\t\tif(this.DEBUG)console.log('Extracted identifiers from rationale: '+identifiers);\n\t\t\tif(identifiers.length>candidatesForFinalSelection)identifiers=identifiers.slice(0,candidatesForFinalSelection);\n\t\t\tselectedCandidates=lodash.compact(identifiers.map(identifier=>findCandidateFromIdentifier({\n\t\t\t\tidentifier,\n\t\t\t\tcandidateIdentifierField,\n\t\t\t\tcandidates\n\t\t\t})));\n\t\t}\n\n\t\tif(!Array.isArray(selectedCandidates)||selectedCandidates.length<candidatesForFinalSelection){\n\t\t\tif(!Array.isArray(selectedCandidates))selectedCandidates=[];\n\t\t\tlet additionalSelectedCandidates=lodash.compact(queryResult.map(result=>{\n\t\t\t\tlet identifier=extractIdentifierFromCandidateDocument({\n\t\t\t\t\tcandidateDocument:result.pageContent,\n\t\t\t\t\tcandidateIdentifierField:String(candidateIdentifierField)\n\t\t\t\t});\n\t\t\t\tif(this.DEBUG)console.log('Extracted identifier from candidate document: '+identifier);\n\t\t\t\treturn findCandidateFromIdentifier({\n\t\t\t\t\tidentifier,\n\t\t\t\t\tcandidateIdentifierField,\n\t\t\t\t\tcandidates\n\t\t\t\t});\n\t\t\t}));\n\t\t\tselectedCandidates.splice(selectedCandidates.length,0,...additionalSelectedCandidates);\n\t\t\tselectedCandidates=lodash.uniq(selectedCandidates).slice(0,candidatesForFinalSelection);\n\t\t}\n\t\tif(this.DEBUG)console.log('Selected candidates',selectedCandidates);\n\n\t\treturn{\n\t\t\trationale,\n\t\t\tsummaries,\n\t\t\t...(rationaleError?{rationaleError}:{}),\n\t\t\tselectedCandidates\n\t\t};\n\t}\n};\n\nexport namespace AICompareCandidates{\n\texport interface LoadArguments{\n\t\tprogressCallback?:ProgressCallback;\n\t\tmodelName?:string;\n\t};\n\n\texport interface SummarisableSubstringIndices{\n\t\tstart:number;\n\t\tend:number;\n\t};\n\n\texport interface CompareArguments<Candidate>{\n\t\tcandidates:Candidate[];\n\t\tproblemDescription:string;\n\t\tperformGeneration?:(performGenerationArguments:PerformGenerationArguments)=>Promise<string>;\n\t\tgenerateSearchAreasInstruction?:(problemDescription:string)=>string;\n\t\tparseSearchAreasResponse?:(searchAreasResponse:string)=>string;\n\t\tconvertCandidateToDocument?:(convertCandidateToDocumentArguments:ConvertCandidateToDocumentArguments<Candidate>)=>string;\n\t\tcandidatesForInitialSelection?:number;\n\t\tcandidatesForFinalSelection?:number;\n\t\tgenerateRankingInstruction?:(generateRankingInstructionArguments:GenerateRankingInstructionArguments)=>string;\n\t\textractIdentifiersFromRationale?:(rationale:string)=>string[];\n\t\textractIdentifierFromCandidateDocument?:(extractIdentifierFromCandidateDocumentArguments:ExtractIdentifierFromCandidateDocumentArguments)=>string;\n\t\tcandidateIdentifierField?:keyof Candidate;\n\t\tfindCandidateFromIdentifier?:(findCandidateFromIdentifierArguments:FindCandidateFromIdentifierArguments<Candidate>)=>Candidate|null;\n\t\tgetSummarisableSubstringIndices?:(candidateDocument:string)=>SummarisableSubstringIndices;\n\t\tgeneratePromptTemplate?:(prompt:string)=>string;\n\t\tskipRationale?:boolean;\n\t};\n\n\texport interface PerformGenerationArguments{\n\t\tgenerator:TextGenerationPipeline;\n\t\ttokeniser:PreTrainedTokenizer;\n\t\tprompt:string;\n\t\ttextGenerationConfig?:Partial<TextGenerationConfig>;\n\t};\n\n\texport interface ConvertCandidateToDocumentArguments<Candidate>{\n\t\tcandidate:Candidate;\n\t\tindex:number;\n\t};\n\n\texport interface ExtractIdentifierFromCandidateDocumentArguments{\n\t\tcandidateDocument:string;\n\t\tcandidateIdentifierField:string;\n\t};\n\n\texport interface FindCandidateFromIdentifierArguments<Candidate>{\n\t\tidentifier:string;\n\t\tcandidateIdentifierField:keyof Candidate;\n\t\tcandidates:Candidate[];\n\t};\n\n\texport interface GenerateRankingInstructionArguments{\n\t\tproblemDescription:string;\n\t\tsummaries:string[];\n\t\tcandidatesForFinalSelection:number;\n\t\tcandidateIdentifierField:string;\n\t};\n\n\texport interface CompareCandidatesReturn<Candidate>{\n\t\tselectedCandidates:Candidate[],\n\t\trationale:string,\n\t\trationaleError?:string,\n\t\tsummaries:string[]\n\t};\n};\n\nexport default AICompareCandidates;"],"mappings":"itBAmBA,IAAa,EAAb,cAAyCA,EAAAA,UAAU,CAClD,IAAaC,EAAAA,IACb,MAAM,GAEN,UAAsC,KACtC,mBAAmB,gCACnB,iBAAsD,KACtD,sBAAiD,EAAE,CACnD,0BAAgD,KAChD,yBAAyB,IAAI,gBAE7B,WAAsC,KACtC,oBAAoB,6BACpB,kBAAsD,KACtD,uBAAkD,EAAE,CACpD,2BAAiD,KACjD,0BAA0B,IAAI,gBAE9B,SAAwC,KACxC,kBAAkB,2BAClB,gBAAwD,KACxD,qBAAgD,EAAE,CAClD,yBAA+C,KAC/C,wBAAwB,IAAI,gBAE5B,UAAmC,KACnC,mBAAmB,KAAK,mBACxB,iBAAmD,KACnD,sBAAiD,EAAE,CACnD,0BAAgD,KAChD,yBAAyB,IAAI,gBAE7B,gCAAgC,GAChC,+BAA+B,IAC/B,qCAAqC,IAErC,oBAAoB,GACpB,mBAAmB,IACnB,yBAAyB,IAEzB,iCAAiC,IAEjC,OACC,EAAA,IAAI,eAAe,GACnB,EAAA,IAAI,kBAAkB,GACtB,EAAA,IAAI,iBAAiB,GAGtB,aAAa,CACZ,MAAM,EAAE,CAAC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AAM,CAClB,EAAe,KAAK,aAAa,EAAM,CACvC,EAAU,IAIZ,GAAG,EAAU,CACZ,IAAI,EAAY,EAAgC,EAAU,CACvD,KAAK,OAAM,QAAQ,IAAI,yCAAyC,EAAY,CAC5E,EAAY,OAAO,IAA4B,EAAY,EAAY,MAAM,EAAE,EAA4B,EAC9G,EAAmB,EAAA,QAAO,QAAQ,EAAY,IAAI,GAAY,EAA4B,CACzF,aACA,2BACA,aACA,CAAC,CAAC,CAAC,CAGL,GAAG,CAAC,MAAM,QAAQ,EAAmB,EAAE,EAAmB,OAAO,EAA4B,CACxF,MAAM,QAAQ,EAAmB,GAAC,EAAmB,EAAE,EAC3D,IAAI,EAA6B,EAAA,QAAO,QAAQ,EAAY,IAAI,GAAQ,CACvE,IAAI,EAAW,EAAuC,CACrD,kBAAkB,EAAO,YACzB,yBAAyB,OAAO,EAAyB,CACzD,CAAC,CAEF,OADG,KAAK,OAAM,QAAQ,IAAI,iDAAiD,EAAW,CAC/E,EAA4B,CAClC,aACA,2BACA,aACA,CAAC,EACD,CAAC,CACH,EAAmB,OAAO,EAAmB,OAAO,EAAE,GAAG,EAA6B,CACtF,EAAmB,EAAA,QAAO,KAAK,EAAmB,CAAC,MAAM,EAAE,EAA4B,CAIxF,OAFG,KAAK,OAAM,QAAQ,IAAI,sBAAsB,EAAmB,CAE7D,CACL,YACA,YACA,GAAI,EAAe,CAAC,iBAAe,CAAC,EAAE,CACtC,qBACA,2BAwEH,IAAA,EAAe"}
1
+ {"version":3,"file":"index.cjs","names":["Embeddings","env","AutoTokenizer","TextStreamer","matches:string[]","match:RegExpExecArray|null","selectedCandidates:Candidate[]","MemoryVectorStore","summaries:string[]","summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices"],"sources":["../src/index.ts"],"sourcesContent":["import{\n\tenv,\n\tpipeline,\n\tAutoTokenizer,\n\tTextGenerationPipeline,\n\tProgressInfo,\n\tProgressCallback,\n\tSummarizationPipeline,\n\tFeatureExtractionPipeline,\n\tPreTrainedTokenizer,\n\tTextGenerationConfig,\n\tTextGenerationSingle,\n\tTextStreamer\n}from '@sroussey/transformers';\nimport {MemoryVectorStore} from '@langchain/classic/vectorstores/memory';\nimport {Embeddings} from '@langchain/core/embeddings';\nimport lodash from 'lodash';\nimport jsan from 'jsan';\n\nexport class AICompareCandidates extends Embeddings{\n\treadonly env=env;\n\tDEBUG=true;\n\n\tgenerator:TextGenerationPipeline|null=null;\n\tgeneratorModelName='Xenova/Phi-3-mini-4k-instruct';\n\tgeneratorPromise:Promise<TextGenerationPipeline>|null=null;\n\tgeneratorProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tgeneratorProgressCallback:ProgressCallback|null=null;\n\tgeneratorAbortController=new AbortController();\n\n\tsummariser:SummarizationPipeline|null=null;\n\tsummariserModelName='Xenova/distilbart-cnn-12-6';\n\tsummariserPromise:Promise<SummarizationPipeline>|null=null;\n\tsummariserProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tsummariserProgressCallback:ProgressCallback|null=null;\n\tsummariserAbortController=new AbortController();\n\n\tembedder:FeatureExtractionPipeline|null=null;\n\tembedderModelName='Xenova/all-MiniLM-L12-v2';\n\tembedderPromise:Promise<FeatureExtractionPipeline>|null=null;\n\tembedderProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tembedderProgressCallback:ProgressCallback|null=null;\n\tembedderAbortController=new AbortController();\n\n\ttokeniser:PreTrainedTokenizer|null=null;\n\ttokeniserModelName=this.generatorModelName;\n\ttokeniserPromise:Promise<PreTrainedTokenizer>|null=null;\n\ttokeniserProgressInfo:ProgressInfo=<ProgressInfo>{};\n\ttokeniserProgressCallback:ProgressCallback|null=null;\n\ttokeniserAbortController=new AbortController();\n\n\tgenerateSearchAreasMaxNewTokens=64;\n\tgenerateSearchAreasTemperature=0.35;\n\tgenerateSearchAreasRepetitionPenalty=1.5;\n\n\trankingMaxNewTokens=64;\n\trankingTemperature=0.35;\n\trankingRepetitionPenalty=1.5;\n\n\ttargetSummarisedStringTokenCount=300;\n\n\tstatic{\n\t\tenv.localModelPath='';\n\t\tenv.allowRemoteModels=true;\n\t\tenv.allowLocalModels=false;\n\t}\n\n\tconstructor(){\n\t\tsuper({});\n\t}\n\t\n\tasync loadGenerator({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.generatorModelName=modelName;\n\t\tif(!this.generatorModelName)throw new Error('Invalid generator model name');\n\t\tif(progressCallback)this.generatorProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.generatorPromise=pipeline('text-generation',this.generatorModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.generatorProgressInfo,progressInfo);\n\t\t\t\treturn this.generatorProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.generatorAbortController.signal\n\t\t});\n\t\tthis.generator=await this.generatorPromise;\n\t\treturn this.generator;\n\t}\n\n\tasync checkGeneratorLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.generatorPromise)this.loadGenerator({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.generator){\n\t\t\ttry{\n\t\t\t\tawait this.generatorPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.generatorPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.generator){\n\t\t\tthis.generatorPromise=null;\n\t\t\tthrow new Error('Unable to load generator');\n\t\t}\n\t}\n\n\tasync abortLoadGenerator(reason?:any){\n\t\tthis.generatorAbortController.abort(reason);\n\t\tthis.generatorAbortController=new AbortController();\n\t}\n\n\tasync loadSummariser({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.summariserModelName=modelName;\n\t\tif(!this.summariserModelName)throw new Error('Invalid summariser model name');\n\t\tif(progressCallback)this.summariserProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.summariserPromise=pipeline('summarization',this.summariserModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.summariserProgressInfo,progressInfo);\n\t\t\t\treturn this.summariserProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.summariserAbortController.signal\n\t\t});\n\t\tthis.summariser=await this.summariserPromise;\n\t\treturn this.summariser;\n\t}\n\n\tasync checkSummariserLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.summariserPromise)this.loadSummariser({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.summariser){\n\t\t\ttry{\n\t\t\t\tawait this.summariserPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.summariserPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.summariser){\n\t\t\tthis.summariserPromise=null;\n\t\t\tthrow new Error('Unable to load summariser');\n\t\t}\n\t}\n\n\tasync abortLoadSummariser(){\n\t\tthis.summariserAbortController.abort();\n\t\tthis.summariserAbortController=new AbortController();\n\t}\n\n\tasync loadEmbedder({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.embedderModelName=modelName;\n\t\tif(!this.embedderModelName)throw new Error('Invalid embedder model name');\n\t\tif(progressCallback)this.embedderProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.embedderPromise=pipeline('feature-extraction',this.embedderModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.embedderProgressInfo,progressInfo);\n\t\t\t\treturn this.embedderProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.embedderAbortController.signal\n\t\t});\n\t\tthis.embedder=await this.embedderPromise;\n\t\treturn this.embedder;\n\t}\n\n\tasync checkEmbedderLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.embedderPromise)this.loadEmbedder({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.embedder){\n\t\t\ttry{\n\t\t\t\tawait this.embedderPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.embedderPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.embedder){\n\t\t\tthis.embedderPromise=null;\n\t\t\tthrow new Error('Unable to load embedder');\n\t\t}\n\t}\n\n\tasync abortLoadEmbedder(){\n\t\tthis.embedderAbortController.abort();\n\t\tthis.embedderAbortController=new AbortController();\n\t}\n\n\tasync loadTokeniser({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.tokeniserModelName=modelName;\n\t\tif(!this.tokeniserModelName)throw new Error('Invalid tokeniser model name');\n\t\tif(progressCallback)this.tokeniserProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.tokeniserPromise=AutoTokenizer.from_pretrained(this.tokeniserModelName,{\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.tokeniserProgressInfo,progressInfo);\n\t\t\t\treturn this.tokeniserProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.tokeniserAbortController.signal\n\t\t});\n\t\tthis.tokeniser=await this.tokeniserPromise;\n\t\treturn this.tokeniser;\n\t}\n\n\tasync checkTokeniserLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.tokeniserPromise)this.loadTokeniser({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.tokeniser){\n\t\t\ttry{\n\t\t\t\tawait this.tokeniserPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.tokeniserPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.tokeniser){\n\t\t\tthis.tokeniserPromise=null;\n\t\t\tthrow new Error('Unable to load tokeniser');\n\t\t}\n\t}\n\n\tasync abortLoadTokeniser(){\n\t\tthis.tokeniserAbortController.abort();\n\t\tthis.tokeniserAbortController=new AbortController();\n\t}\n\n\tasync embedQuery(text:string):Promise<number[]>{\n\t\tawait this.checkEmbedderLoaded();\n\t\tif(typeof this.embedder==='function')return Array.from((await this.embedder(text,{\n\t\t\tpooling:'mean',\n\t\t\tnormalize:true\n\t\t}))?.data);\n\t\treturn [];\n\t}\n\n\tasync embedDocuments(texts:string[]):Promise<number[][]>{\n\t\treturn Promise.all(texts.map(text=>this.embedQuery(text)));\n\t}\n\n\tdefaultGeneratePromptTemplate(prompt:string){\n\t\treturn prompt;\n\t}\n\n\tasync defaultPerformGeneration({\n\t\tgenerator,\n\t\ttokeniser,\n\t\tprompt='',\n\t\ttextGenerationConfig={}\n\t}:AICompareCandidates.PerformGenerationArguments=<AICompareCandidates.PerformGenerationArguments>{}){\n\t\tlet errors='';\n\t\tif(!generator)errors+='No generator provided.';\n\t\tif(!tokeniser)errors+=(errors?'\\n':'')+'No tokeniser provided.';\n\t\tif(typeof prompt!=='string'||!prompt)errors+=(errors?'\\n':'')+'No valid prompt provided.';\n\t\tif(errors)throw new Error(errors);\n\t\tlet messages=[{\n\t\t\trole:'user',\n\t\t\tcontent:prompt\n\t\t}];\n\t\tlet streamer=new TextStreamer(tokeniser,{\n\t\t\tskip_prompt:true\n\t\t});\n\t\tif(!textGenerationConfig.pad_token_id)textGenerationConfig.pad_token_id=tokeniser.pad_token_id??tokeniser.sep_token_id??0;\n\t\tif(!textGenerationConfig.eos_token_id)textGenerationConfig.eos_token_id=tokeniser.sep_token_id??2;\n\t\tlet output=await generator(messages,textGenerationConfig);\n\t\tif(this.DEBUG)console.log(output);\n\t\tlet outputObject=Array.isArray(output?.[0])?output?.[0]?.[0]:output?.[0];\n\t\tif(!outputObject.generated_text)throw new Error('No generated text');\n\t\tif(typeof outputObject.generated_text==='string')return outputObject.generated_text;\n\t\tlet content=outputObject.generated_text?.at(-1)?.content;\n\t\tif(typeof content!=='string'||!content)throw new Error('No content in generated text');\n\t\treturn content;\n\t}\n\n\tdefaultGenerateSearchAreasInstruction(problemDescription:string){\n\t\treturn 'List the relevant subject areas for the following issues. Limit your response to 100 words.\\nIssues: \"'+problemDescription+'\"';\n\t}\n\n\tdefaultConvertCandidateToDocument<Candidate>({\n\t\tcandidate,\n\t\tindex\n\t}:AICompareCandidates.ConvertCandidateToDocumentArguments<Candidate>=<AICompareCandidates.ConvertCandidateToDocumentArguments<Candidate>>{}){\n\t\tlet document='Start of Candidate #'+index;\n\t\tfor(let i in candidate)document+='\\n'+lodash.startCase(i)+': '+(typeof candidate[i]==='object'?jsan.stringify(candidate[i]):String(candidate[i]));\n\t\tdocument+='\\nEnd of Candidate #'+index;\n\t\treturn document;\n\t}\n\n\tdefaultGenerateRankingInstruction({\n\t\tproblemDescription,\n\t\tsummaries,\n\t\tcandidatesForFinalSelection,\n\t\tcandidateIdentifierField\n\t}:AICompareCandidates.GenerateRankingInstructionArguments=<AICompareCandidates.GenerateRankingInstructionArguments>{}){\n\t\treturn 'Rank only the top '+candidatesForFinalSelection+' candidates by connecting them to \"'+problemDescription+'\" stating # followed by the candidate number and the full '+lodash.startCase(candidateIdentifierField)+' followed by a 15-word explanation for each ranking. Stop generating text immediately thereafter.\\n\\nCandidates:\\n\\n'+summaries.join('\\n\\n');\n\t}\n\n\tregexIndexOf(text:string,regex:RegExp,startIndex:number){\n \tlet indexInSuffix=text.slice(startIndex).search(regex);\n \treturn indexInSuffix<0?indexInSuffix:indexInSuffix+startIndex;\n\t}\n\n\tdefaultExtractIdentifierFromCandidateDocument({\n\t\tcandidateDocument,\n\t\tcandidateIdentifierField\n\t}:AICompareCandidates.ExtractIdentifierFromCandidateDocumentArguments=<AICompareCandidates.ExtractIdentifierFromCandidateDocumentArguments>{}){\n\t\tif(this.DEBUG)console.log(candidateDocument,candidateIdentifierField);\n\t\tlet startCase=lodash.startCase(candidateIdentifierField);\n\t\tlet startIndex=candidateDocument.indexOf(startCase);\n\t\tif(startIndex<0)startIndex=candidateDocument.toLowerCase().indexOf(startCase.toLowerCase());\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex>=0)startIndex+=startCase.length;\n\t\tif(startIndex<0){\n\t\t\tstartIndex=candidateDocument.toLowerCase().indexOf(candidateIdentifierField.toLowerCase());\n\t\t\tif(startIndex>=0)startIndex+=candidateIdentifierField.length;\n\t\t}\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\telse return '';\n\t\tstartIndex=candidateDocument.indexOf(':',startIndex);\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex<0)startIndex=this.regexIndexOf(candidateDocument,/\\s+/,startIndex);\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex<0)return '';\n\t\tlet endIndex=candidateDocument.indexOf('\\n',startIndex);\n\t\tif(endIndex<0)endIndex=candidateDocument.length;\n\t\tif(this.DEBUG)console.log(endIndex);\n\t\treturn candidateDocument.substring(startIndex,endIndex).trim();\n\t}\n\n\tdefaultExtractIdentifiersFromRationale(rationale:string){\n\t\tlet regex=/^\\d+?\\s*?\\p{P}\\s*?(.+?)\\s*?(-|\\.|;|\\n)/gmu;\n\t\tlet matches:string[]=[];\n\t\tfor(let match:RegExpExecArray|null;Array.isArray(match=regex.exec(rationale));)if(match[1])matches.push(match[1]);\n\t\treturn matches;\n\t}\n\n\tdefaultFindCandidateFromIdentifier<Candidate>({\n\t\tidentifier,\n\t\tcandidateIdentifierField,\n\t\tcandidates\n\t}:AICompareCandidates.FindCandidateFromIdentifierArguments<Candidate>=<AICompareCandidates.FindCandidateFromIdentifierArguments<Candidate>>{}){\n\t\tif(!identifier||typeof identifier!=='string')identifier=String(identifier);\n\t\tconsole.log('identifier',identifier);\n\t\tlet selectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField])===identifier);\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField]).toLowerCase()===identifier.toLowerCase());\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField]).toLowerCase().includes(identifier.toLowerCase()));\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>identifier.toLowerCase().includes(String(candidate[candidateIdentifierField]).toLowerCase()));\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\t//split by space and find highest number of matches (tie break if it is in same order)\n\t\tlet identifierWords=identifier.split(/\\s+/g).filter(identifierWord=>/\\w/.test(identifierWord));\n\t\tif(this.DEBUG)console.log('Identifier words',identifierWords);\n\t\tlet selectedCandidates=candidates.map(candidate=>({\n\t\t\tidentifierWordIndices:identifierWords.map(identifierWord=>String(candidate[candidateIdentifierField]).indexOf(identifierWord)),\n\t\t\tcandidate\n\t\t})).filter(candidate=>candidate.identifierWordIndices.some(index=>index>=0));\n\t\tif(selectedCandidates.length>1){\n\t\t\tselectedCandidates.sort((a,b)=>{\n\t\t\t\tlet aCount=lodash.sumBy(a.identifierWordIndices,aElement=>aElement<0?0:1);\n\t\t\t\tlet bCount=lodash.sumBy(b.identifierWordIndices,bElement=>bElement<0?0:1);\n\t\t\t\tif(this.DEBUG){\n\t\t\t\t\tconsole.log('a',a);\n\t\t\t\t\tconsole.log('b',b);\n\t\t\t\t\tconsole.log('a.identifierWordIndices',a.identifierWordIndices);\n\t\t\t\t\tconsole.log('b.identifierWordIndices',b.identifierWordIndices);\n\t\t\t\t\tconsole.log('aCount',aCount);\n\t\t\t\t\tconsole.log('bCount',bCount);\n\t\t\t\t}\n\t\t\t\tif(aCount!==bCount)return bCount-aCount;\n\t\t\t\tif(aCount===0&&bCount===0)return 0;\n\t\t\t\taCount=0;\n\t\t\t\tbCount=0;\n\t\t\t\tfor(let i=0;i<a.identifierWordIndices.length-1;++i){\n\t\t\t\t\tfor(let j=i+1;j<a.identifierWordIndices.length;++j){\n\t\t\t\t\t\tif(a.identifierWordIndices[i]<0||a.identifierWordIndices[j]<0)continue;\n\t\t\t\t\t\tif(a.identifierWordIndices[i]<a.identifierWordIndices[j]){\n\t\t\t\t\t\t\tif(this.DEBUG){\n\t\t\t\t\t\t\t\tconsole.log('i',i);\n\t\t\t\t\t\t\t\tconsole.log('j',j);\n\t\t\t\t\t\t\t\tconsole.log('a.identifierWordIndices[i]',a.identifierWordIndices[i]);\n\t\t\t\t\t\t\t\tconsole.log('a.identifierWordIndices[j]',a.identifierWordIndices[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t++aCount;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(let i=0;i<b.identifierWordIndices.length-1;++i){\n\t\t\t\t\tfor(let j=i+1;j<b.identifierWordIndices.length;++j){\n\t\t\t\t\t\tif(b.identifierWordIndices[i]<0||b.identifierWordIndices[j]<0)continue;\n\t\t\t\t\t\tif(b.identifierWordIndices[i]<b.identifierWordIndices[j]){\n\t\t\t\t\t\t\tif(this.DEBUG){\n\t\t\t\t\t\t\t\tconsole.log('i',i);\n\t\t\t\t\t\t\t\tconsole.log('j',j);\n\t\t\t\t\t\t\t\tconsole.log('b.identifierWordIndices[i]',b.identifierWordIndices[i]);\n\t\t\t\t\t\t\t\tconsole.log('b.identifierWordIndices[j]',b.identifierWordIndices[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t++bCount;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(this.DEBUG){\n\t\t\t\t\tconsole.log('aCount',aCount);\n\t\t\t\t\tconsole.log('bCount',bCount);\n\t\t\t\t}\n\t\t\t\treturn bCount-aCount;\n\t\t\t});\n\t\t}\n\t\tif(selectedCandidates.length>=1&&selectedCandidates[0].candidate)return selectedCandidates[0].candidate;\n\t\treturn null;\n\t}\n\n\tdefaultParseSearchAreasResponse(searchAreasResponse:string){\n\t\tlet searchAreasResponseIndex=String(searchAreasResponse).indexOf('### Response:');\n\t\tif(searchAreasResponseIndex>=0)searchAreasResponseIndex+='### Response:'.length;\n\t\telse searchAreasResponseIndex=0;\n\t\treturn String(searchAreasResponse).substring(searchAreasResponseIndex).trim();\n\t}\n\n\terrorMessage(error:any){\n\t\treturn typeof error?.response?.data==='string'?error.response.data:error?.response?.data?jsan.stringify(error.response.data):typeof error?.message==='string'?error.message:error?.message?jsan.stringify(error.message):typeof error==='string'?error:jsan.stringify(error);\n\t}\n\n\tasync compareCandidates<Candidate>({\n\t\tcandidates,\n\t\tproblemDescription='',\n\t\tperformGeneration=this.defaultPerformGeneration.bind(this),\n\t\tgenerateSearchAreasInstruction=this.defaultGenerateSearchAreasInstruction.bind(this),\n\t\tparseSearchAreasResponse=this.defaultParseSearchAreasResponse.bind(this),\n\t\tconvertCandidateToDocument=this.defaultConvertCandidateToDocument.bind(this),\n\t\tcandidatesForInitialSelection=2,\n\t\tcandidatesForFinalSelection=1,\n\t\tgenerateRankingInstruction=this.defaultGenerateRankingInstruction.bind(this),\n\t\textractIdentifiersFromRationale=this.defaultExtractIdentifiersFromRationale.bind(this),\n\t\textractIdentifierFromCandidateDocument=this.defaultExtractIdentifierFromCandidateDocument.bind(this),\n\t\tcandidateIdentifierField=undefined,\n\t\tfindCandidateFromIdentifier=this.defaultFindCandidateFromIdentifier.bind(this),\n\t\tgetSummarisableSubstringIndices,\n\t\tgeneratePromptTemplate=this.defaultGeneratePromptTemplate.bind(this),\n\t\tskipRationale=false,\n\t\tparallelSummarisation=true\n\t}:AICompareCandidates.CompareArguments<Candidate>=<AICompareCandidates.CompareArguments<Candidate>>{}):Promise<AICompareCandidates.CompareCandidatesReturn<Candidate>|void>{\n\t\tif(!Array.isArray(candidates)||candidates.length<=0)throw new Error('No candidates provided');\n\t\tcandidatesForInitialSelection=lodash.toSafeInteger(candidatesForInitialSelection);\n\t\tif(candidatesForInitialSelection<=0)throw new Error('Candidates for initial selection must be a positive integer bigger than 0');\n\t\tcandidatesForFinalSelection=lodash.toSafeInteger(candidatesForFinalSelection);\n\t\tif(candidatesForFinalSelection<=0)throw new Error('Candidates for initial selection must be a positive integer bigger than 0');\n\t\tif(candidatesForInitialSelection<candidatesForFinalSelection)throw new Error('Candidates for initial selection must be equal or more than candidates for final selection');\n\t\tif(candidatesForInitialSelection>candidates.length)throw new Error('There are '+candidatesForInitialSelection+'candidates for initial selection which is more than the total number of candidates of '+candidates.length);\n\t\tif(candidatesForFinalSelection>candidates.length)throw new Error('There are '+candidatesForFinalSelection+'candidates for initial selection which is more than the total number of candidates of '+candidates.length);\n\t\tif(!candidateIdentifierField){\n\t\t\tcandidateIdentifierField=Object.keys(candidates[0] as object)[0] as keyof Candidate;\n\t\t\tif(!candidateIdentifierField)throw new Error('No candidate identifier field');\n\t\t}\n\n\t\tlet rationale='';\n\t\tlet selectedCandidates:Candidate[]=[];\n\n\t\tawait this.checkEmbedderLoaded();\n\t\tif(!this.embedder)return;\n\t\tlet candidateDocuments=candidates.map((candidate,index)=>convertCandidateToDocument({\n\t\t\tcandidate,\n\t\t\tindex\n\t\t}));\n\t\tlet vectorStore=await MemoryVectorStore.fromTexts(\n\t\t\tlodash.cloneDeep(candidateDocuments),\n\t\t\tcandidateDocuments.map((document,index)=>index),\n\t\t\tthis\n\t\t);\n\n\t\tlet searchAreasPromptTemplate=generatePromptTemplate(generateSearchAreasInstruction(problemDescription));\n\t\tif(this.DEBUG)console.log('Formatted search areas prompt: '+searchAreasPromptTemplate);\n\t\tawait this.checkTokeniserLoaded();\n\t\tif(!this.tokeniser)return;\n\t\tlet searchAreasPromptTokens=this.tokeniser.encode(searchAreasPromptTemplate);\n\t\tif(searchAreasPromptTokens.length>this.tokeniser.model_max_length)throw new Error('Search areas instruction prompt is too long for the tokeniser model');\n\n\t\tawait this.checkGeneratorLoaded();\n\t\tif(!this.generator)return;\n\t\tlet generatedText=await performGeneration({\n\t\t\tgenerator:this.generator,\n\t\t\ttokeniser:this.tokeniser,\n\t\t\tprompt:searchAreasPromptTemplate,\n\t\t\ttextGenerationConfig:{\n\t\t\t\tmax_new_tokens:this.generateSearchAreasMaxNewTokens,\n\t\t\t\ttemperature:this.generateSearchAreasTemperature,\n\t\t\t\trepetition_penalty:this.generateSearchAreasRepetitionPenalty\n\t\t\t}\n\t\t});\n\t\tif(this.DEBUG)console.log('Generated search areas response: '+generatedText);\n\t\tlet vectorSearchQuery=parseSearchAreasResponse(generatedText);\n\t\t//generally the first sentence has the greatest relevance to the actual prompt\n\t\t//if(vectorSearchQuery.includes('.'))vectorSearchQuery=vectorSearchQuery.split('.')[0].trim();\n\t\tif(this.DEBUG)console.log('Vector search query: '+vectorSearchQuery);\n\t\tlet queryResult=await vectorStore.similaritySearch(vectorSearchQuery,candidatesForInitialSelection);\n\t\tif(this.DEBUG)console.log('Vector search results: ',queryResult);\n\n\t\tlet summaries:string[]=[];\n\t\t//only bother doing summarisation if there are candidates which exceed the token count\n\t\tif(queryResult.some(result=>result.pageContent.trim().split(/\\s+/).length>this.targetSummarisedStringTokenCount)){\n\t\t\tawait this.checkSummariserLoaded();\n\t\t\tif(!this.summariser)return;\n\t\t\tif(parallelSummarisation){\n\t\t\t\tsummaries=(await Promise.allSettled(queryResult.map(async result=>{\n\t\t\t\t\tif(!result.pageContent||typeof result.pageContent!=='string')return '';\n\t\t\t\t\tif(result.pageContent.trim().split(/\\s+/).length<=this.targetSummarisedStringTokenCount)return result.pageContent;\n\t\t\t\t\tlet summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={\n\t\t\t\t\t\tstart:0,\n\t\t\t\t\t\tend:result.pageContent.length\n\t\t\t\t\t};\n\t\t\t\t\tif(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));\n\t\t\t\t\tsummarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);\n\t\t\t\t\tsummarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);\n\t\t\t\t\tif(this.DEBUG)console.log(summarisableSubstringIndices);\n\t\t\t\t\tlet summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);\n\t\t\t\t\tif(this.DEBUG)console.log(summarisableSubstring);\n\t\t\t\t\tlet contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);\n\t\t\t\t\tlet contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);\n\t\t\t\t\tlet wordsWithoutSummarisable=contentBefore.split(/\\s+/).length+contentAfter.split(/\\s+/).length;\n\t\t\t\t\tlet targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);\n\t\t\t\t\tif(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);\n\t\t\t\t\tlet summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{\n\t\t\t\t\t\tmax_length:targetSummarisedSubstringTokenCount\n\t\t\t\t\t});\n\t\t\t\t\tlet summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];\n\t\t\t\t\tif(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));\n\t\t\t\t\tlet summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;\n\t\t\t\t\tif(this.DEBUG)console.log('Summarised candidate: '+summarisedString);\n\t\t\t\t\treturn summarisedString;\n\t\t\t\t}))).filter(result=>result.status==='fulfilled'&&result.value).map(result=>(result as PromiseFulfilledResult<string>).value);\n\t\t\t}else{\n\t\t\t\tfor(let result of queryResult){\n\t\t\t\t\ttry{\n\t\t\t\t\t\tif(!result.pageContent||typeof result.pageContent!=='string')continue;\n\t\t\t\t\t\tif(result.pageContent.trim().split(/\\s+/).length<=this.targetSummarisedStringTokenCount){\n\t\t\t\t\t\t\tsummaries.push(result.pageContent);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={\n\t\t\t\t\t\t\tstart:0,\n\t\t\t\t\t\t\tend:result.pageContent.length\n\t\t\t\t\t\t};\n\t\t\t\t\t\tif(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));\n\t\t\t\t\t\tsummarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);\n\t\t\t\t\t\tsummarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);\n\t\t\t\t\t\tif(this.DEBUG)console.log(summarisableSubstringIndices);\n\t\t\t\t\t\tlet summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);\n\t\t\t\t\t\tif(this.DEBUG)console.log(summarisableSubstring);\n\t\t\t\t\t\tlet contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);\n\t\t\t\t\t\tlet contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);\n\t\t\t\t\t\tlet wordsWithoutSummarisable=contentBefore.split(/\\s+/).length+contentAfter.split(/\\s+/).length;\n\t\t\t\t\t\tlet targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);\n\t\t\t\t\t\tif(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);\n\t\t\t\t\t\tlet summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{\n\t\t\t\t\t\t\tmax_length:targetSummarisedSubstringTokenCount\n\t\t\t\t\t\t});\n\t\t\t\t\t\tlet summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];\n\t\t\t\t\t\tif(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));\n\t\t\t\t\t\tlet summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;\n\t\t\t\t\t\tif(this.DEBUG)console.log('Summarised candidate: '+summarisedString);\n\t\t\t\t\t\tsummaries.push(summarisedString);\n\t\t\t\t\t}catch(error){\n\t\t\t\t\t\tconsole.log(error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\tsummaries=queryResult.map(result=>result.pageContent);\n\t\t}\n\t\t\n\t\tlet rationaleError='';\n\n\t\tif(!skipRationale){\n\t\t\tlet rankingPromptTemplate=generatePromptTemplate(generateRankingInstruction({\n\t\t\t\tproblemDescription,\n\t\t\t\tsummaries,\n\t\t\t\tcandidatesForFinalSelection,\n\t\t\t\tcandidateIdentifierField:String(candidateIdentifierField)\n\t\t\t}));\n\t\t\tif(this.DEBUG)console.log('Formatted ranking prompt: '+rankingPromptTemplate);\n\t\t\tlet rankingPromptTokens=this.tokeniser.encode(rankingPromptTemplate);\n\t\t\tif(this.DEBUG)console.log(rankingPromptTokens.length,this.tokeniser.model_max_length);\n\t\t\tif(rankingPromptTokens.length>this.tokeniser.model_max_length)throw new Error('Ranking instruction prompt is too long for the tokeniser model');\n\t\t\ttry{\n\t\t\t\tlet ranking=await performGeneration({\n\t\t\t\t\tgenerator:this.generator,\n\t\t\t\t\ttokeniser:this.tokeniser,\n\t\t\t\t\tprompt:rankingPromptTemplate,\n\t\t\t\t\ttextGenerationConfig:{\n\t\t\t\t\t\tmax_new_tokens:this.rankingMaxNewTokens,\n\t\t\t\t\t\ttemperature:this.rankingTemperature,\n\t\t\t\t\t\trepetition_penalty:this.rankingRepetitionPenalty\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\trationale=ranking.trim().replace(/(\\*\\*)|(<\\/?s>)|(\\[.*?\\])\\s*/g, '');\n\t\t\t\tif(this.DEBUG)console.log('Generated rationale: '+rationale);\n\t\t\t\tlet rationaleResponseIndex=rationale.indexOf('### Response:');\n\t\t\t\tif(rationaleResponseIndex>=0)rationaleResponseIndex+='### Response:'.length;\n\t\t\t\telse rationaleResponseIndex=0;\n\t\t\t\trationale=rationale.substring(rationaleResponseIndex);\n\t\t\t\t//if(!rationale)throw new Error('No rationale generated');\n\t\t\t}catch(error){\n\t\t\t\tconsole.log(error);\n\t\t\t\trationaleError=this.errorMessage(error);\n\t\t\t\trationale='';\n\t\t\t}\n\t\t}\n\n\t\tif(rationale){\n\t\t\tlet identifiers=extractIdentifiersFromRationale(rationale);\n\t\t\tif(this.DEBUG)console.log('Extracted identifiers from rationale: '+identifiers);\n\t\t\tif(identifiers.length>candidatesForFinalSelection)identifiers=identifiers.slice(0,candidatesForFinalSelection);\n\t\t\tselectedCandidates=lodash.compact(identifiers.map(identifier=>findCandidateFromIdentifier({\n\t\t\t\tidentifier,\n\t\t\t\tcandidateIdentifierField,\n\t\t\t\tcandidates\n\t\t\t})));\n\t\t}\n\n\t\tif(!Array.isArray(selectedCandidates)||selectedCandidates.length<candidatesForFinalSelection){\n\t\t\tif(!Array.isArray(selectedCandidates))selectedCandidates=[];\n\t\t\tlet additionalSelectedCandidates=lodash.compact(queryResult.map(result=>{\n\t\t\t\tlet identifier=extractIdentifierFromCandidateDocument({\n\t\t\t\t\tcandidateDocument:result.pageContent,\n\t\t\t\t\tcandidateIdentifierField:String(candidateIdentifierField)\n\t\t\t\t});\n\t\t\t\tif(this.DEBUG)console.log('Extracted identifier from candidate document: '+identifier);\n\t\t\t\treturn findCandidateFromIdentifier({\n\t\t\t\t\tidentifier,\n\t\t\t\t\tcandidateIdentifierField,\n\t\t\t\t\tcandidates\n\t\t\t\t});\n\t\t\t}));\n\t\t\tselectedCandidates.splice(selectedCandidates.length,0,...additionalSelectedCandidates);\n\t\t\tselectedCandidates=lodash.uniq(selectedCandidates).slice(0,candidatesForFinalSelection);\n\t\t}\n\t\tif(this.DEBUG)console.log('Selected candidates',selectedCandidates);\n\n\t\treturn{\n\t\t\trationale,\n\t\t\tsummaries,\n\t\t\t...(rationaleError?{rationaleError}:{}),\n\t\t\tselectedCandidates\n\t\t};\n\t}\n};\n\nexport namespace AICompareCandidates{\n\texport interface LoadArguments{\n\t\tprogressCallback?:ProgressCallback;\n\t\tmodelName?:string;\n\t};\n\n\texport interface SummarisableSubstringIndices{\n\t\tstart:number;\n\t\tend:number;\n\t};\n\n\texport interface CompareArguments<Candidate>{\n\t\tcandidates:Candidate[];\n\t\tproblemDescription:string;\n\t\tperformGeneration?:(performGenerationArguments:PerformGenerationArguments)=>Promise<string>;\n\t\tgenerateSearchAreasInstruction?:(problemDescription:string)=>string;\n\t\tparseSearchAreasResponse?:(searchAreasResponse:string)=>string;\n\t\tconvertCandidateToDocument?:(convertCandidateToDocumentArguments:ConvertCandidateToDocumentArguments<Candidate>)=>string;\n\t\tcandidatesForInitialSelection?:number;\n\t\tcandidatesForFinalSelection?:number;\n\t\tgenerateRankingInstruction?:(generateRankingInstructionArguments:GenerateRankingInstructionArguments)=>string;\n\t\textractIdentifiersFromRationale?:(rationale:string)=>string[];\n\t\textractIdentifierFromCandidateDocument?:(extractIdentifierFromCandidateDocumentArguments:ExtractIdentifierFromCandidateDocumentArguments)=>string;\n\t\tcandidateIdentifierField?:keyof Candidate;\n\t\tfindCandidateFromIdentifier?:(findCandidateFromIdentifierArguments:FindCandidateFromIdentifierArguments<Candidate>)=>Candidate|null;\n\t\tgetSummarisableSubstringIndices?:(candidateDocument:string)=>SummarisableSubstringIndices;\n\t\tgeneratePromptTemplate?:(prompt:string)=>string;\n\t\tskipRationale?:boolean;\n\t\tparallelSummarisation?:boolean;\n\t};\n\n\texport interface PerformGenerationArguments{\n\t\tgenerator:TextGenerationPipeline;\n\t\ttokeniser:PreTrainedTokenizer;\n\t\tprompt:string;\n\t\ttextGenerationConfig?:Partial<TextGenerationConfig>;\n\t};\n\n\texport interface ConvertCandidateToDocumentArguments<Candidate>{\n\t\tcandidate:Candidate;\n\t\tindex:number;\n\t};\n\n\texport interface ExtractIdentifierFromCandidateDocumentArguments{\n\t\tcandidateDocument:string;\n\t\tcandidateIdentifierField:string;\n\t};\n\n\texport interface FindCandidateFromIdentifierArguments<Candidate>{\n\t\tidentifier:string;\n\t\tcandidateIdentifierField:keyof Candidate;\n\t\tcandidates:Candidate[];\n\t};\n\n\texport interface GenerateRankingInstructionArguments{\n\t\tproblemDescription:string;\n\t\tsummaries:string[];\n\t\tcandidatesForFinalSelection:number;\n\t\tcandidateIdentifierField:string;\n\t};\n\n\texport interface CompareCandidatesReturn<Candidate>{\n\t\tselectedCandidates:Candidate[],\n\t\trationale:string,\n\t\trationaleError?:string,\n\t\tsummaries:string[]\n\t};\n};\n\nexport default AICompareCandidates;"],"mappings":"itBAmBA,IAAa,EAAb,cAAyCA,EAAAA,UAAU,CAClD,IAAaC,EAAAA,IACb,MAAM,GAEN,UAAsC,KACtC,mBAAmB,gCACnB,iBAAsD,KACtD,sBAAiD,EAAE,CACnD,0BAAgD,KAChD,yBAAyB,IAAI,gBAE7B,WAAsC,KACtC,oBAAoB,6BACpB,kBAAsD,KACtD,uBAAkD,EAAE,CACpD,2BAAiD,KACjD,0BAA0B,IAAI,gBAE9B,SAAwC,KACxC,kBAAkB,2BAClB,gBAAwD,KACxD,qBAAgD,EAAE,CAClD,yBAA+C,KAC/C,wBAAwB,IAAI,gBAE5B,UAAmC,KACnC,mBAAmB,KAAK,mBACxB,iBAAmD,KACnD,sBAAiD,EAAE,CACnD,0BAAgD,KAChD,yBAAyB,IAAI,gBAE7B,gCAAgC,GAChC,+BAA+B,IAC/B,qCAAqC,IAErC,oBAAoB,GACpB,mBAAmB,IACnB,yBAAyB,IAEzB,iCAAiC,IAEjC,OACC,EAAA,IAAI,eA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IAAA,EAAe"}
package/dist/index.d.cts CHANGED
@@ -123,7 +123,8 @@ declare class AICompareCandidates extends Embeddings {
123
123
  findCandidateFromIdentifier,
124
124
  getSummarisableSubstringIndices,
125
125
  generatePromptTemplate,
126
- skipRationale
126
+ skipRationale,
127
+ parallelSummarisation
127
128
  }?: AICompareCandidates.CompareArguments<Candidate>): Promise<AICompareCandidates.CompareCandidatesReturn<Candidate> | void>;
128
129
  }
129
130
  declare namespace AICompareCandidates {
@@ -152,6 +153,7 @@ declare namespace AICompareCandidates {
152
153
  getSummarisableSubstringIndices?: (candidateDocument: string) => SummarisableSubstringIndices;
153
154
  generatePromptTemplate?: (prompt: string) => string;
154
155
  skipRationale?: boolean;
156
+ parallelSummarisation?: boolean;
155
157
  }
156
158
  interface PerformGenerationArguments {
157
159
  generator: TextGenerationPipeline;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;cAmBa,mBAAA,SAA4B,UAAA;gBAAR,iCAAA,CACpB;;EADA,SAAA,EAIF,sBAJsB,GAAA,IAAA;EAAA,kBAAA,EAAA,MAAA;EAItB,gBAAA,EAEO,OAFP,CAEe,sBAFf,CAAA,GAAA,IAAA;EAEe,qBAAA,EACH,YADG;EAAR,yBAAA,EAES,gBAFT,GAAA,IAAA;EACK,wBAAA,EAEE,eAFF;EACI,UAAA,EAGf,qBAHe,GAAA,IAAA;EACF,mBAAA,EAAA,MAAA;EAEb,iBAAA,EAEO,OAFP,CAEe,qBAFf,CAAA,GAAA,IAAA;EAEe,sBAAA,EACH,YADG;EAAR,0BAAA,EAES,gBAFT,GAAA,IAAA;EACK,yBAAA,EAEE,eAFF;EACI,QAAA,EAGlB,yBAHkB,GAAA,IAAA;EACF,iBAAA,EAAA,MAAA;EAEhB,eAAA,EAEO,OAFP,CAEe,yBAFf,CAAA,GAAA,IAAA;EAEe,oBAAA,EACH,YADG;EAAR,wBAAA,EAES,gBAFT,GAAA,IAA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AAuH;EAAA,UAAA,mCAAA,CAAA,SAAA,CAAA,CAAA;IAyG5I,SAAA,EAsQU,SAtQV;IACA,KAAA,EAAA,MAAA;EACA;EACA,UAAA,+CAAA,CAAA;IACA,iBAAA,EAAA,MAAA;IACA,wBAAA,EAAA,MAAA;EACA;EACA,UAAA,oCAAA,CAAA,SAAA,CAAA,CAAA;IACA,UAAA,EAAA,MAAA;IACA,wBAAA,EAAA,MAwQ+B,SAxQ/B;IACA,UAAA,EAwQW,SAxQX,EAAA;EACA;EACA,UAAA,mCAAA,CAAA;IACA,kBAAA,EAAA,MAAA;IACA,SAAA,EAAA,MAAA,EAAA;IACA,2BAAA,EAAA,MAAA;IACA,wBAAA,EAAA,MAAA;EACsC;EAArC,UAAA,uBAAoB,CAAA,SAAA,CAAA,CAAA;IAAqI,kBAAA,EA4QvI,SA5QuI,EAAA;IAA5C,SAAA,EAAA,MAAoB;IAA5B,cAAA,CAAA,EAAA,MAAA;IAle/D,SAAA,EAAA,MAAA,EAAA;EAAU;AAgrBnD"}
package/dist/index.d.mts CHANGED
@@ -123,7 +123,8 @@ declare class AICompareCandidates extends Embeddings {
123
123
  findCandidateFromIdentifier,
124
124
  getSummarisableSubstringIndices,
125
125
  generatePromptTemplate,
126
- skipRationale
126
+ skipRationale,
127
+ parallelSummarisation
127
128
  }?: AICompareCandidates.CompareArguments<Candidate>): Promise<AICompareCandidates.CompareCandidatesReturn<Candidate> | void>;
128
129
  }
129
130
  declare namespace AICompareCandidates {
@@ -152,6 +153,7 @@ declare namespace AICompareCandidates {
152
153
  getSummarisableSubstringIndices?: (candidateDocument: string) => SummarisableSubstringIndices;
153
154
  generatePromptTemplate?: (prompt: string) => string;
154
155
  skipRationale?: boolean;
156
+ parallelSummarisation?: boolean;
155
157
  }
156
158
  interface PerformGenerationArguments {
157
159
  generator: TextGenerationPipeline;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;cAm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EAAA,MAAA,EAAA;EAAU;AAgrBnD"}
package/dist/index.mjs CHANGED
@@ -10,5 +10,5 @@ Candidates:
10
10
  `+t.join(`
11
11
 
12
12
  `)}regexIndexOf(e,t,n){let r=e.slice(n).search(t);return r<0?r:r+n}defaultExtractIdentifierFromCandidateDocument({candidateDocument:e,candidateIdentifierField:t}={}){this.DEBUG&&console.log(e,t);let n=o.startCase(t),r=e.indexOf(n);if(r<0&&(r=e.toLowerCase().indexOf(n.toLowerCase())),this.DEBUG&&console.log(r),r>=0&&(r+=n.length),r<0&&(r=e.toLowerCase().indexOf(t.toLowerCase()),r>=0&&(r+=t.length)),this.DEBUG)console.log(r);else return``;if(r=e.indexOf(`:`,r),this.DEBUG&&console.log(r),r<0&&(r=this.regexIndexOf(e,/\s+/,r)),this.DEBUG&&console.log(r),r<0)return``;let i=e.indexOf(`
13
- `,r);return i<0&&(i=e.length),this.DEBUG&&console.log(i),e.substring(r,i).trim()}defaultExtractIdentifiersFromRationale(e){let t=/^\d+?\s*?\p{P}\s*?(.+?)\s*?(-|\.|;|\n)/gmu,n=[];for(let r;Array.isArray(r=t.exec(e));)r[1]&&n.push(r[1]);return n}defaultFindCandidateFromIdentifier({identifier:e,candidateIdentifierField:t,candidates:n}={}){(!e||typeof e!=`string`)&&(e=String(e)),console.log(`identifier`,e);let r=n.find(n=>String(n[t])===e);if(r||(r=n.find(n=>String(n[t]).toLowerCase()===e.toLowerCase()),r)||(r=n.find(n=>String(n[t]).toLowerCase().includes(e.toLowerCase())),r)||(r=n.find(n=>e.toLowerCase().includes(String(n[t]).toLowerCase())),r))return this.DEBUG&&console.log(`Candidate found based on case-sensitive match`,r[t]),r;let i=e.split(/\s+/g).filter(e=>/\w/.test(e));this.DEBUG&&console.log(`Identifier words`,i);let a=n.map(e=>({identifierWordIndices:i.map(n=>String(e[t]).indexOf(n)),candidate:e})).filter(e=>e.identifierWordIndices.some(e=>e>=0));return a.length>1&&a.sort((e,t)=>{let n=o.sumBy(e.identifierWordIndices,e=>e<0?0:1),r=o.sumBy(t.identifierWordIndices,e=>e<0?0:1);if(this.DEBUG&&(console.log(`a`,e),console.log(`b`,t),console.log(`a.identifierWordIndices`,e.identifierWordIndices),console.log(`b.identifierWordIndices`,t.identifierWordIndices),console.log(`aCount`,n),console.log(`bCount`,r)),n!==r)return r-n;if(n===0&&r===0)return 0;n=0,r=0;for(let t=0;t<e.identifierWordIndices.length-1;++t)for(let r=t+1;r<e.identifierWordIndices.length;++r)e.identifierWordIndices[t]<0||e.identifierWordIndices[r]<0||e.identifierWordIndices[t]<e.identifierWordIndices[r]&&(this.DEBUG&&(console.log(`i`,t),console.log(`j`,r),console.log(`a.identifierWordIndices[i]`,e.identifierWordIndices[t]),console.log(`a.identifierWordIndices[j]`,e.identifierWordIndices[r])),++n);for(let e=0;e<t.identifierWordIndices.length-1;++e)for(let n=e+1;n<t.identifierWordIndices.length;++n)t.identifierWordIndices[e]<0||t.identifierWordIndices[n]<0||t.identifierWordIndices[e]<t.identifierWordIndices[n]&&(this.DEBUG&&(console.log(`i`,e),console.log(`j`,n),console.log(`b.identifierWordIndices[i]`,t.identifierWordIndices[e]),console.log(`b.identifierWordIndices[j]`,t.identifierWordIndices[n])),++r);return this.DEBUG&&(console.log(`aCount`,n),console.log(`bCount`,r)),r-n}),a.length>=1&&a[0].candidate?a[0].candidate:null}defaultParseSearchAreasResponse(e){let t=String(e).indexOf(`### Response:`);return t>=0?t+=13:t=0,String(e).substring(t).trim()}errorMessage(e){return typeof e?.response?.data==`string`?e.response.data:e?.response?.data?s.stringify(e.response.data):typeof e?.message==`string`?e.message:e?.message?s.stringify(e.message):typeof e==`string`?e:s.stringify(e)}async compareCandidates({candidates:e,problemDescription:t=``,performGeneration:n=this.defaultPerformGeneration.bind(this),generateSearchAreasInstruction:r=this.defaultGenerateSearchAreasInstruction.bind(this),parseSearchAreasResponse:a=this.defaultParseSearchAreasResponse.bind(this),convertCandidateToDocument:s=this.defaultConvertCandidateToDocument.bind(this),candidatesForInitialSelection:c=2,candidatesForFinalSelection:l=1,generateRankingInstruction:u=this.defaultGenerateRankingInstruction.bind(this),extractIdentifiersFromRationale:d=this.defaultExtractIdentifiersFromRationale.bind(this),extractIdentifierFromCandidateDocument:f=this.defaultExtractIdentifierFromCandidateDocument.bind(this),candidateIdentifierField:p=void 0,findCandidateFromIdentifier:m=this.defaultFindCandidateFromIdentifier.bind(this),getSummarisableSubstringIndices:h,generatePromptTemplate:g=this.defaultGeneratePromptTemplate.bind(this),skipRationale:_=!1}={}){if(!Array.isArray(e)||e.length<=0)throw Error(`No candidates provided`);if(c=o.toSafeInteger(c),c<=0||(l=o.toSafeInteger(l),l<=0))throw Error(`Candidates for initial selection must be a positive integer bigger than 0`);if(c<l)throw Error(`Candidates for initial selection must be equal or more than candidates for final selection`);if(c>e.length)throw Error(`There are `+c+`candidates for initial selection which is more than the total number of candidates of `+e.length);if(l>e.length)throw Error(`There are `+l+`candidates for initial selection which is more than the total number of candidates of `+e.length);if(!p&&(p=Object.keys(e[0])[0],!p))throw Error(`No candidate identifier field`);let v=``,y=[];if(await this.checkEmbedderLoaded(),!this.embedder)return;let b=e.map((e,t)=>s({candidate:e,index:t})),x=await i.fromTexts(o.cloneDeep(b),b.map((e,t)=>t),this),S=g(r(t));if(this.DEBUG&&console.log(`Formatted search areas prompt: `+S),await this.checkTokeniserLoaded(),!this.tokeniser)return;if(this.tokeniser.encode(S).length>this.tokeniser.model_max_length)throw Error(`Search areas instruction prompt is too long for the tokeniser model`);if(await this.checkGeneratorLoaded(),!this.generator)return;let C=await n({generator:this.generator,tokeniser:this.tokeniser,prompt:S,textGenerationConfig:{max_new_tokens:this.generateSearchAreasMaxNewTokens,temperature:this.generateSearchAreasTemperature,repetition_penalty:this.generateSearchAreasRepetitionPenalty}});this.DEBUG&&console.log(`Generated search areas response: `+C);let w=a(C);this.DEBUG&&console.log(`Vector search query: `+w);let T=await x.similaritySearch(w,c);this.DEBUG&&console.log(`Vector search results: `,T);let E=[];if(T.some(e=>e.pageContent.trim().split(/\s+/).length>this.targetSummarisedStringTokenCount)){if(await this.checkSummariserLoaded(),!this.summariser)return;E=(await Promise.allSettled(T.map(async e=>{if(!e.pageContent||typeof e.pageContent!=`string`)return``;if(e.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount)return e.pageContent;let t={start:0,end:e.pageContent.length};h&&Object.assign(t,h(e.pageContent)),t.start=o.clamp(o.toSafeInteger(t.start),0,e.pageContent.length),t.end=o.clamp(o.toSafeInteger(t.end),0,e.pageContent.length),this.DEBUG&&console.log(t);let n=e.pageContent.substring(t.start,t.end);this.DEBUG&&console.log(n);let r=e.pageContent.substring(0,t.start),i=e.pageContent.substring(t.end),a=r.split(/\s+/).length+i.split(/\s+/).length,s=Math.max(1,this.targetSummarisedStringTokenCount-a);this.DEBUG&&console.log(a,s);let c=await this.summariser?.(n,{max_length:s}),l=Array.isArray(c?.[0])?c?.[0]?.[0]:c?.[0];this.DEBUG&&console.log(c,l,l?.summary_text??``,(l?.summary_text??``).split(/\s+/).slice(0,s).join(` `));let u=r+(l?.summary_text??``).split(/\s+/).slice(0,s).join(` `).trim()+i;return this.DEBUG&&console.log(`Summarised candidate: `+u),u}))).filter(e=>e.status===`fulfilled`&&e.value).map(e=>e.value)}else E=T.map(e=>e.pageContent);let D=``;if(!_){let e=g(u({problemDescription:t,summaries:E,candidatesForFinalSelection:l,candidateIdentifierField:String(p)}));this.DEBUG&&console.log(`Formatted ranking prompt: `+e);let r=this.tokeniser.encode(e);if(this.DEBUG&&console.log(r.length,this.tokeniser.model_max_length),r.length>this.tokeniser.model_max_length)throw Error(`Ranking instruction prompt is too long for the tokeniser model`);try{v=(await n({generator:this.generator,tokeniser:this.tokeniser,prompt:e,textGenerationConfig:{max_new_tokens:this.rankingMaxNewTokens,temperature:this.rankingTemperature,repetition_penalty:this.rankingRepetitionPenalty}})).trim().replace(/(\*\*)|(<\/?s>)|(\[.*?\])\s*/g,``),this.DEBUG&&console.log(`Generated rationale: `+v);let t=v.indexOf(`### Response:`);t>=0?t+=13:t=0,v=v.substring(t)}catch(e){console.log(e),D=this.errorMessage(e),v=``}}if(v){let t=d(v);this.DEBUG&&console.log(`Extracted identifiers from rationale: `+t),t.length>l&&(t=t.slice(0,l)),y=o.compact(t.map(t=>m({identifier:t,candidateIdentifierField:p,candidates:e})))}if(!Array.isArray(y)||y.length<l){Array.isArray(y)||(y=[]);let t=o.compact(T.map(t=>{let n=f({candidateDocument:t.pageContent,candidateIdentifierField:String(p)});return this.DEBUG&&console.log(`Extracted identifier from candidate document: `+n),m({identifier:n,candidateIdentifierField:p,candidates:e})}));y.splice(y.length,0,...t),y=o.uniq(y).slice(0,l)}return this.DEBUG&&console.log(`Selected candidates`,y),{rationale:v,summaries:E,...D?{rationaleError:D}:{},selectedCandidates:y}}};(function(e){})(c||={});var l=c;export{c as AICompareCandidates,l as default};
13
+ `,r);return i<0&&(i=e.length),this.DEBUG&&console.log(i),e.substring(r,i).trim()}defaultExtractIdentifiersFromRationale(e){let t=/^\d+?\s*?\p{P}\s*?(.+?)\s*?(-|\.|;|\n)/gmu,n=[];for(let r;Array.isArray(r=t.exec(e));)r[1]&&n.push(r[1]);return n}defaultFindCandidateFromIdentifier({identifier:e,candidateIdentifierField:t,candidates:n}={}){(!e||typeof e!=`string`)&&(e=String(e)),console.log(`identifier`,e);let r=n.find(n=>String(n[t])===e);if(r||(r=n.find(n=>String(n[t]).toLowerCase()===e.toLowerCase()),r)||(r=n.find(n=>String(n[t]).toLowerCase().includes(e.toLowerCase())),r)||(r=n.find(n=>e.toLowerCase().includes(String(n[t]).toLowerCase())),r))return this.DEBUG&&console.log(`Candidate found based on case-sensitive match`,r[t]),r;let i=e.split(/\s+/g).filter(e=>/\w/.test(e));this.DEBUG&&console.log(`Identifier words`,i);let a=n.map(e=>({identifierWordIndices:i.map(n=>String(e[t]).indexOf(n)),candidate:e})).filter(e=>e.identifierWordIndices.some(e=>e>=0));return a.length>1&&a.sort((e,t)=>{let n=o.sumBy(e.identifierWordIndices,e=>e<0?0:1),r=o.sumBy(t.identifierWordIndices,e=>e<0?0:1);if(this.DEBUG&&(console.log(`a`,e),console.log(`b`,t),console.log(`a.identifierWordIndices`,e.identifierWordIndices),console.log(`b.identifierWordIndices`,t.identifierWordIndices),console.log(`aCount`,n),console.log(`bCount`,r)),n!==r)return r-n;if(n===0&&r===0)return 0;n=0,r=0;for(let t=0;t<e.identifierWordIndices.length-1;++t)for(let r=t+1;r<e.identifierWordIndices.length;++r)e.identifierWordIndices[t]<0||e.identifierWordIndices[r]<0||e.identifierWordIndices[t]<e.identifierWordIndices[r]&&(this.DEBUG&&(console.log(`i`,t),console.log(`j`,r),console.log(`a.identifierWordIndices[i]`,e.identifierWordIndices[t]),console.log(`a.identifierWordIndices[j]`,e.identifierWordIndices[r])),++n);for(let e=0;e<t.identifierWordIndices.length-1;++e)for(let n=e+1;n<t.identifierWordIndices.length;++n)t.identifierWordIndices[e]<0||t.identifierWordIndices[n]<0||t.identifierWordIndices[e]<t.identifierWordIndices[n]&&(this.DEBUG&&(console.log(`i`,e),console.log(`j`,n),console.log(`b.identifierWordIndices[i]`,t.identifierWordIndices[e]),console.log(`b.identifierWordIndices[j]`,t.identifierWordIndices[n])),++r);return this.DEBUG&&(console.log(`aCount`,n),console.log(`bCount`,r)),r-n}),a.length>=1&&a[0].candidate?a[0].candidate:null}defaultParseSearchAreasResponse(e){let t=String(e).indexOf(`### Response:`);return t>=0?t+=13:t=0,String(e).substring(t).trim()}errorMessage(e){return typeof e?.response?.data==`string`?e.response.data:e?.response?.data?s.stringify(e.response.data):typeof e?.message==`string`?e.message:e?.message?s.stringify(e.message):typeof e==`string`?e:s.stringify(e)}async compareCandidates({candidates:e,problemDescription:t=``,performGeneration:n=this.defaultPerformGeneration.bind(this),generateSearchAreasInstruction:r=this.defaultGenerateSearchAreasInstruction.bind(this),parseSearchAreasResponse:a=this.defaultParseSearchAreasResponse.bind(this),convertCandidateToDocument:s=this.defaultConvertCandidateToDocument.bind(this),candidatesForInitialSelection:c=2,candidatesForFinalSelection:l=1,generateRankingInstruction:u=this.defaultGenerateRankingInstruction.bind(this),extractIdentifiersFromRationale:d=this.defaultExtractIdentifiersFromRationale.bind(this),extractIdentifierFromCandidateDocument:f=this.defaultExtractIdentifierFromCandidateDocument.bind(this),candidateIdentifierField:p=void 0,findCandidateFromIdentifier:m=this.defaultFindCandidateFromIdentifier.bind(this),getSummarisableSubstringIndices:h,generatePromptTemplate:g=this.defaultGeneratePromptTemplate.bind(this),skipRationale:_=!1,parallelSummarisation:v=!0}={}){if(!Array.isArray(e)||e.length<=0)throw Error(`No candidates provided`);if(c=o.toSafeInteger(c),c<=0||(l=o.toSafeInteger(l),l<=0))throw Error(`Candidates for initial selection must be a positive integer bigger than 0`);if(c<l)throw Error(`Candidates for initial selection must be equal or more than candidates for final selection`);if(c>e.length)throw Error(`There are `+c+`candidates for initial selection which is more than the total number of candidates of `+e.length);if(l>e.length)throw Error(`There are `+l+`candidates for initial selection which is more than the total number of candidates of `+e.length);if(!p&&(p=Object.keys(e[0])[0],!p))throw Error(`No candidate identifier field`);let y=``,b=[];if(await this.checkEmbedderLoaded(),!this.embedder)return;let x=e.map((e,t)=>s({candidate:e,index:t})),S=await i.fromTexts(o.cloneDeep(x),x.map((e,t)=>t),this),C=g(r(t));if(this.DEBUG&&console.log(`Formatted search areas prompt: `+C),await this.checkTokeniserLoaded(),!this.tokeniser)return;if(this.tokeniser.encode(C).length>this.tokeniser.model_max_length)throw Error(`Search areas instruction prompt is too long for the tokeniser model`);if(await this.checkGeneratorLoaded(),!this.generator)return;let w=await n({generator:this.generator,tokeniser:this.tokeniser,prompt:C,textGenerationConfig:{max_new_tokens:this.generateSearchAreasMaxNewTokens,temperature:this.generateSearchAreasTemperature,repetition_penalty:this.generateSearchAreasRepetitionPenalty}});this.DEBUG&&console.log(`Generated search areas response: `+w);let T=a(w);this.DEBUG&&console.log(`Vector search query: `+T);let E=await S.similaritySearch(T,c);this.DEBUG&&console.log(`Vector search results: `,E);let D=[];if(E.some(e=>e.pageContent.trim().split(/\s+/).length>this.targetSummarisedStringTokenCount)){if(await this.checkSummariserLoaded(),!this.summariser)return;if(v)D=(await Promise.allSettled(E.map(async e=>{if(!e.pageContent||typeof e.pageContent!=`string`)return``;if(e.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount)return e.pageContent;let t={start:0,end:e.pageContent.length};h&&Object.assign(t,h(e.pageContent)),t.start=o.clamp(o.toSafeInteger(t.start),0,e.pageContent.length),t.end=o.clamp(o.toSafeInteger(t.end),0,e.pageContent.length),this.DEBUG&&console.log(t);let n=e.pageContent.substring(t.start,t.end);this.DEBUG&&console.log(n);let r=e.pageContent.substring(0,t.start),i=e.pageContent.substring(t.end),a=r.split(/\s+/).length+i.split(/\s+/).length,s=Math.max(1,this.targetSummarisedStringTokenCount-a);this.DEBUG&&console.log(a,s);let c=await this.summariser?.(n,{max_length:s}),l=Array.isArray(c?.[0])?c?.[0]?.[0]:c?.[0];this.DEBUG&&console.log(c,l,l?.summary_text??``,(l?.summary_text??``).split(/\s+/).slice(0,s).join(` `));let u=r+(l?.summary_text??``).split(/\s+/).slice(0,s).join(` `).trim()+i;return this.DEBUG&&console.log(`Summarised candidate: `+u),u}))).filter(e=>e.status===`fulfilled`&&e.value).map(e=>e.value);else for(let e of E)try{if(!e.pageContent||typeof e.pageContent!=`string`)continue;if(e.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount){D.push(e.pageContent);continue}let t={start:0,end:e.pageContent.length};h&&Object.assign(t,h(e.pageContent)),t.start=o.clamp(o.toSafeInteger(t.start),0,e.pageContent.length),t.end=o.clamp(o.toSafeInteger(t.end),0,e.pageContent.length),this.DEBUG&&console.log(t);let n=e.pageContent.substring(t.start,t.end);this.DEBUG&&console.log(n);let r=e.pageContent.substring(0,t.start),i=e.pageContent.substring(t.end),a=r.split(/\s+/).length+i.split(/\s+/).length,s=Math.max(1,this.targetSummarisedStringTokenCount-a);this.DEBUG&&console.log(a,s);let c=await this.summariser?.(n,{max_length:s}),l=Array.isArray(c?.[0])?c?.[0]?.[0]:c?.[0];this.DEBUG&&console.log(c,l,l?.summary_text??``,(l?.summary_text??``).split(/\s+/).slice(0,s).join(` `));let u=r+(l?.summary_text??``).split(/\s+/).slice(0,s).join(` `).trim()+i;this.DEBUG&&console.log(`Summarised candidate: `+u),D.push(u)}catch(e){console.log(e)}}else D=E.map(e=>e.pageContent);let O=``;if(!_){let e=g(u({problemDescription:t,summaries:D,candidatesForFinalSelection:l,candidateIdentifierField:String(p)}));this.DEBUG&&console.log(`Formatted ranking prompt: `+e);let r=this.tokeniser.encode(e);if(this.DEBUG&&console.log(r.length,this.tokeniser.model_max_length),r.length>this.tokeniser.model_max_length)throw Error(`Ranking instruction prompt is too long for the tokeniser model`);try{y=(await n({generator:this.generator,tokeniser:this.tokeniser,prompt:e,textGenerationConfig:{max_new_tokens:this.rankingMaxNewTokens,temperature:this.rankingTemperature,repetition_penalty:this.rankingRepetitionPenalty}})).trim().replace(/(\*\*)|(<\/?s>)|(\[.*?\])\s*/g,``),this.DEBUG&&console.log(`Generated rationale: `+y);let t=y.indexOf(`### Response:`);t>=0?t+=13:t=0,y=y.substring(t)}catch(e){console.log(e),O=this.errorMessage(e),y=``}}if(y){let t=d(y);this.DEBUG&&console.log(`Extracted identifiers from rationale: `+t),t.length>l&&(t=t.slice(0,l)),b=o.compact(t.map(t=>m({identifier:t,candidateIdentifierField:p,candidates:e})))}if(!Array.isArray(b)||b.length<l){Array.isArray(b)||(b=[]);let t=o.compact(E.map(t=>{let n=f({candidateDocument:t.pageContent,candidateIdentifierField:String(p)});return this.DEBUG&&console.log(`Extracted identifier from candidate document: `+n),m({identifier:n,candidateIdentifierField:p,candidates:e})}));b.splice(b.length,0,...t),b=o.uniq(b).slice(0,l)}return this.DEBUG&&console.log(`Selected candidates`,b),{rationale:y,summaries:D,...O?{rationaleError:O}:{},selectedCandidates:b}}};(function(e){})(c||={});var l=c;export{c as AICompareCandidates,l as default};
14
14
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["matches:string[]","match:RegExpExecArray|null","selectedCandidates:Candidate[]","summaries:string[]","summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices"],"sources":["../src/index.ts"],"sourcesContent":["import{\n\tenv,\n\tpipeline,\n\tAutoTokenizer,\n\tTextGenerationPipeline,\n\tProgressInfo,\n\tProgressCallback,\n\tSummarizationPipeline,\n\tFeatureExtractionPipeline,\n\tPreTrainedTokenizer,\n\tTextGenerationConfig,\n\tTextGenerationSingle,\n\tTextStreamer\n}from '@sroussey/transformers';\nimport {MemoryVectorStore} from '@langchain/classic/vectorstores/memory';\nimport {Embeddings} from '@langchain/core/embeddings';\nimport lodash from 'lodash';\nimport jsan from 'jsan';\n\nexport class AICompareCandidates extends Embeddings{\n\treadonly env=env;\n\tDEBUG=true;\n\n\tgenerator:TextGenerationPipeline|null=null;\n\tgeneratorModelName='Xenova/Phi-3-mini-4k-instruct';\n\tgeneratorPromise:Promise<TextGenerationPipeline>|null=null;\n\tgeneratorProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tgeneratorProgressCallback:ProgressCallback|null=null;\n\tgeneratorAbortController=new AbortController();\n\n\tsummariser:SummarizationPipeline|null=null;\n\tsummariserModelName='Xenova/distilbart-cnn-12-6';\n\tsummariserPromise:Promise<SummarizationPipeline>|null=null;\n\tsummariserProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tsummariserProgressCallback:ProgressCallback|null=null;\n\tsummariserAbortController=new AbortController();\n\n\tembedder:FeatureExtractionPipeline|null=null;\n\tembedderModelName='Xenova/all-MiniLM-L12-v2';\n\tembedderPromise:Promise<FeatureExtractionPipeline>|null=null;\n\tembedderProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tembedderProgressCallback:ProgressCallback|null=null;\n\tembedderAbortController=new AbortController();\n\n\ttokeniser:PreTrainedTokenizer|null=null;\n\ttokeniserModelName=this.generatorModelName;\n\ttokeniserPromise:Promise<PreTrainedTokenizer>|null=null;\n\ttokeniserProgressInfo:ProgressInfo=<ProgressInfo>{};\n\ttokeniserProgressCallback:ProgressCallback|null=null;\n\ttokeniserAbortController=new AbortController();\n\n\tgenerateSearchAreasMaxNewTokens=64;\n\tgenerateSearchAreasTemperature=0.35;\n\tgenerateSearchAreasRepetitionPenalty=1.5;\n\n\trankingMaxNewTokens=64;\n\trankingTemperature=0.35;\n\trankingRepetitionPenalty=1.5;\n\n\ttargetSummarisedStringTokenCount=300;\n\n\tstatic{\n\t\tenv.localModelPath='';\n\t\tenv.allowRemoteModels=true;\n\t\tenv.allowLocalModels=false;\n\t}\n\n\tconstructor(){\n\t\tsuper({});\n\t}\n\t\n\tasync loadGenerator({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.generatorModelName=modelName;\n\t\tif(!this.generatorModelName)throw new Error('Invalid generator model name');\n\t\tif(progressCallback)this.generatorProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.generatorPromise=pipeline('text-generation',this.generatorModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.generatorProgressInfo,progressInfo);\n\t\t\t\treturn this.generatorProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.generatorAbortController.signal\n\t\t});\n\t\tthis.generator=await this.generatorPromise;\n\t\treturn this.generator;\n\t}\n\n\tasync checkGeneratorLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.generatorPromise)this.loadGenerator({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.generator){\n\t\t\ttry{\n\t\t\t\tawait this.generatorPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.generatorPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.generator){\n\t\t\tthis.generatorPromise=null;\n\t\t\tthrow new Error('Unable to load generator');\n\t\t}\n\t}\n\n\tasync abortLoadGenerator(reason?:any){\n\t\tthis.generatorAbortController.abort(reason);\n\t\tthis.generatorAbortController=new AbortController();\n\t}\n\n\tasync loadSummariser({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.summariserModelName=modelName;\n\t\tif(!this.summariserModelName)throw new Error('Invalid summariser model name');\n\t\tif(progressCallback)this.summariserProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.summariserPromise=pipeline('summarization',this.summariserModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.summariserProgressInfo,progressInfo);\n\t\t\t\treturn this.summariserProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.summariserAbortController.signal\n\t\t});\n\t\tthis.summariser=await this.summariserPromise;\n\t\treturn this.summariser;\n\t}\n\n\tasync checkSummariserLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.summariserPromise)this.loadSummariser({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.summariser){\n\t\t\ttry{\n\t\t\t\tawait this.summariserPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.summariserPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.summariser){\n\t\t\tthis.summariserPromise=null;\n\t\t\tthrow new Error('Unable to load summariser');\n\t\t}\n\t}\n\n\tasync abortLoadSummariser(){\n\t\tthis.summariserAbortController.abort();\n\t\tthis.summariserAbortController=new AbortController();\n\t}\n\n\tasync loadEmbedder({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.embedderModelName=modelName;\n\t\tif(!this.embedderModelName)throw new Error('Invalid embedder model name');\n\t\tif(progressCallback)this.embedderProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.embedderPromise=pipeline('feature-extraction',this.embedderModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.embedderProgressInfo,progressInfo);\n\t\t\t\treturn this.embedderProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.embedderAbortController.signal\n\t\t});\n\t\tthis.embedder=await this.embedderPromise;\n\t\treturn this.embedder;\n\t}\n\n\tasync checkEmbedderLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.embedderPromise)this.loadEmbedder({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.embedder){\n\t\t\ttry{\n\t\t\t\tawait this.embedderPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.embedderPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.embedder){\n\t\t\tthis.embedderPromise=null;\n\t\t\tthrow new Error('Unable to load embedder');\n\t\t}\n\t}\n\n\tasync abortLoadEmbedder(){\n\t\tthis.embedderAbortController.abort();\n\t\tthis.embedderAbortController=new AbortController();\n\t}\n\n\tasync loadTokeniser({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.tokeniserModelName=modelName;\n\t\tif(!this.tokeniserModelName)throw new Error('Invalid tokeniser model name');\n\t\tif(progressCallback)this.tokeniserProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.tokeniserPromise=AutoTokenizer.from_pretrained(this.tokeniserModelName,{\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.tokeniserProgressInfo,progressInfo);\n\t\t\t\treturn this.tokeniserProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.tokeniserAbortController.signal\n\t\t});\n\t\tthis.tokeniser=await this.tokeniserPromise;\n\t\treturn this.tokeniser;\n\t}\n\n\tasync checkTokeniserLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.tokeniserPromise)this.loadTokeniser({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.tokeniser){\n\t\t\ttry{\n\t\t\t\tawait this.tokeniserPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.tokeniserPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.tokeniser){\n\t\t\tthis.tokeniserPromise=null;\n\t\t\tthrow new Error('Unable to load tokeniser');\n\t\t}\n\t}\n\n\tasync abortLoadTokeniser(){\n\t\tthis.tokeniserAbortController.abort();\n\t\tthis.tokeniserAbortController=new AbortController();\n\t}\n\n\tasync embedQuery(text:string):Promise<number[]>{\n\t\tawait this.checkEmbedderLoaded();\n\t\tif(typeof this.embedder==='function')return Array.from((await this.embedder(text,{\n\t\t\tpooling:'mean',\n\t\t\tnormalize:true\n\t\t}))?.data);\n\t\treturn [];\n\t}\n\n\tasync embedDocuments(texts:string[]):Promise<number[][]>{\n\t\treturn Promise.all(texts.map(text=>this.embedQuery(text)));\n\t}\n\n\tdefaultGeneratePromptTemplate(prompt:string){\n\t\treturn prompt;\n\t}\n\n\tasync defaultPerformGeneration({\n\t\tgenerator,\n\t\ttokeniser,\n\t\tprompt='',\n\t\ttextGenerationConfig={}\n\t}:AICompareCandidates.PerformGenerationArguments=<AICompareCandidates.PerformGenerationArguments>{}){\n\t\tlet errors='';\n\t\tif(!generator)errors+='No generator provided.';\n\t\tif(!tokeniser)errors+=(errors?'\\n':'')+'No tokeniser provided.';\n\t\tif(typeof prompt!=='string'||!prompt)errors+=(errors?'\\n':'')+'No valid prompt provided.';\n\t\tif(errors)throw new Error(errors);\n\t\tlet messages=[{\n\t\t\trole:'user',\n\t\t\tcontent:prompt\n\t\t}];\n\t\tlet streamer=new TextStreamer(tokeniser,{\n\t\t\tskip_prompt:true\n\t\t});\n\t\tif(!textGenerationConfig.pad_token_id)textGenerationConfig.pad_token_id=tokeniser.pad_token_id??tokeniser.sep_token_id??0;\n\t\tif(!textGenerationConfig.eos_token_id)textGenerationConfig.eos_token_id=tokeniser.sep_token_id??2;\n\t\tlet output=await generator(messages,textGenerationConfig);\n\t\tif(this.DEBUG)console.log(output);\n\t\tlet outputObject=Array.isArray(output?.[0])?output?.[0]?.[0]:output?.[0];\n\t\tif(!outputObject.generated_text)throw new Error('No generated text');\n\t\tif(typeof outputObject.generated_text==='string')return outputObject.generated_text;\n\t\tlet content=outputObject.generated_text?.at(-1)?.content;\n\t\tif(typeof content!=='string'||!content)throw new Error('No content in generated text');\n\t\treturn content;\n\t}\n\n\tdefaultGenerateSearchAreasInstruction(problemDescription:string){\n\t\treturn 'List the relevant subject areas for the following issues. Limit your response to 100 words.\\nIssues: \"'+problemDescription+'\"';\n\t}\n\n\tdefaultConvertCandidateToDocument<Candidate>({\n\t\tcandidate,\n\t\tindex\n\t}:AICompareCandidates.ConvertCandidateToDocumentArguments<Candidate>=<AICompareCandidates.ConvertCandidateToDocumentArguments<Candidate>>{}){\n\t\tlet document='Start of Candidate #'+index;\n\t\tfor(let i in candidate)document+='\\n'+lodash.startCase(i)+': '+(typeof candidate[i]==='object'?jsan.stringify(candidate[i]):String(candidate[i]));\n\t\tdocument+='\\nEnd of Candidate #'+index;\n\t\treturn document;\n\t}\n\n\tdefaultGenerateRankingInstruction({\n\t\tproblemDescription,\n\t\tsummaries,\n\t\tcandidatesForFinalSelection,\n\t\tcandidateIdentifierField\n\t}:AICompareCandidates.GenerateRankingInstructionArguments=<AICompareCandidates.GenerateRankingInstructionArguments>{}){\n\t\treturn 'Rank only the top '+candidatesForFinalSelection+' candidates by connecting them to \"'+problemDescription+'\" stating # followed by the candidate number and the full '+lodash.startCase(candidateIdentifierField)+' followed by a 15-word explanation for each ranking. Stop generating text immediately thereafter.\\n\\nCandidates:\\n\\n'+summaries.join('\\n\\n');\n\t}\n\n\tregexIndexOf(text:string,regex:RegExp,startIndex:number){\n \tlet indexInSuffix=text.slice(startIndex).search(regex);\n \treturn indexInSuffix<0?indexInSuffix:indexInSuffix+startIndex;\n\t}\n\n\tdefaultExtractIdentifierFromCandidateDocument({\n\t\tcandidateDocument,\n\t\tcandidateIdentifierField\n\t}:AICompareCandidates.ExtractIdentifierFromCandidateDocumentArguments=<AICompareCandidates.ExtractIdentifierFromCandidateDocumentArguments>{}){\n\t\tif(this.DEBUG)console.log(candidateDocument,candidateIdentifierField);\n\t\tlet startCase=lodash.startCase(candidateIdentifierField);\n\t\tlet startIndex=candidateDocument.indexOf(startCase);\n\t\tif(startIndex<0)startIndex=candidateDocument.toLowerCase().indexOf(startCase.toLowerCase());\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex>=0)startIndex+=startCase.length;\n\t\tif(startIndex<0){\n\t\t\tstartIndex=candidateDocument.toLowerCase().indexOf(candidateIdentifierField.toLowerCase());\n\t\t\tif(startIndex>=0)startIndex+=candidateIdentifierField.length;\n\t\t}\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\telse return '';\n\t\tstartIndex=candidateDocument.indexOf(':',startIndex);\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex<0)startIndex=this.regexIndexOf(candidateDocument,/\\s+/,startIndex);\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex<0)return '';\n\t\tlet endIndex=candidateDocument.indexOf('\\n',startIndex);\n\t\tif(endIndex<0)endIndex=candidateDocument.length;\n\t\tif(this.DEBUG)console.log(endIndex);\n\t\treturn candidateDocument.substring(startIndex,endIndex).trim();\n\t}\n\n\tdefaultExtractIdentifiersFromRationale(rationale:string){\n\t\tlet regex=/^\\d+?\\s*?\\p{P}\\s*?(.+?)\\s*?(-|\\.|;|\\n)/gmu;\n\t\tlet matches:string[]=[];\n\t\tfor(let match:RegExpExecArray|null;Array.isArray(match=regex.exec(rationale));)if(match[1])matches.push(match[1]);\n\t\treturn matches;\n\t}\n\n\tdefaultFindCandidateFromIdentifier<Candidate>({\n\t\tidentifier,\n\t\tcandidateIdentifierField,\n\t\tcandidates\n\t}:AICompareCandidates.FindCandidateFromIdentifierArguments<Candidate>=<AICompareCandidates.FindCandidateFromIdentifierArguments<Candidate>>{}){\n\t\tif(!identifier||typeof identifier!=='string')identifier=String(identifier);\n\t\tconsole.log('identifier',identifier);\n\t\tlet selectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField])===identifier);\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField]).toLowerCase()===identifier.toLowerCase());\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField]).toLowerCase().includes(identifier.toLowerCase()));\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>identifier.toLowerCase().includes(String(candidate[candidateIdentifierField]).toLowerCase()));\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\t//split by space and find highest number of matches (tie break if it is in same order)\n\t\tlet identifierWords=identifier.split(/\\s+/g).filter(identifierWord=>/\\w/.test(identifierWord));\n\t\tif(this.DEBUG)console.log('Identifier words',identifierWords);\n\t\tlet selectedCandidates=candidates.map(candidate=>({\n\t\t\tidentifierWordIndices:identifierWords.map(identifierWord=>String(candidate[candidateIdentifierField]).indexOf(identifierWord)),\n\t\t\tcandidate\n\t\t})).filter(candidate=>candidate.identifierWordIndices.some(index=>index>=0));\n\t\tif(selectedCandidates.length>1){\n\t\t\tselectedCandidates.sort((a,b)=>{\n\t\t\t\tlet aCount=lodash.sumBy(a.identifierWordIndices,aElement=>aElement<0?0:1);\n\t\t\t\tlet bCount=lodash.sumBy(b.identifierWordIndices,bElement=>bElement<0?0:1);\n\t\t\t\tif(this.DEBUG){\n\t\t\t\t\tconsole.log('a',a);\n\t\t\t\t\tconsole.log('b',b);\n\t\t\t\t\tconsole.log('a.identifierWordIndices',a.identifierWordIndices);\n\t\t\t\t\tconsole.log('b.identifierWordIndices',b.identifierWordIndices);\n\t\t\t\t\tconsole.log('aCount',aCount);\n\t\t\t\t\tconsole.log('bCount',bCount);\n\t\t\t\t}\n\t\t\t\tif(aCount!==bCount)return bCount-aCount;\n\t\t\t\tif(aCount===0&&bCount===0)return 0;\n\t\t\t\taCount=0;\n\t\t\t\tbCount=0;\n\t\t\t\tfor(let i=0;i<a.identifierWordIndices.length-1;++i){\n\t\t\t\t\tfor(let j=i+1;j<a.identifierWordIndices.length;++j){\n\t\t\t\t\t\tif(a.identifierWordIndices[i]<0||a.identifierWordIndices[j]<0)continue;\n\t\t\t\t\t\tif(a.identifierWordIndices[i]<a.identifierWordIndices[j]){\n\t\t\t\t\t\t\tif(this.DEBUG){\n\t\t\t\t\t\t\t\tconsole.log('i',i);\n\t\t\t\t\t\t\t\tconsole.log('j',j);\n\t\t\t\t\t\t\t\tconsole.log('a.identifierWordIndices[i]',a.identifierWordIndices[i]);\n\t\t\t\t\t\t\t\tconsole.log('a.identifierWordIndices[j]',a.identifierWordIndices[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t++aCount;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(let i=0;i<b.identifierWordIndices.length-1;++i){\n\t\t\t\t\tfor(let j=i+1;j<b.identifierWordIndices.length;++j){\n\t\t\t\t\t\tif(b.identifierWordIndices[i]<0||b.identifierWordIndices[j]<0)continue;\n\t\t\t\t\t\tif(b.identifierWordIndices[i]<b.identifierWordIndices[j]){\n\t\t\t\t\t\t\tif(this.DEBUG){\n\t\t\t\t\t\t\t\tconsole.log('i',i);\n\t\t\t\t\t\t\t\tconsole.log('j',j);\n\t\t\t\t\t\t\t\tconsole.log('b.identifierWordIndices[i]',b.identifierWordIndices[i]);\n\t\t\t\t\t\t\t\tconsole.log('b.identifierWordIndices[j]',b.identifierWordIndices[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t++bCount;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(this.DEBUG){\n\t\t\t\t\tconsole.log('aCount',aCount);\n\t\t\t\t\tconsole.log('bCount',bCount);\n\t\t\t\t}\n\t\t\t\treturn bCount-aCount;\n\t\t\t});\n\t\t}\n\t\tif(selectedCandidates.length>=1&&selectedCandidates[0].candidate)return selectedCandidates[0].candidate;\n\t\treturn null;\n\t}\n\n\tdefaultParseSearchAreasResponse(searchAreasResponse:string){\n\t\tlet searchAreasResponseIndex=String(searchAreasResponse).indexOf('### Response:');\n\t\tif(searchAreasResponseIndex>=0)searchAreasResponseIndex+='### Response:'.length;\n\t\telse searchAreasResponseIndex=0;\n\t\treturn String(searchAreasResponse).substring(searchAreasResponseIndex).trim();\n\t}\n\n\terrorMessage(error:any){\n\t\treturn typeof error?.response?.data==='string'?error.response.data:error?.response?.data?jsan.stringify(error.response.data):typeof error?.message==='string'?error.message:error?.message?jsan.stringify(error.message):typeof error==='string'?error:jsan.stringify(error);\n\t}\n\n\tasync compareCandidates<Candidate>({\n\t\tcandidates,\n\t\tproblemDescription='',\n\t\tperformGeneration=this.defaultPerformGeneration.bind(this),\n\t\tgenerateSearchAreasInstruction=this.defaultGenerateSearchAreasInstruction.bind(this),\n\t\tparseSearchAreasResponse=this.defaultParseSearchAreasResponse.bind(this),\n\t\tconvertCandidateToDocument=this.defaultConvertCandidateToDocument.bind(this),\n\t\tcandidatesForInitialSelection=2,\n\t\tcandidatesForFinalSelection=1,\n\t\tgenerateRankingInstruction=this.defaultGenerateRankingInstruction.bind(this),\n\t\textractIdentifiersFromRationale=this.defaultExtractIdentifiersFromRationale.bind(this),\n\t\textractIdentifierFromCandidateDocument=this.defaultExtractIdentifierFromCandidateDocument.bind(this),\n\t\tcandidateIdentifierField=undefined,\n\t\tfindCandidateFromIdentifier=this.defaultFindCandidateFromIdentifier.bind(this),\n\t\tgetSummarisableSubstringIndices,\n\t\tgeneratePromptTemplate=this.defaultGeneratePromptTemplate.bind(this),\n\t\tskipRationale=false\n\t}:AICompareCandidates.CompareArguments<Candidate>=<AICompareCandidates.CompareArguments<Candidate>>{}):Promise<AICompareCandidates.CompareCandidatesReturn<Candidate>|void>{\n\t\tif(!Array.isArray(candidates)||candidates.length<=0)throw new Error('No candidates provided');\n\t\tcandidatesForInitialSelection=lodash.toSafeInteger(candidatesForInitialSelection);\n\t\tif(candidatesForInitialSelection<=0)throw new Error('Candidates for initial selection must be a positive integer bigger than 0');\n\t\tcandidatesForFinalSelection=lodash.toSafeInteger(candidatesForFinalSelection);\n\t\tif(candidatesForFinalSelection<=0)throw new Error('Candidates for initial selection must be a positive integer bigger than 0');\n\t\tif(candidatesForInitialSelection<candidatesForFinalSelection)throw new Error('Candidates for initial selection must be equal or more than candidates for final selection');\n\t\tif(candidatesForInitialSelection>candidates.length)throw new Error('There are '+candidatesForInitialSelection+'candidates for initial selection which is more than the total number of candidates of '+candidates.length);\n\t\tif(candidatesForFinalSelection>candidates.length)throw new Error('There are '+candidatesForFinalSelection+'candidates for initial selection which is more than the total number of candidates of '+candidates.length);\n\t\tif(!candidateIdentifierField){\n\t\t\tcandidateIdentifierField=Object.keys(candidates[0] as object)[0] as keyof Candidate;\n\t\t\tif(!candidateIdentifierField)throw new Error('No candidate identifier field');\n\t\t}\n\n\t\tlet rationale='';\n\t\tlet selectedCandidates:Candidate[]=[];\n\n\t\tawait this.checkEmbedderLoaded();\n\t\tif(!this.embedder)return;\n\t\tlet candidateDocuments=candidates.map((candidate,index)=>convertCandidateToDocument({\n\t\t\tcandidate,\n\t\t\tindex\n\t\t}));\n\t\tlet vectorStore=await MemoryVectorStore.fromTexts(\n\t\t\tlodash.cloneDeep(candidateDocuments),\n\t\t\tcandidateDocuments.map((document,index)=>index),\n\t\t\tthis\n\t\t);\n\n\t\tlet searchAreasPromptTemplate=generatePromptTemplate(generateSearchAreasInstruction(problemDescription));\n\t\tif(this.DEBUG)console.log('Formatted search areas prompt: '+searchAreasPromptTemplate);\n\t\tawait this.checkTokeniserLoaded();\n\t\tif(!this.tokeniser)return;\n\t\tlet searchAreasPromptTokens=this.tokeniser.encode(searchAreasPromptTemplate);\n\t\tif(searchAreasPromptTokens.length>this.tokeniser.model_max_length)throw new Error('Search areas instruction prompt is too long for the tokeniser model');\n\n\t\tawait this.checkGeneratorLoaded();\n\t\tif(!this.generator)return;\n\t\tlet generatedText=await performGeneration({\n\t\t\tgenerator:this.generator,\n\t\t\ttokeniser:this.tokeniser,\n\t\t\tprompt:searchAreasPromptTemplate,\n\t\t\ttextGenerationConfig:{\n\t\t\t\tmax_new_tokens:this.generateSearchAreasMaxNewTokens,\n\t\t\t\ttemperature:this.generateSearchAreasTemperature,\n\t\t\t\trepetition_penalty:this.generateSearchAreasRepetitionPenalty\n\t\t\t}\n\t\t});\n\t\tif(this.DEBUG)console.log('Generated search areas response: '+generatedText);\n\t\tlet vectorSearchQuery=parseSearchAreasResponse(generatedText);\n\t\t//generally the first sentence has the greatest relevance to the actual prompt\n\t\t//if(vectorSearchQuery.includes('.'))vectorSearchQuery=vectorSearchQuery.split('.')[0].trim();\n\t\tif(this.DEBUG)console.log('Vector search query: '+vectorSearchQuery);\n\t\tlet queryResult=await vectorStore.similaritySearch(vectorSearchQuery,candidatesForInitialSelection);\n\t\tif(this.DEBUG)console.log('Vector search results: ',queryResult);\n\n\t\tlet summaries:string[]=[];\n\t\t//only bother doing summarisation if there are candidates which exceed the token count\n\t\tif(queryResult.some(result=>result.pageContent.trim().split(/\\s+/).length>this.targetSummarisedStringTokenCount)){\n\t\t\tawait this.checkSummariserLoaded();\n\t\t\tif(!this.summariser)return;\n\t\t\tsummaries=(await Promise.allSettled(queryResult.map(async result=>{\n\t\t\t\tif(!result.pageContent||typeof result.pageContent!=='string')return '';\n\t\t\t\tif(result.pageContent.trim().split(/\\s+/).length<=this.targetSummarisedStringTokenCount)return result.pageContent;\n\t\t\t\tlet summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={\n\t\t\t\t\tstart:0,\n\t\t\t\t\tend:result.pageContent.length\n\t\t\t\t};\n\t\t\t\tif(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));\n\t\t\t\tsummarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);\n\t\t\t\tsummarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);\n\t\t\t\tif(this.DEBUG)console.log(summarisableSubstringIndices);\n\t\t\t\tlet summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);\n\t\t\t\tif(this.DEBUG)console.log(summarisableSubstring);\n\t\t\t\tlet contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);\n\t\t\t\tlet contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);\n\t\t\t\tlet wordsWithoutSummarisable=contentBefore.split(/\\s+/).length+contentAfter.split(/\\s+/).length;\n\t\t\t\tlet targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);\n\t\t\t\tif(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);\n\t\t\t\tlet summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{\n\t\t\t\t\tmax_length:targetSummarisedSubstringTokenCount\n\t\t\t\t});\n\t\t\t\tlet summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];\n\t\t\t\tif(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));\n\t\t\t\tlet summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;\n\t\t\t\tif(this.DEBUG)console.log('Summarised candidate: '+summarisedString);\n\t\t\t\treturn summarisedString;\n\t\t\t}))).filter(result=>result.status==='fulfilled'&&result.value).map(result=>(result as PromiseFulfilledResult<string>).value);\n\t\t}else{\n\t\t\tsummaries=queryResult.map(result=>result.pageContent);\n\t\t}\n\t\t\n\t\tlet rationaleError='';\n\n\t\tif(!skipRationale){\n\t\t\tlet rankingPromptTemplate=generatePromptTemplate(generateRankingInstruction({\n\t\t\t\tproblemDescription,\n\t\t\t\tsummaries,\n\t\t\t\tcandidatesForFinalSelection,\n\t\t\t\tcandidateIdentifierField:String(candidateIdentifierField)\n\t\t\t}));\n\t\t\tif(this.DEBUG)console.log('Formatted ranking prompt: '+rankingPromptTemplate);\n\t\t\tlet rankingPromptTokens=this.tokeniser.encode(rankingPromptTemplate);\n\t\t\tif(this.DEBUG)console.log(rankingPromptTokens.length,this.tokeniser.model_max_length);\n\t\t\tif(rankingPromptTokens.length>this.tokeniser.model_max_length)throw new Error('Ranking instruction prompt is too long for the tokeniser model');\n\t\t\ttry{\n\t\t\t\tlet ranking=await performGeneration({\n\t\t\t\t\tgenerator:this.generator,\n\t\t\t\t\ttokeniser:this.tokeniser,\n\t\t\t\t\tprompt:rankingPromptTemplate,\n\t\t\t\t\ttextGenerationConfig:{\n\t\t\t\t\t\tmax_new_tokens:this.rankingMaxNewTokens,\n\t\t\t\t\t\ttemperature:this.rankingTemperature,\n\t\t\t\t\t\trepetition_penalty:this.rankingRepetitionPenalty\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\trationale=ranking.trim().replace(/(\\*\\*)|(<\\/?s>)|(\\[.*?\\])\\s*/g, '');\n\t\t\t\tif(this.DEBUG)console.log('Generated rationale: '+rationale);\n\t\t\t\tlet rationaleResponseIndex=rationale.indexOf('### Response:');\n\t\t\t\tif(rationaleResponseIndex>=0)rationaleResponseIndex+='### Response:'.length;\n\t\t\t\telse rationaleResponseIndex=0;\n\t\t\t\trationale=rationale.substring(rationaleResponseIndex);\n\t\t\t\t//if(!rationale)throw new Error('No rationale generated');\n\t\t\t}catch(error){\n\t\t\t\tconsole.log(error);\n\t\t\t\trationaleError=this.errorMessage(error);\n\t\t\t\trationale='';\n\t\t\t}\n\t\t}\n\n\t\tif(rationale){\n\t\t\tlet identifiers=extractIdentifiersFromRationale(rationale);\n\t\t\tif(this.DEBUG)console.log('Extracted identifiers from rationale: '+identifiers);\n\t\t\tif(identifiers.length>candidatesForFinalSelection)identifiers=identifiers.slice(0,candidatesForFinalSelection);\n\t\t\tselectedCandidates=lodash.compact(identifiers.map(identifier=>findCandidateFromIdentifier({\n\t\t\t\tidentifier,\n\t\t\t\tcandidateIdentifierField,\n\t\t\t\tcandidates\n\t\t\t})));\n\t\t}\n\n\t\tif(!Array.isArray(selectedCandidates)||selectedCandidates.length<candidatesForFinalSelection){\n\t\t\tif(!Array.isArray(selectedCandidates))selectedCandidates=[];\n\t\t\tlet additionalSelectedCandidates=lodash.compact(queryResult.map(result=>{\n\t\t\t\tlet identifier=extractIdentifierFromCandidateDocument({\n\t\t\t\t\tcandidateDocument:result.pageContent,\n\t\t\t\t\tcandidateIdentifierField:String(candidateIdentifierField)\n\t\t\t\t});\n\t\t\t\tif(this.DEBUG)console.log('Extracted identifier from candidate document: '+identifier);\n\t\t\t\treturn findCandidateFromIdentifier({\n\t\t\t\t\tidentifier,\n\t\t\t\t\tcandidateIdentifierField,\n\t\t\t\t\tcandidates\n\t\t\t\t});\n\t\t\t}));\n\t\t\tselectedCandidates.splice(selectedCandidates.length,0,...additionalSelectedCandidates);\n\t\t\tselectedCandidates=lodash.uniq(selectedCandidates).slice(0,candidatesForFinalSelection);\n\t\t}\n\t\tif(this.DEBUG)console.log('Selected candidates',selectedCandidates);\n\n\t\treturn{\n\t\t\trationale,\n\t\t\tsummaries,\n\t\t\t...(rationaleError?{rationaleError}:{}),\n\t\t\tselectedCandidates\n\t\t};\n\t}\n};\n\nexport namespace AICompareCandidates{\n\texport interface LoadArguments{\n\t\tprogressCallback?:ProgressCallback;\n\t\tmodelName?:string;\n\t};\n\n\texport interface SummarisableSubstringIndices{\n\t\tstart:number;\n\t\tend:number;\n\t};\n\n\texport interface CompareArguments<Candidate>{\n\t\tcandidates:Candidate[];\n\t\tproblemDescription:string;\n\t\tperformGeneration?:(performGenerationArguments:PerformGenerationArguments)=>Promise<string>;\n\t\tgenerateSearchAreasInstruction?:(problemDescription:string)=>string;\n\t\tparseSearchAreasResponse?:(searchAreasResponse:string)=>string;\n\t\tconvertCandidateToDocument?:(convertCandidateToDocumentArguments:ConvertCandidateToDocumentArguments<Candidate>)=>string;\n\t\tcandidatesForInitialSelection?:number;\n\t\tcandidatesForFinalSelection?:number;\n\t\tgenerateRankingInstruction?:(generateRankingInstructionArguments:GenerateRankingInstructionArguments)=>string;\n\t\textractIdentifiersFromRationale?:(rationale:string)=>string[];\n\t\textractIdentifierFromCandidateDocument?:(extractIdentifierFromCandidateDocumentArguments:ExtractIdentifierFromCandidateDocumentArguments)=>string;\n\t\tcandidateIdentifierField?:keyof Candidate;\n\t\tfindCandidateFromIdentifier?:(findCandidateFromIdentifierArguments:FindCandidateFromIdentifierArguments<Candidate>)=>Candidate|null;\n\t\tgetSummarisableSubstringIndices?:(candidateDocument:string)=>SummarisableSubstringIndices;\n\t\tgeneratePromptTemplate?:(prompt:string)=>string;\n\t\tskipRationale?:boolean;\n\t};\n\n\texport interface PerformGenerationArguments{\n\t\tgenerator:TextGenerationPipeline;\n\t\ttokeniser:PreTrainedTokenizer;\n\t\tprompt:string;\n\t\ttextGenerationConfig?:Partial<TextGenerationConfig>;\n\t};\n\n\texport interface ConvertCandidateToDocumentArguments<Candidate>{\n\t\tcandidate:Candidate;\n\t\tindex:number;\n\t};\n\n\texport interface ExtractIdentifierFromCandidateDocumentArguments{\n\t\tcandidateDocument:string;\n\t\tcandidateIdentifierField:string;\n\t};\n\n\texport interface FindCandidateFromIdentifierArguments<Candidate>{\n\t\tidentifier:string;\n\t\tcandidateIdentifierField:keyof Candidate;\n\t\tcandidates:Candidate[];\n\t};\n\n\texport interface GenerateRankingInstructionArguments{\n\t\tproblemDescription:string;\n\t\tsummaries:string[];\n\t\tcandidatesForFinalSelection:number;\n\t\tcandidateIdentifierField:string;\n\t};\n\n\texport interface CompareCandidatesReturn<Candidate>{\n\t\tselectedCandidates:Candidate[],\n\t\trationale:string,\n\t\trationaleError?:string,\n\t\tsummaries:string[]\n\t};\n};\n\nexport default AICompareCandidates;"],"mappings":"6QAmBA,IAAa,EAAb,cAAyC,CAAU,CAClD,IAAa,EACb,MAAM,GAEN,UAAsC,KACtC,mBAAmB,gCACnB,iBAAsD,KACtD,sBAAiD,EAAE,CACnD,0BAAgD,KAChD,yBAAyB,IAAI,gBAE7B,WAAsC,KACtC,oBAAoB,6BACpB,kBAAsD,KACtD,uBAAkD,EAAE,CACpD,2BAAiD,KACjD,0BAA0B,IAAI,gBAE9B,SAAwC,KACxC,kBAAkB,2BAClB,gBAAwD,KACxD,qBAAgD,EAAE,CAClD,yBAA+C,KAC/C,wBAAwB,IAAI,gBAE5B,UAAmC,KACnC,mBAAmB,KAAK,mBACxB,iBAAmD,KACnD,sBAAiD,EAAE,CACnD,0BAAgD,KAChD,yBAAyB,IAAI,gBAE7B,gCAAgC,GAChC,+BAA+B,IAC/B,qCAAqC,IAErC,oBAAoB,GACpB,mBAAmB,IACnB,yBAAyB,IAEzB,iCAAiC,IAEjC,OACC,EAAI,eAAe,GACnB,EAAI,kBAAkB,GACtB,EAAI,iBAAiB,GAGtB,aAAa,CACZ,MAAM,EAAE,CAAC,CAGV,MAAM,cAAc,CACnB,mBACA,YAAU,IAC4D,EAAE,CAAC,CAEzE,GADG,OAAO,GAAY,UAAU,IAAU,KAAK,mBAAmB,GAC/D,CAAC,KAAK,mBAAmB,MAAU,MAAM,+BAA+B,CAc3E,OAbG,IAAiB,KAAK,0BAA0B,GAGnD,KAAK,iBAAiB,EAAS,kBAAkB,KAAK,mBAAmB,CACxE,OAAO,SACP,kBAAkB,IACd,KAAK,OAAM,QAAQ,IAAI,EAAK,UAAU,EAAa,CAAC,CACvD,OAAO,OAAO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AO,EAAyB,CACzD,CAAC,CAEF,OADG,KAAK,OAAM,QAAQ,IAAI,iDAAiD,EAAW,CAC/E,EAA4B,CAClC,aACA,2BACA,aACA,CAAC,EACD,CAAC,CACH,EAAmB,OAAO,EAAmB,OAAO,EAAE,GAAG,EAA6B,CACtF,EAAmB,EAAO,KAAK,EAAmB,CAAC,MAAM,EAAE,EAA4B,CAIxF,OAFG,KAAK,OAAM,QAAQ,IAAI,sBAAsB,EAAmB,CAE7D,CACL,YACA,YACA,GAAI,EAAe,CAAC,iBAAe,CAAC,EAAE,CACtC,qBACA,2BAwEH,IAAA,EAAe"}
1
+ {"version":3,"file":"index.mjs","names":["matches:string[]","match:RegExpExecArray|null","selectedCandidates:Candidate[]","summaries:string[]","summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices"],"sources":["../src/index.ts"],"sourcesContent":["import{\n\tenv,\n\tpipeline,\n\tAutoTokenizer,\n\tTextGenerationPipeline,\n\tProgressInfo,\n\tProgressCallback,\n\tSummarizationPipeline,\n\tFeatureExtractionPipeline,\n\tPreTrainedTokenizer,\n\tTextGenerationConfig,\n\tTextGenerationSingle,\n\tTextStreamer\n}from '@sroussey/transformers';\nimport {MemoryVectorStore} from '@langchain/classic/vectorstores/memory';\nimport {Embeddings} from '@langchain/core/embeddings';\nimport lodash from 'lodash';\nimport jsan from 'jsan';\n\nexport class AICompareCandidates extends Embeddings{\n\treadonly env=env;\n\tDEBUG=true;\n\n\tgenerator:TextGenerationPipeline|null=null;\n\tgeneratorModelName='Xenova/Phi-3-mini-4k-instruct';\n\tgeneratorPromise:Promise<TextGenerationPipeline>|null=null;\n\tgeneratorProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tgeneratorProgressCallback:ProgressCallback|null=null;\n\tgeneratorAbortController=new AbortController();\n\n\tsummariser:SummarizationPipeline|null=null;\n\tsummariserModelName='Xenova/distilbart-cnn-12-6';\n\tsummariserPromise:Promise<SummarizationPipeline>|null=null;\n\tsummariserProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tsummariserProgressCallback:ProgressCallback|null=null;\n\tsummariserAbortController=new AbortController();\n\n\tembedder:FeatureExtractionPipeline|null=null;\n\tembedderModelName='Xenova/all-MiniLM-L12-v2';\n\tembedderPromise:Promise<FeatureExtractionPipeline>|null=null;\n\tembedderProgressInfo:ProgressInfo=<ProgressInfo>{};\n\tembedderProgressCallback:ProgressCallback|null=null;\n\tembedderAbortController=new AbortController();\n\n\ttokeniser:PreTrainedTokenizer|null=null;\n\ttokeniserModelName=this.generatorModelName;\n\ttokeniserPromise:Promise<PreTrainedTokenizer>|null=null;\n\ttokeniserProgressInfo:ProgressInfo=<ProgressInfo>{};\n\ttokeniserProgressCallback:ProgressCallback|null=null;\n\ttokeniserAbortController=new AbortController();\n\n\tgenerateSearchAreasMaxNewTokens=64;\n\tgenerateSearchAreasTemperature=0.35;\n\tgenerateSearchAreasRepetitionPenalty=1.5;\n\n\trankingMaxNewTokens=64;\n\trankingTemperature=0.35;\n\trankingRepetitionPenalty=1.5;\n\n\ttargetSummarisedStringTokenCount=300;\n\n\tstatic{\n\t\tenv.localModelPath='';\n\t\tenv.allowRemoteModels=true;\n\t\tenv.allowLocalModels=false;\n\t}\n\n\tconstructor(){\n\t\tsuper({});\n\t}\n\t\n\tasync loadGenerator({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.generatorModelName=modelName;\n\t\tif(!this.generatorModelName)throw new Error('Invalid generator model name');\n\t\tif(progressCallback)this.generatorProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.generatorPromise=pipeline('text-generation',this.generatorModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.generatorProgressInfo,progressInfo);\n\t\t\t\treturn this.generatorProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.generatorAbortController.signal\n\t\t});\n\t\tthis.generator=await this.generatorPromise;\n\t\treturn this.generator;\n\t}\n\n\tasync checkGeneratorLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.generatorPromise)this.loadGenerator({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.generator){\n\t\t\ttry{\n\t\t\t\tawait this.generatorPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.generatorPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.generator){\n\t\t\tthis.generatorPromise=null;\n\t\t\tthrow new Error('Unable to load generator');\n\t\t}\n\t}\n\n\tasync abortLoadGenerator(reason?:any){\n\t\tthis.generatorAbortController.abort(reason);\n\t\tthis.generatorAbortController=new AbortController();\n\t}\n\n\tasync loadSummariser({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.summariserModelName=modelName;\n\t\tif(!this.summariserModelName)throw new Error('Invalid summariser model name');\n\t\tif(progressCallback)this.summariserProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.summariserPromise=pipeline('summarization',this.summariserModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.summariserProgressInfo,progressInfo);\n\t\t\t\treturn this.summariserProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.summariserAbortController.signal\n\t\t});\n\t\tthis.summariser=await this.summariserPromise;\n\t\treturn this.summariser;\n\t}\n\n\tasync checkSummariserLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.summariserPromise)this.loadSummariser({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.summariser){\n\t\t\ttry{\n\t\t\t\tawait this.summariserPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.summariserPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.summariser){\n\t\t\tthis.summariserPromise=null;\n\t\t\tthrow new Error('Unable to load summariser');\n\t\t}\n\t}\n\n\tasync abortLoadSummariser(){\n\t\tthis.summariserAbortController.abort();\n\t\tthis.summariserAbortController=new AbortController();\n\t}\n\n\tasync loadEmbedder({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.embedderModelName=modelName;\n\t\tif(!this.embedderModelName)throw new Error('Invalid embedder model name');\n\t\tif(progressCallback)this.embedderProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.embedderPromise=pipeline('feature-extraction',this.embedderModelName,{\n\t\t\tdevice:'webgpu',\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.embedderProgressInfo,progressInfo);\n\t\t\t\treturn this.embedderProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.embedderAbortController.signal\n\t\t});\n\t\tthis.embedder=await this.embedderPromise;\n\t\treturn this.embedder;\n\t}\n\n\tasync checkEmbedderLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.embedderPromise)this.loadEmbedder({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.embedder){\n\t\t\ttry{\n\t\t\t\tawait this.embedderPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.embedderPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.embedder){\n\t\t\tthis.embedderPromise=null;\n\t\t\tthrow new Error('Unable to load embedder');\n\t\t}\n\t}\n\n\tasync abortLoadEmbedder(){\n\t\tthis.embedderAbortController.abort();\n\t\tthis.embedderAbortController=new AbortController();\n\t}\n\n\tasync loadTokeniser({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(typeof modelName==='string'&&modelName)this.tokeniserModelName=modelName;\n\t\tif(!this.tokeniserModelName)throw new Error('Invalid tokeniser model name');\n\t\tif(progressCallback)this.tokeniserProgressCallback=progressCallback;\n\t\t//ts-ignore is needed due to frequent error TS2590: Expression produces a union type that is too complex to represent.\n\t\t//@ts-ignore\n\t\tthis.tokeniserPromise=AutoTokenizer.from_pretrained(this.tokeniserModelName,{\n\t\t\tprogress_callback:progressInfo=>{\n\t\t\t\tif(this.DEBUG)console.log(jsan.stringify(progressInfo));\n\t\t\t\tObject.assign(this.tokeniserProgressInfo,progressInfo);\n\t\t\t\treturn this.tokeniserProgressCallback?.(progressInfo);\n\t\t\t},\n\t\t\tabort_signal:this.tokeniserAbortController.signal\n\t\t});\n\t\tthis.tokeniser=await this.tokeniserPromise;\n\t\treturn this.tokeniser;\n\t}\n\n\tasync checkTokeniserLoaded({\n\t\tprogressCallback,\n\t\tmodelName=''\n\t}:AICompareCandidates.LoadArguments=<AICompareCandidates.LoadArguments>{}){\n\t\tif(!this.tokeniserPromise)this.loadTokeniser({\n\t\t\tprogressCallback,\n\t\t\tmodelName\n\t\t});\n\t\tif(!this.tokeniser){\n\t\t\ttry{\n\t\t\t\tawait this.tokeniserPromise;\n\t\t\t}catch(error){\n\t\t\t\tthis.tokeniserPromise=null;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tif(!this.tokeniser){\n\t\t\tthis.tokeniserPromise=null;\n\t\t\tthrow new Error('Unable to load tokeniser');\n\t\t}\n\t}\n\n\tasync abortLoadTokeniser(){\n\t\tthis.tokeniserAbortController.abort();\n\t\tthis.tokeniserAbortController=new AbortController();\n\t}\n\n\tasync embedQuery(text:string):Promise<number[]>{\n\t\tawait this.checkEmbedderLoaded();\n\t\tif(typeof this.embedder==='function')return Array.from((await this.embedder(text,{\n\t\t\tpooling:'mean',\n\t\t\tnormalize:true\n\t\t}))?.data);\n\t\treturn [];\n\t}\n\n\tasync embedDocuments(texts:string[]):Promise<number[][]>{\n\t\treturn Promise.all(texts.map(text=>this.embedQuery(text)));\n\t}\n\n\tdefaultGeneratePromptTemplate(prompt:string){\n\t\treturn prompt;\n\t}\n\n\tasync defaultPerformGeneration({\n\t\tgenerator,\n\t\ttokeniser,\n\t\tprompt='',\n\t\ttextGenerationConfig={}\n\t}:AICompareCandidates.PerformGenerationArguments=<AICompareCandidates.PerformGenerationArguments>{}){\n\t\tlet errors='';\n\t\tif(!generator)errors+='No generator provided.';\n\t\tif(!tokeniser)errors+=(errors?'\\n':'')+'No tokeniser provided.';\n\t\tif(typeof prompt!=='string'||!prompt)errors+=(errors?'\\n':'')+'No valid prompt provided.';\n\t\tif(errors)throw new Error(errors);\n\t\tlet messages=[{\n\t\t\trole:'user',\n\t\t\tcontent:prompt\n\t\t}];\n\t\tlet streamer=new TextStreamer(tokeniser,{\n\t\t\tskip_prompt:true\n\t\t});\n\t\tif(!textGenerationConfig.pad_token_id)textGenerationConfig.pad_token_id=tokeniser.pad_token_id??tokeniser.sep_token_id??0;\n\t\tif(!textGenerationConfig.eos_token_id)textGenerationConfig.eos_token_id=tokeniser.sep_token_id??2;\n\t\tlet output=await generator(messages,textGenerationConfig);\n\t\tif(this.DEBUG)console.log(output);\n\t\tlet outputObject=Array.isArray(output?.[0])?output?.[0]?.[0]:output?.[0];\n\t\tif(!outputObject.generated_text)throw new Error('No generated text');\n\t\tif(typeof outputObject.generated_text==='string')return outputObject.generated_text;\n\t\tlet content=outputObject.generated_text?.at(-1)?.content;\n\t\tif(typeof content!=='string'||!content)throw new Error('No content in generated text');\n\t\treturn content;\n\t}\n\n\tdefaultGenerateSearchAreasInstruction(problemDescription:string){\n\t\treturn 'List the relevant subject areas for the following issues. Limit your response to 100 words.\\nIssues: \"'+problemDescription+'\"';\n\t}\n\n\tdefaultConvertCandidateToDocument<Candidate>({\n\t\tcandidate,\n\t\tindex\n\t}:AICompareCandidates.ConvertCandidateToDocumentArguments<Candidate>=<AICompareCandidates.ConvertCandidateToDocumentArguments<Candidate>>{}){\n\t\tlet document='Start of Candidate #'+index;\n\t\tfor(let i in candidate)document+='\\n'+lodash.startCase(i)+': '+(typeof candidate[i]==='object'?jsan.stringify(candidate[i]):String(candidate[i]));\n\t\tdocument+='\\nEnd of Candidate #'+index;\n\t\treturn document;\n\t}\n\n\tdefaultGenerateRankingInstruction({\n\t\tproblemDescription,\n\t\tsummaries,\n\t\tcandidatesForFinalSelection,\n\t\tcandidateIdentifierField\n\t}:AICompareCandidates.GenerateRankingInstructionArguments=<AICompareCandidates.GenerateRankingInstructionArguments>{}){\n\t\treturn 'Rank only the top '+candidatesForFinalSelection+' candidates by connecting them to \"'+problemDescription+'\" stating # followed by the candidate number and the full '+lodash.startCase(candidateIdentifierField)+' followed by a 15-word explanation for each ranking. Stop generating text immediately thereafter.\\n\\nCandidates:\\n\\n'+summaries.join('\\n\\n');\n\t}\n\n\tregexIndexOf(text:string,regex:RegExp,startIndex:number){\n \tlet indexInSuffix=text.slice(startIndex).search(regex);\n \treturn indexInSuffix<0?indexInSuffix:indexInSuffix+startIndex;\n\t}\n\n\tdefaultExtractIdentifierFromCandidateDocument({\n\t\tcandidateDocument,\n\t\tcandidateIdentifierField\n\t}:AICompareCandidates.ExtractIdentifierFromCandidateDocumentArguments=<AICompareCandidates.ExtractIdentifierFromCandidateDocumentArguments>{}){\n\t\tif(this.DEBUG)console.log(candidateDocument,candidateIdentifierField);\n\t\tlet startCase=lodash.startCase(candidateIdentifierField);\n\t\tlet startIndex=candidateDocument.indexOf(startCase);\n\t\tif(startIndex<0)startIndex=candidateDocument.toLowerCase().indexOf(startCase.toLowerCase());\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex>=0)startIndex+=startCase.length;\n\t\tif(startIndex<0){\n\t\t\tstartIndex=candidateDocument.toLowerCase().indexOf(candidateIdentifierField.toLowerCase());\n\t\t\tif(startIndex>=0)startIndex+=candidateIdentifierField.length;\n\t\t}\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\telse return '';\n\t\tstartIndex=candidateDocument.indexOf(':',startIndex);\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex<0)startIndex=this.regexIndexOf(candidateDocument,/\\s+/,startIndex);\n\t\tif(this.DEBUG)console.log(startIndex);\n\t\tif(startIndex<0)return '';\n\t\tlet endIndex=candidateDocument.indexOf('\\n',startIndex);\n\t\tif(endIndex<0)endIndex=candidateDocument.length;\n\t\tif(this.DEBUG)console.log(endIndex);\n\t\treturn candidateDocument.substring(startIndex,endIndex).trim();\n\t}\n\n\tdefaultExtractIdentifiersFromRationale(rationale:string){\n\t\tlet regex=/^\\d+?\\s*?\\p{P}\\s*?(.+?)\\s*?(-|\\.|;|\\n)/gmu;\n\t\tlet matches:string[]=[];\n\t\tfor(let match:RegExpExecArray|null;Array.isArray(match=regex.exec(rationale));)if(match[1])matches.push(match[1]);\n\t\treturn matches;\n\t}\n\n\tdefaultFindCandidateFromIdentifier<Candidate>({\n\t\tidentifier,\n\t\tcandidateIdentifierField,\n\t\tcandidates\n\t}:AICompareCandidates.FindCandidateFromIdentifierArguments<Candidate>=<AICompareCandidates.FindCandidateFromIdentifierArguments<Candidate>>{}){\n\t\tif(!identifier||typeof identifier!=='string')identifier=String(identifier);\n\t\tconsole.log('identifier',identifier);\n\t\tlet selectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField])===identifier);\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField]).toLowerCase()===identifier.toLowerCase());\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>String(candidate[candidateIdentifierField]).toLowerCase().includes(identifier.toLowerCase()));\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\tselectedCandidate=candidates.find(candidate=>identifier.toLowerCase().includes(String(candidate[candidateIdentifierField]).toLowerCase()));\n\t\tif(selectedCandidate){\n\t\t\tif(this.DEBUG){\n\t\t\t\tconsole.log('Candidate found based on case-sensitive match',selectedCandidate[candidateIdentifierField]);\n\t\t\t}\n\t\t\treturn selectedCandidate;\n\t\t}\n\t\t//split by space and find highest number of matches (tie break if it is in same order)\n\t\tlet identifierWords=identifier.split(/\\s+/g).filter(identifierWord=>/\\w/.test(identifierWord));\n\t\tif(this.DEBUG)console.log('Identifier words',identifierWords);\n\t\tlet selectedCandidates=candidates.map(candidate=>({\n\t\t\tidentifierWordIndices:identifierWords.map(identifierWord=>String(candidate[candidateIdentifierField]).indexOf(identifierWord)),\n\t\t\tcandidate\n\t\t})).filter(candidate=>candidate.identifierWordIndices.some(index=>index>=0));\n\t\tif(selectedCandidates.length>1){\n\t\t\tselectedCandidates.sort((a,b)=>{\n\t\t\t\tlet aCount=lodash.sumBy(a.identifierWordIndices,aElement=>aElement<0?0:1);\n\t\t\t\tlet bCount=lodash.sumBy(b.identifierWordIndices,bElement=>bElement<0?0:1);\n\t\t\t\tif(this.DEBUG){\n\t\t\t\t\tconsole.log('a',a);\n\t\t\t\t\tconsole.log('b',b);\n\t\t\t\t\tconsole.log('a.identifierWordIndices',a.identifierWordIndices);\n\t\t\t\t\tconsole.log('b.identifierWordIndices',b.identifierWordIndices);\n\t\t\t\t\tconsole.log('aCount',aCount);\n\t\t\t\t\tconsole.log('bCount',bCount);\n\t\t\t\t}\n\t\t\t\tif(aCount!==bCount)return bCount-aCount;\n\t\t\t\tif(aCount===0&&bCount===0)return 0;\n\t\t\t\taCount=0;\n\t\t\t\tbCount=0;\n\t\t\t\tfor(let i=0;i<a.identifierWordIndices.length-1;++i){\n\t\t\t\t\tfor(let j=i+1;j<a.identifierWordIndices.length;++j){\n\t\t\t\t\t\tif(a.identifierWordIndices[i]<0||a.identifierWordIndices[j]<0)continue;\n\t\t\t\t\t\tif(a.identifierWordIndices[i]<a.identifierWordIndices[j]){\n\t\t\t\t\t\t\tif(this.DEBUG){\n\t\t\t\t\t\t\t\tconsole.log('i',i);\n\t\t\t\t\t\t\t\tconsole.log('j',j);\n\t\t\t\t\t\t\t\tconsole.log('a.identifierWordIndices[i]',a.identifierWordIndices[i]);\n\t\t\t\t\t\t\t\tconsole.log('a.identifierWordIndices[j]',a.identifierWordIndices[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t++aCount;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(let i=0;i<b.identifierWordIndices.length-1;++i){\n\t\t\t\t\tfor(let j=i+1;j<b.identifierWordIndices.length;++j){\n\t\t\t\t\t\tif(b.identifierWordIndices[i]<0||b.identifierWordIndices[j]<0)continue;\n\t\t\t\t\t\tif(b.identifierWordIndices[i]<b.identifierWordIndices[j]){\n\t\t\t\t\t\t\tif(this.DEBUG){\n\t\t\t\t\t\t\t\tconsole.log('i',i);\n\t\t\t\t\t\t\t\tconsole.log('j',j);\n\t\t\t\t\t\t\t\tconsole.log('b.identifierWordIndices[i]',b.identifierWordIndices[i]);\n\t\t\t\t\t\t\t\tconsole.log('b.identifierWordIndices[j]',b.identifierWordIndices[j]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t++bCount;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(this.DEBUG){\n\t\t\t\t\tconsole.log('aCount',aCount);\n\t\t\t\t\tconsole.log('bCount',bCount);\n\t\t\t\t}\n\t\t\t\treturn bCount-aCount;\n\t\t\t});\n\t\t}\n\t\tif(selectedCandidates.length>=1&&selectedCandidates[0].candidate)return selectedCandidates[0].candidate;\n\t\treturn null;\n\t}\n\n\tdefaultParseSearchAreasResponse(searchAreasResponse:string){\n\t\tlet searchAreasResponseIndex=String(searchAreasResponse).indexOf('### Response:');\n\t\tif(searchAreasResponseIndex>=0)searchAreasResponseIndex+='### Response:'.length;\n\t\telse searchAreasResponseIndex=0;\n\t\treturn String(searchAreasResponse).substring(searchAreasResponseIndex).trim();\n\t}\n\n\terrorMessage(error:any){\n\t\treturn typeof error?.response?.data==='string'?error.response.data:error?.response?.data?jsan.stringify(error.response.data):typeof error?.message==='string'?error.message:error?.message?jsan.stringify(error.message):typeof error==='string'?error:jsan.stringify(error);\n\t}\n\n\tasync compareCandidates<Candidate>({\n\t\tcandidates,\n\t\tproblemDescription='',\n\t\tperformGeneration=this.defaultPerformGeneration.bind(this),\n\t\tgenerateSearchAreasInstruction=this.defaultGenerateSearchAreasInstruction.bind(this),\n\t\tparseSearchAreasResponse=this.defaultParseSearchAreasResponse.bind(this),\n\t\tconvertCandidateToDocument=this.defaultConvertCandidateToDocument.bind(this),\n\t\tcandidatesForInitialSelection=2,\n\t\tcandidatesForFinalSelection=1,\n\t\tgenerateRankingInstruction=this.defaultGenerateRankingInstruction.bind(this),\n\t\textractIdentifiersFromRationale=this.defaultExtractIdentifiersFromRationale.bind(this),\n\t\textractIdentifierFromCandidateDocument=this.defaultExtractIdentifierFromCandidateDocument.bind(this),\n\t\tcandidateIdentifierField=undefined,\n\t\tfindCandidateFromIdentifier=this.defaultFindCandidateFromIdentifier.bind(this),\n\t\tgetSummarisableSubstringIndices,\n\t\tgeneratePromptTemplate=this.defaultGeneratePromptTemplate.bind(this),\n\t\tskipRationale=false,\n\t\tparallelSummarisation=true\n\t}:AICompareCandidates.CompareArguments<Candidate>=<AICompareCandidates.CompareArguments<Candidate>>{}):Promise<AICompareCandidates.CompareCandidatesReturn<Candidate>|void>{\n\t\tif(!Array.isArray(candidates)||candidates.length<=0)throw new Error('No candidates provided');\n\t\tcandidatesForInitialSelection=lodash.toSafeInteger(candidatesForInitialSelection);\n\t\tif(candidatesForInitialSelection<=0)throw new Error('Candidates for initial selection must be a positive integer bigger than 0');\n\t\tcandidatesForFinalSelection=lodash.toSafeInteger(candidatesForFinalSelection);\n\t\tif(candidatesForFinalSelection<=0)throw new Error('Candidates for initial selection must be a positive integer bigger than 0');\n\t\tif(candidatesForInitialSelection<candidatesForFinalSelection)throw new Error('Candidates for initial selection must be equal or more than candidates for final selection');\n\t\tif(candidatesForInitialSelection>candidates.length)throw new Error('There are '+candidatesForInitialSelection+'candidates for initial selection which is more than the total number of candidates of '+candidates.length);\n\t\tif(candidatesForFinalSelection>candidates.length)throw new Error('There are '+candidatesForFinalSelection+'candidates for initial selection which is more than the total number of candidates of '+candidates.length);\n\t\tif(!candidateIdentifierField){\n\t\t\tcandidateIdentifierField=Object.keys(candidates[0] as object)[0] as keyof Candidate;\n\t\t\tif(!candidateIdentifierField)throw new Error('No candidate identifier field');\n\t\t}\n\n\t\tlet rationale='';\n\t\tlet selectedCandidates:Candidate[]=[];\n\n\t\tawait this.checkEmbedderLoaded();\n\t\tif(!this.embedder)return;\n\t\tlet candidateDocuments=candidates.map((candidate,index)=>convertCandidateToDocument({\n\t\t\tcandidate,\n\t\t\tindex\n\t\t}));\n\t\tlet vectorStore=await MemoryVectorStore.fromTexts(\n\t\t\tlodash.cloneDeep(candidateDocuments),\n\t\t\tcandidateDocuments.map((document,index)=>index),\n\t\t\tthis\n\t\t);\n\n\t\tlet searchAreasPromptTemplate=generatePromptTemplate(generateSearchAreasInstruction(problemDescription));\n\t\tif(this.DEBUG)console.log('Formatted search areas prompt: '+searchAreasPromptTemplate);\n\t\tawait this.checkTokeniserLoaded();\n\t\tif(!this.tokeniser)return;\n\t\tlet searchAreasPromptTokens=this.tokeniser.encode(searchAreasPromptTemplate);\n\t\tif(searchAreasPromptTokens.length>this.tokeniser.model_max_length)throw new Error('Search areas instruction prompt is too long for the tokeniser model');\n\n\t\tawait this.checkGeneratorLoaded();\n\t\tif(!this.generator)return;\n\t\tlet generatedText=await performGeneration({\n\t\t\tgenerator:this.generator,\n\t\t\ttokeniser:this.tokeniser,\n\t\t\tprompt:searchAreasPromptTemplate,\n\t\t\ttextGenerationConfig:{\n\t\t\t\tmax_new_tokens:this.generateSearchAreasMaxNewTokens,\n\t\t\t\ttemperature:this.generateSearchAreasTemperature,\n\t\t\t\trepetition_penalty:this.generateSearchAreasRepetitionPenalty\n\t\t\t}\n\t\t});\n\t\tif(this.DEBUG)console.log('Generated search areas response: '+generatedText);\n\t\tlet vectorSearchQuery=parseSearchAreasResponse(generatedText);\n\t\t//generally the first sentence has the greatest relevance to the actual prompt\n\t\t//if(vectorSearchQuery.includes('.'))vectorSearchQuery=vectorSearchQuery.split('.')[0].trim();\n\t\tif(this.DEBUG)console.log('Vector search query: '+vectorSearchQuery);\n\t\tlet queryResult=await vectorStore.similaritySearch(vectorSearchQuery,candidatesForInitialSelection);\n\t\tif(this.DEBUG)console.log('Vector search results: ',queryResult);\n\n\t\tlet summaries:string[]=[];\n\t\t//only bother doing summarisation if there are candidates which exceed the token count\n\t\tif(queryResult.some(result=>result.pageContent.trim().split(/\\s+/).length>this.targetSummarisedStringTokenCount)){\n\t\t\tawait this.checkSummariserLoaded();\n\t\t\tif(!this.summariser)return;\n\t\t\tif(parallelSummarisation){\n\t\t\t\tsummaries=(await Promise.allSettled(queryResult.map(async result=>{\n\t\t\t\t\tif(!result.pageContent||typeof result.pageContent!=='string')return '';\n\t\t\t\t\tif(result.pageContent.trim().split(/\\s+/).length<=this.targetSummarisedStringTokenCount)return result.pageContent;\n\t\t\t\t\tlet summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={\n\t\t\t\t\t\tstart:0,\n\t\t\t\t\t\tend:result.pageContent.length\n\t\t\t\t\t};\n\t\t\t\t\tif(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));\n\t\t\t\t\tsummarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);\n\t\t\t\t\tsummarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);\n\t\t\t\t\tif(this.DEBUG)console.log(summarisableSubstringIndices);\n\t\t\t\t\tlet summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);\n\t\t\t\t\tif(this.DEBUG)console.log(summarisableSubstring);\n\t\t\t\t\tlet contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);\n\t\t\t\t\tlet contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);\n\t\t\t\t\tlet wordsWithoutSummarisable=contentBefore.split(/\\s+/).length+contentAfter.split(/\\s+/).length;\n\t\t\t\t\tlet targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);\n\t\t\t\t\tif(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);\n\t\t\t\t\tlet summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{\n\t\t\t\t\t\tmax_length:targetSummarisedSubstringTokenCount\n\t\t\t\t\t});\n\t\t\t\t\tlet summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];\n\t\t\t\t\tif(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));\n\t\t\t\t\tlet summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;\n\t\t\t\t\tif(this.DEBUG)console.log('Summarised candidate: '+summarisedString);\n\t\t\t\t\treturn summarisedString;\n\t\t\t\t}))).filter(result=>result.status==='fulfilled'&&result.value).map(result=>(result as PromiseFulfilledResult<string>).value);\n\t\t\t}else{\n\t\t\t\tfor(let result of queryResult){\n\t\t\t\t\ttry{\n\t\t\t\t\t\tif(!result.pageContent||typeof result.pageContent!=='string')continue;\n\t\t\t\t\t\tif(result.pageContent.trim().split(/\\s+/).length<=this.targetSummarisedStringTokenCount){\n\t\t\t\t\t\t\tsummaries.push(result.pageContent);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={\n\t\t\t\t\t\t\tstart:0,\n\t\t\t\t\t\t\tend:result.pageContent.length\n\t\t\t\t\t\t};\n\t\t\t\t\t\tif(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));\n\t\t\t\t\t\tsummarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);\n\t\t\t\t\t\tsummarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);\n\t\t\t\t\t\tif(this.DEBUG)console.log(summarisableSubstringIndices);\n\t\t\t\t\t\tlet summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);\n\t\t\t\t\t\tif(this.DEBUG)console.log(summarisableSubstring);\n\t\t\t\t\t\tlet contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);\n\t\t\t\t\t\tlet contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);\n\t\t\t\t\t\tlet wordsWithoutSummarisable=contentBefore.split(/\\s+/).length+contentAfter.split(/\\s+/).length;\n\t\t\t\t\t\tlet targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);\n\t\t\t\t\t\tif(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);\n\t\t\t\t\t\tlet summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{\n\t\t\t\t\t\t\tmax_length:targetSummarisedSubstringTokenCount\n\t\t\t\t\t\t});\n\t\t\t\t\t\tlet summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];\n\t\t\t\t\t\tif(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));\n\t\t\t\t\t\tlet summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;\n\t\t\t\t\t\tif(this.DEBUG)console.log('Summarised candidate: '+summarisedString);\n\t\t\t\t\t\tsummaries.push(summarisedString);\n\t\t\t\t\t}catch(error){\n\t\t\t\t\t\tconsole.log(error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\tsummaries=queryResult.map(result=>result.pageContent);\n\t\t}\n\t\t\n\t\tlet rationaleError='';\n\n\t\tif(!skipRationale){\n\t\t\tlet rankingPromptTemplate=generatePromptTemplate(generateRankingInstruction({\n\t\t\t\tproblemDescription,\n\t\t\t\tsummaries,\n\t\t\t\tcandidatesForFinalSelection,\n\t\t\t\tcandidateIdentifierField:String(candidateIdentifierField)\n\t\t\t}));\n\t\t\tif(this.DEBUG)console.log('Formatted ranking prompt: '+rankingPromptTemplate);\n\t\t\tlet rankingPromptTokens=this.tokeniser.encode(rankingPromptTemplate);\n\t\t\tif(this.DEBUG)console.log(rankingPromptTokens.length,this.tokeniser.model_max_length);\n\t\t\tif(rankingPromptTokens.length>this.tokeniser.model_max_length)throw new Error('Ranking instruction prompt is too long for the tokeniser model');\n\t\t\ttry{\n\t\t\t\tlet ranking=await performGeneration({\n\t\t\t\t\tgenerator:this.generator,\n\t\t\t\t\ttokeniser:this.tokeniser,\n\t\t\t\t\tprompt:rankingPromptTemplate,\n\t\t\t\t\ttextGenerationConfig:{\n\t\t\t\t\t\tmax_new_tokens:this.rankingMaxNewTokens,\n\t\t\t\t\t\ttemperature:this.rankingTemperature,\n\t\t\t\t\t\trepetition_penalty:this.rankingRepetitionPenalty\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\trationale=ranking.trim().replace(/(\\*\\*)|(<\\/?s>)|(\\[.*?\\])\\s*/g, '');\n\t\t\t\tif(this.DEBUG)console.log('Generated rationale: '+rationale);\n\t\t\t\tlet rationaleResponseIndex=rationale.indexOf('### Response:');\n\t\t\t\tif(rationaleResponseIndex>=0)rationaleResponseIndex+='### Response:'.length;\n\t\t\t\telse rationaleResponseIndex=0;\n\t\t\t\trationale=rationale.substring(rationaleResponseIndex);\n\t\t\t\t//if(!rationale)throw new Error('No rationale generated');\n\t\t\t}catch(error){\n\t\t\t\tconsole.log(error);\n\t\t\t\trationaleError=this.errorMessage(error);\n\t\t\t\trationale='';\n\t\t\t}\n\t\t}\n\n\t\tif(rationale){\n\t\t\tlet identifiers=extractIdentifiersFromRationale(rationale);\n\t\t\tif(this.DEBUG)console.log('Extracted identifiers from rationale: '+identifiers);\n\t\t\tif(identifiers.length>candidatesForFinalSelection)identifiers=identifiers.slice(0,candidatesForFinalSelection);\n\t\t\tselectedCandidates=lodash.compact(identifiers.map(identifier=>findCandidateFromIdentifier({\n\t\t\t\tidentifier,\n\t\t\t\tcandidateIdentifierField,\n\t\t\t\tcandidates\n\t\t\t})));\n\t\t}\n\n\t\tif(!Array.isArray(selectedCandidates)||selectedCandidates.length<candidatesForFinalSelection){\n\t\t\tif(!Array.isArray(selectedCandidates))selectedCandidates=[];\n\t\t\tlet additionalSelectedCandidates=lodash.compact(queryResult.map(result=>{\n\t\t\t\tlet identifier=extractIdentifierFromCandidateDocument({\n\t\t\t\t\tcandidateDocument:result.pageContent,\n\t\t\t\t\tcandidateIdentifierField:String(candidateIdentifierField)\n\t\t\t\t});\n\t\t\t\tif(this.DEBUG)console.log('Extracted identifier from candidate document: '+identifier);\n\t\t\t\treturn findCandidateFromIdentifier({\n\t\t\t\t\tidentifier,\n\t\t\t\t\tcandidateIdentifierField,\n\t\t\t\t\tcandidates\n\t\t\t\t});\n\t\t\t}));\n\t\t\tselectedCandidates.splice(selectedCandidates.length,0,...additionalSelectedCandidates);\n\t\t\tselectedCandidates=lodash.uniq(selectedCandidates).slice(0,candidatesForFinalSelection);\n\t\t}\n\t\tif(this.DEBUG)console.log('Selected candidates',selectedCandidates);\n\n\t\treturn{\n\t\t\trationale,\n\t\t\tsummaries,\n\t\t\t...(rationaleError?{rationaleError}:{}),\n\t\t\tselectedCandidates\n\t\t};\n\t}\n};\n\nexport namespace AICompareCandidates{\n\texport interface LoadArguments{\n\t\tprogressCallback?:ProgressCallback;\n\t\tmodelName?:string;\n\t};\n\n\texport interface SummarisableSubstringIndices{\n\t\tstart:number;\n\t\tend:number;\n\t};\n\n\texport interface CompareArguments<Candidate>{\n\t\tcandidates:Candidate[];\n\t\tproblemDescription:string;\n\t\tperformGeneration?:(performGenerationArguments:PerformGenerationArguments)=>Promise<string>;\n\t\tgenerateSearchAreasInstruction?:(problemDescription:string)=>string;\n\t\tparseSearchAreasResponse?:(searchAreasResponse:string)=>string;\n\t\tconvertCandidateToDocument?:(convertCandidateToDocumentArguments:ConvertCandidateToDocumentArguments<Candidate>)=>string;\n\t\tcandidatesForInitialSelection?:number;\n\t\tcandidatesForFinalSelection?:number;\n\t\tgenerateRankingInstruction?:(generateRankingInstructionArguments:GenerateRankingInstructionArguments)=>string;\n\t\textractIdentifiersFromRationale?:(rationale:string)=>string[];\n\t\textractIdentifierFromCandidateDocument?:(extractIdentifierFromCandidateDocumentArguments:ExtractIdentifierFromCandidateDocumentArguments)=>string;\n\t\tcandidateIdentifierField?:keyof Candidate;\n\t\tfindCandidateFromIdentifier?:(findCandidateFromIdentifierArguments:FindCandidateFromIdentifierArguments<Candidate>)=>Candidate|null;\n\t\tgetSummarisableSubstringIndices?:(candidateDocument:string)=>SummarisableSubstringIndices;\n\t\tgeneratePromptTemplate?:(prompt:string)=>string;\n\t\tskipRationale?:boolean;\n\t\tparallelSummarisation?:boolean;\n\t};\n\n\texport interface PerformGenerationArguments{\n\t\tgenerator:TextGenerationPipeline;\n\t\ttokeniser:PreTrainedTokenizer;\n\t\tprompt:string;\n\t\ttextGenerationConfig?:Partial<TextGenerationConfig>;\n\t};\n\n\texport interface ConvertCandidateToDocumentArguments<Candidate>{\n\t\tcandidate:Candidate;\n\t\tindex:number;\n\t};\n\n\texport interface ExtractIdentifierFromCandidateDocumentArguments{\n\t\tcandidateDocument:string;\n\t\tcandidateIdentifierField:string;\n\t};\n\n\texport interface FindCandidateFromIdentifierArguments<Candidate>{\n\t\tidentifier:string;\n\t\tcandidateIdentifierField:keyof Candidate;\n\t\tcandidates:Candidate[];\n\t};\n\n\texport interface GenerateRankingInstructionArguments{\n\t\tproblemDescription:string;\n\t\tsummaries:string[];\n\t\tcandidatesForFinalSelection:number;\n\t\tcandidateIdentifierField:string;\n\t};\n\n\texport interface CompareCandidatesReturn<Candidate>{\n\t\tselectedCandidates:Candidate[],\n\t\trationale:string,\n\t\trationaleError?:string,\n\t\tsummaries:string[]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B,EAAO,YACzB,yBAAyB,OAAO,EAAyB,CACzD,CAAC,CAEF,OADG,KAAK,OAAM,QAAQ,IAAI,iDAAiD,EAAW,CAC/E,EAA4B,CAClC,aACA,2BACA,aACA,CAAC,EACD,CAAC,CACH,EAAmB,OAAO,EAAmB,OAAO,EAAE,GAAG,EAA6B,CACtF,EAAmB,EAAO,KAAK,EAAmB,CAAC,MAAM,EAAE,EAA4B,CAIxF,OAFG,KAAK,OAAM,QAAQ,IAAI,sBAAsB,EAAmB,CAE7D,CACL,YACA,YACA,GAAI,EAAe,CAAC,iBAAe,CAAC,EAAE,CACtC,qBACA,2BAyEH,IAAA,EAAe"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-compare-candidates-example",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "An example for the ai-compare-candidates library",
5
5
  "productName": "AI Compare Candidates Example",
6
6
  "author": "Wilson Foo Yu Kang <wilson.foo@customautosys.com>",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-compare-candidates",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Compare and rank multiple candidate objects using artificial intelligence retrieval augmented generation, providing the rationale",
5
5
  "main": "dist/index.mjs",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -497,7 +497,8 @@ export class AICompareCandidates extends Embeddings{
497
497
  findCandidateFromIdentifier=this.defaultFindCandidateFromIdentifier.bind(this),
498
498
  getSummarisableSubstringIndices,
499
499
  generatePromptTemplate=this.defaultGeneratePromptTemplate.bind(this),
500
- skipRationale=false
500
+ skipRationale=false,
501
+ parallelSummarisation=true
501
502
  }:AICompareCandidates.CompareArguments<Candidate>=<AICompareCandidates.CompareArguments<Candidate>>{}):Promise<AICompareCandidates.CompareCandidatesReturn<Candidate>|void>{
502
503
  if(!Array.isArray(candidates)||candidates.length<=0)throw new Error('No candidates provided');
503
504
  candidatesForInitialSelection=lodash.toSafeInteger(candidatesForInitialSelection);
@@ -559,33 +560,70 @@ export class AICompareCandidates extends Embeddings{
559
560
  if(queryResult.some(result=>result.pageContent.trim().split(/\s+/).length>this.targetSummarisedStringTokenCount)){
560
561
  await this.checkSummariserLoaded();
561
562
  if(!this.summariser)return;
562
- summaries=(await Promise.allSettled(queryResult.map(async result=>{
563
- if(!result.pageContent||typeof result.pageContent!=='string')return '';
564
- if(result.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount)return result.pageContent;
565
- let summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={
566
- start:0,
567
- end:result.pageContent.length
568
- };
569
- if(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));
570
- summarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);
571
- summarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);
572
- if(this.DEBUG)console.log(summarisableSubstringIndices);
573
- let summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);
574
- if(this.DEBUG)console.log(summarisableSubstring);
575
- let contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);
576
- let contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);
577
- let wordsWithoutSummarisable=contentBefore.split(/\s+/).length+contentAfter.split(/\s+/).length;
578
- let targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);
579
- if(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);
580
- let summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{
581
- max_length:targetSummarisedSubstringTokenCount
582
- });
583
- let summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];
584
- if(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));
585
- let summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;
586
- if(this.DEBUG)console.log('Summarised candidate: '+summarisedString);
587
- return summarisedString;
588
- }))).filter(result=>result.status==='fulfilled'&&result.value).map(result=>(result as PromiseFulfilledResult<string>).value);
563
+ if(parallelSummarisation){
564
+ summaries=(await Promise.allSettled(queryResult.map(async result=>{
565
+ if(!result.pageContent||typeof result.pageContent!=='string')return '';
566
+ if(result.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount)return result.pageContent;
567
+ let summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={
568
+ start:0,
569
+ end:result.pageContent.length
570
+ };
571
+ if(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));
572
+ summarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);
573
+ summarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);
574
+ if(this.DEBUG)console.log(summarisableSubstringIndices);
575
+ let summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);
576
+ if(this.DEBUG)console.log(summarisableSubstring);
577
+ let contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);
578
+ let contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);
579
+ let wordsWithoutSummarisable=contentBefore.split(/\s+/).length+contentAfter.split(/\s+/).length;
580
+ let targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);
581
+ if(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);
582
+ let summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{
583
+ max_length:targetSummarisedSubstringTokenCount
584
+ });
585
+ let summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];
586
+ if(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));
587
+ let summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;
588
+ if(this.DEBUG)console.log('Summarised candidate: '+summarisedString);
589
+ return summarisedString;
590
+ }))).filter(result=>result.status==='fulfilled'&&result.value).map(result=>(result as PromiseFulfilledResult<string>).value);
591
+ }else{
592
+ for(let result of queryResult){
593
+ try{
594
+ if(!result.pageContent||typeof result.pageContent!=='string')continue;
595
+ if(result.pageContent.trim().split(/\s+/).length<=this.targetSummarisedStringTokenCount){
596
+ summaries.push(result.pageContent);
597
+ continue;
598
+ }
599
+ let summarisableSubstringIndices:AICompareCandidates.SummarisableSubstringIndices={
600
+ start:0,
601
+ end:result.pageContent.length
602
+ };
603
+ if(getSummarisableSubstringIndices)Object.assign(summarisableSubstringIndices,getSummarisableSubstringIndices(result.pageContent));
604
+ summarisableSubstringIndices.start=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.start),0,result.pageContent.length);
605
+ summarisableSubstringIndices.end=lodash.clamp(lodash.toSafeInteger(summarisableSubstringIndices.end),0,result.pageContent.length);
606
+ if(this.DEBUG)console.log(summarisableSubstringIndices);
607
+ let summarisableSubstring=result.pageContent.substring(summarisableSubstringIndices.start,summarisableSubstringIndices.end);
608
+ if(this.DEBUG)console.log(summarisableSubstring);
609
+ let contentBefore=result.pageContent.substring(0,summarisableSubstringIndices.start);
610
+ let contentAfter=result.pageContent.substring(summarisableSubstringIndices.end);
611
+ let wordsWithoutSummarisable=contentBefore.split(/\s+/).length+contentAfter.split(/\s+/).length;
612
+ let targetSummarisedSubstringTokenCount=Math.max(1,this.targetSummarisedStringTokenCount-wordsWithoutSummarisable);
613
+ if(this.DEBUG)console.log(wordsWithoutSummarisable,targetSummarisedSubstringTokenCount);
614
+ let summarisedSubstringArray=await this.summariser?.(summarisableSubstring,<TextGenerationConfig>{
615
+ max_length:targetSummarisedSubstringTokenCount
616
+ });
617
+ let summarisedSubstring=Array.isArray(summarisedSubstringArray?.[0])?summarisedSubstringArray?.[0]?.[0]:summarisedSubstringArray?.[0];
618
+ if(this.DEBUG)console.log(summarisedSubstringArray,summarisedSubstring,summarisedSubstring?.summary_text??'',(summarisedSubstring?.summary_text??'').split(/\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' '));
619
+ let summarisedString=contentBefore+(summarisedSubstring?.summary_text??'').split(/\s+/).slice(0,targetSummarisedSubstringTokenCount).join(' ').trim()+contentAfter;
620
+ if(this.DEBUG)console.log('Summarised candidate: '+summarisedString);
621
+ summaries.push(summarisedString);
622
+ }catch(error){
623
+ console.log(error);
624
+ }
625
+ }
626
+ }
589
627
  }else{
590
628
  summaries=queryResult.map(result=>result.pageContent);
591
629
  }
@@ -695,6 +733,7 @@ export namespace AICompareCandidates{
695
733
  getSummarisableSubstringIndices?:(candidateDocument:string)=>SummarisableSubstringIndices;
696
734
  generatePromptTemplate?:(prompt:string)=>string;
697
735
  skipRationale?:boolean;
736
+ parallelSummarisation?:boolean;
698
737
  };
699
738
 
700
739
  export interface PerformGenerationArguments{