modelmix 2.9.2 → 2.9.4
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/demo/grok.mjs +4 -5
- package/index.js +25 -9
- package/package.json +1 -1
package/demo/grok.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'dotenv/config'
|
|
2
2
|
|
|
3
|
-
import { ModelMix, MixGrok, MixAnthropic } from '../index.js';
|
|
3
|
+
import { ModelMix, MixGrok, MixAnthropic, MixOpenAI } from '../index.js';
|
|
4
4
|
|
|
5
5
|
const mmix = new ModelMix({
|
|
6
6
|
options: {
|
|
@@ -12,8 +12,7 @@ const mmix = new ModelMix({
|
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
mmix.attach(new MixGrok());
|
|
16
|
-
mmix.attach(new MixAnthropic());
|
|
15
|
+
mmix.attach(new MixGrok(), new MixAnthropic(), new MixOpenAI());
|
|
17
16
|
|
|
18
|
-
const r = await mmix.create(['
|
|
19
|
-
console.log(r)
|
|
17
|
+
const r = await mmix.create(['claude-3-7-sonnet-20250219', 'o3-mini', 'grok-2-latest']).addText('do you like cats?').message();
|
|
18
|
+
console.log(r);
|
package/index.js
CHANGED
|
@@ -37,9 +37,11 @@ class ModelMix {
|
|
|
37
37
|
return this;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
attach(
|
|
41
|
-
const
|
|
42
|
-
|
|
40
|
+
attach(...modelInstances) {
|
|
41
|
+
for (const modelInstance of modelInstances) {
|
|
42
|
+
const key = modelInstance.config.prefix.join("_");
|
|
43
|
+
this.models[key] = modelInstance;
|
|
44
|
+
}
|
|
43
45
|
return this;
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -315,15 +317,29 @@ class MessageHandler {
|
|
|
315
317
|
const nextModelKey = this.fallbackModels[0];
|
|
316
318
|
log.warn(`Model ${this.options.model} failed, trying fallback model ${nextModelKey}...`);
|
|
317
319
|
|
|
318
|
-
// Create new handler with
|
|
319
|
-
const nextHandler = this.mix.create(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
320
|
+
// Create a completely new handler with the fallback model
|
|
321
|
+
const nextHandler = this.mix.create(
|
|
322
|
+
[nextModelKey, ...this.fallbackModels.slice(1)],
|
|
323
|
+
{
|
|
324
|
+
options: {
|
|
325
|
+
// Keep only generic options, not model-specific ones
|
|
326
|
+
max_tokens: this.options.max_tokens,
|
|
327
|
+
temperature: this.options.temperature,
|
|
328
|
+
top_p: this.options.top_p,
|
|
329
|
+
stream: this.options.stream
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
);
|
|
323
333
|
|
|
324
|
-
//
|
|
334
|
+
// Asignar directamente todos los mensajes
|
|
325
335
|
nextHandler.messages = [...this.messages];
|
|
326
336
|
|
|
337
|
+
// Mantener el mismo sistema y reemplazos
|
|
338
|
+
nextHandler.setSystem(this.config.system);
|
|
339
|
+
if (this.config.replace) {
|
|
340
|
+
nextHandler.replace(this.config.replace);
|
|
341
|
+
}
|
|
342
|
+
|
|
327
343
|
// Try with next model
|
|
328
344
|
return nextHandler.execute();
|
|
329
345
|
}
|