Remove unessesary convertions

This commit is contained in:
kwaroran
2024-04-24 20:29:10 +09:00
parent 2eb27a2dde
commit acf72727b6
2 changed files with 17 additions and 26 deletions

View File

@@ -51,14 +51,13 @@ export const runSummarizer = async (text: string) => {
let extractor:FeatureExtractionPipeline = null
type EmbeddingModel = 'Xenova/all-MiniLM-L6-v2'|'nomic-ai/nomic-embed-text-v1.5'
export const runEmbedding = async (text: string, model:EmbeddingModel = 'Xenova/all-MiniLM-L6-v2'):Promise<Float32Array> => {
export const runEmbedding = async (texts: string[], model:EmbeddingModel = 'Xenova/all-MiniLM-L6-v2'):Promise<Float32Array[]> => {
await initTransformers()
if(!extractor){
extractor = await pipeline('feature-extraction', model);
}
const tokenizer = await AutoTokenizer.from_pretrained(model);
let result = await extractor(text, { pooling: 'mean', normalize: true });
return (result?.data as Float32Array) ?? null;
let result = await extractor(texts, { pooling: 'mean', normalize: true });
return (result.data as Float32Array[]) ?? null;
}
export const runImageEmbedding = async (dataurl:string) => {