tomasmcm commited on
Commit
2851004
·
verified ·
1 Parent(s): da0da75

Update TeapotAI.js

Browse files
Files changed (1) hide show
  1. TeapotAI.js +14 -3
TeapotAI.js CHANGED
@@ -1,15 +1,23 @@
1
  import { pipeline, env } from '@huggingface/transformers';
2
 
 
 
3
  class TeapotAI {
4
  /**
5
  * Initializes the TeapotAI class.
6
  * @param {object} options - Configuration options.
7
  * @param {string} [options.modelId='teapotai/teapotllm'] - The Hugging Face model ID.
8
  * @param {boolean} [options.verbose=true] - Whether to print status messages.
 
9
  */
10
- constructor({ modelId = 'teapotai/teapotllm', verbose = false } = {}) {
 
 
 
 
11
  this.modelId = modelId;
12
  this.verbose = verbose;
 
13
  this.generator = null;
14
  this.isInitialized = false;
15
 
@@ -29,7 +37,10 @@ class TeapotAI {
29
  }
30
  try {
31
  if (this.verbose) console.log(`Initializing generator pipeline for model: ${this.modelId}...`);
32
- const pipelineOptions = { model: this.modelId };
 
 
 
33
 
34
  this.generator = await pipeline('text2text-generation', pipelineOptions.model, pipelineOptions);
35
  this.isInitialized = true;
@@ -65,7 +76,7 @@ class TeapotAI {
65
  max_new_tokens: 512,
66
  });
67
 
68
- const generatedText = output[0]?.generated_text ?? "Error: Could not generate text.";
69
  if (this.verbose) console.log("Text generation complete.");
70
  return generatedText;
71
 
 
1
  import { pipeline, env } from '@huggingface/transformers';
2
 
3
+ env.cacheDir = './.cache';
4
+
5
  class TeapotAI {
6
  /**
7
  * Initializes the TeapotAI class.
8
  * @param {object} options - Configuration options.
9
  * @param {string} [options.modelId='teapotai/teapotllm'] - The Hugging Face model ID.
10
  * @param {boolean} [options.verbose=true] - Whether to print status messages.
11
+ * @param {object} [options.pipelineOptions={}] - Additional pipeline options passed to the transformer.
12
  */
13
+ constructor({
14
+ modelId = 'teapotai/teapotllm',
15
+ verbose = false,
16
+ pipelineOptions = {}
17
+ } = {}) {
18
  this.modelId = modelId;
19
  this.verbose = verbose;
20
+ this.pipelineOptions = pipelineOptions;
21
  this.generator = null;
22
  this.isInitialized = false;
23
 
 
37
  }
38
  try {
39
  if (this.verbose) console.log(`Initializing generator pipeline for model: ${this.modelId}...`);
40
+ const pipelineOptions = {
41
+ model: this.modelId,
42
+ ...this.pipelineOptions
43
+ };
44
 
45
  this.generator = await pipeline('text2text-generation', pipelineOptions.model, pipelineOptions);
46
  this.isInitialized = true;
 
76
  max_new_tokens: 512,
77
  });
78
 
79
+ const generatedText = output[0]?.generated_text?.trim() ?? "Error: Could not generate text.";
80
  if (this.verbose) console.log("Text generation complete.");
81
  return generatedText;
82