File tree 1 file changed +26
-3
lines changed
packages/plugin-node/src/services
1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -486,9 +486,32 @@ export class LlamaService extends Service {
486
486
throw new Error ( "Model not initialized. Call initialize() first." ) ;
487
487
}
488
488
489
- const embeddingContext = await this . model . createEmbeddingContext ( ) ;
490
- const embedding = await embeddingContext . getEmbeddingFor ( input ) ;
491
- return embedding ?. vector ? [ ...embedding . vector ] : undefined ;
489
+ const ollamaModel = process . env . OLLAMA_MODEL ;
490
+ const ollamaUrl =
491
+ process . env . OLLAMA_SERVER_URL || "http://localhost:11434" ;
492
+ const embeddingModel =
493
+ process . env . OLLAMA_EMBEDDING_MODEL || "mxbai-embed-large" ;
494
+ elizaLogger . info (
495
+ `Using Ollama API for embeddings with model ${ embeddingModel } (base: ${ ollamaModel } )`
496
+ ) ;
497
+
498
+ const response = await fetch ( `${ ollamaUrl } /api/embeddings` , {
499
+ method : "POST" ,
500
+ headers : {
501
+ "Content-Type" : "application/json" ,
502
+ } ,
503
+ body : JSON . stringify ( {
504
+ input : input ,
505
+ model : embeddingModel ,
506
+ } ) ,
507
+ } ) ;
508
+
509
+ if ( ! response . ok ) {
510
+ throw new Error ( `Failed to get embedding: ${ response . statusText } ` ) ;
511
+ }
512
+
513
+ const embedding = await response . json ( ) ;
514
+ return embedding . vector ;
492
515
}
493
516
}
494
517
You can’t perform that action at this time.
0 commit comments