modelmix 2.9.2 → 2.9.8
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/custom.mjs +3 -3
- package/demo/grok.mjs +4 -5
- package/index.js +44 -11
- package/package.json +5 -3
package/demo/custom.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'dotenv/config'
|
|
2
2
|
|
|
3
|
-
import { ModelMix,
|
|
3
|
+
import { ModelMix, MixCerebras, MixTogether } from '../index.js';
|
|
4
4
|
|
|
5
5
|
const mmix = new ModelMix({
|
|
6
6
|
options: {
|
|
@@ -13,8 +13,8 @@ const mmix = new ModelMix({
|
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
mmix.attach(new
|
|
16
|
+
mmix.attach(new MixCerebras());
|
|
17
17
|
|
|
18
|
-
let r = mmix.create('
|
|
18
|
+
let r = mmix.create('llama-4-scout-17b-16e-instruct').addText('what is the capital of the moon?');
|
|
19
19
|
r = await r.addText('do you like cats?').message();
|
|
20
20
|
console.log(r);
|
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
|
|
|
@@ -314,16 +316,31 @@ class MessageHandler {
|
|
|
314
316
|
if (this.fallbackModels.length > 0) {
|
|
315
317
|
const nextModelKey = this.fallbackModels[0];
|
|
316
318
|
log.warn(`Model ${this.options.model} failed, trying fallback model ${nextModelKey}...`);
|
|
319
|
+
log.warn(error.details);
|
|
320
|
+
|
|
321
|
+
// Create a completely new handler with the fallback model
|
|
322
|
+
const nextHandler = this.mix.create(
|
|
323
|
+
[nextModelKey, ...this.fallbackModels.slice(1)],
|
|
324
|
+
{
|
|
325
|
+
options: {
|
|
326
|
+
// Keep only generic options, not model-specific ones
|
|
327
|
+
max_tokens: this.options.max_tokens,
|
|
328
|
+
temperature: this.options.temperature,
|
|
329
|
+
top_p: this.options.top_p,
|
|
330
|
+
stream: this.options.stream
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
);
|
|
317
334
|
|
|
318
|
-
//
|
|
319
|
-
const nextHandler = this.mix.create(nextModelKey, {
|
|
320
|
-
options: this.options,
|
|
321
|
-
config: this.config
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
// Copy current messages to new handler
|
|
335
|
+
// Asignar directamente todos los mensajes
|
|
325
336
|
nextHandler.messages = [...this.messages];
|
|
326
337
|
|
|
338
|
+
// Mantener el mismo sistema y reemplazos
|
|
339
|
+
nextHandler.setSystem(this.config.system);
|
|
340
|
+
if (this.config.replace) {
|
|
341
|
+
nextHandler.replace(this.config.replace);
|
|
342
|
+
}
|
|
343
|
+
|
|
327
344
|
// Try with next model
|
|
328
345
|
return nextHandler.execute();
|
|
329
346
|
}
|
|
@@ -703,4 +720,20 @@ class MixTogether extends MixCustom {
|
|
|
703
720
|
}
|
|
704
721
|
}
|
|
705
722
|
|
|
706
|
-
|
|
723
|
+
class MixCerebras extends MixCustom {
|
|
724
|
+
getDefaultConfig(customConfig) {
|
|
725
|
+
return super.getDefaultConfig({
|
|
726
|
+
url: 'https://api.cerebras.ai/v1/chat/completions',
|
|
727
|
+
prefix: ["llama"],
|
|
728
|
+
apiKey: process.env.CEREBRAS_API_KEY,
|
|
729
|
+
...customConfig
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
create(args = { config: {}, options: {} }) {
|
|
734
|
+
args.options.messages = [{ role: 'system', content: args.config.system }, ...args.options.messages || []];
|
|
735
|
+
return super.create(args);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
module.exports = { MixCustom, ModelMix, MixAnthropic, MixOpenAI, MixPerplexity, MixOllama, MixLMStudio, MixGroq, MixTogether, MixGrok, MixCerebras };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modelmix",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.8",
|
|
4
4
|
"description": "🧬 ModelMix - Unified API for Diverse AI LLM.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -31,11 +31,13 @@
|
|
|
31
31
|
"deepseek",
|
|
32
32
|
"fallback",
|
|
33
33
|
"o3",
|
|
34
|
-
"o3-mini",
|
|
34
|
+
"o3-mini",
|
|
35
35
|
"nousresearch",
|
|
36
36
|
"reasoning",
|
|
37
37
|
"bottleneck",
|
|
38
38
|
"claude-3-7-sonnet",
|
|
39
|
+
"cerebras",
|
|
40
|
+
"scout",
|
|
39
41
|
"clasen"
|
|
40
42
|
],
|
|
41
43
|
"author": "Martin Clasen",
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
},
|
|
46
48
|
"homepage": "https://github.com/clasen/ModelMix#readme",
|
|
47
49
|
"dependencies": {
|
|
48
|
-
"axios": "^1.
|
|
50
|
+
"axios": "^1.8.4",
|
|
49
51
|
"bottleneck": "^2.19.5",
|
|
50
52
|
"lemonlog": "^1.1.2"
|
|
51
53
|
}
|