modelmix 3.0.8 → 3.1.0
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/index.js +24 -12
- package/package.json +1 -1
- package/schema.js +9 -6
package/index.js
CHANGED
|
@@ -24,6 +24,7 @@ class ModelMix {
|
|
|
24
24
|
|
|
25
25
|
this.config = {
|
|
26
26
|
system: 'You are an assistant.',
|
|
27
|
+
systemExtra: '',
|
|
27
28
|
max_history: 1, // Default max history
|
|
28
29
|
debug: false,
|
|
29
30
|
bottleneck: defaultBottleneckConfig,
|
|
@@ -237,16 +238,19 @@ class MessageHandler {
|
|
|
237
238
|
this.options.response_format = { type: "json_object" };
|
|
238
239
|
if (schemaExample) {
|
|
239
240
|
const schema = generateJsonSchema(schemaExample, schemaDescription);
|
|
240
|
-
this.
|
|
241
|
+
this.config.systemExtra = "\nOutput JSON Schema: \n```\n" + JSON.stringify(schema) + "\n```";
|
|
241
242
|
}
|
|
242
|
-
|
|
243
|
+
const response = await this.message();
|
|
244
|
+
this.config.systemExtra = "";
|
|
245
|
+
return JSON.parse(response);
|
|
243
246
|
}
|
|
244
247
|
|
|
245
248
|
async block({ addText = true } = {}) {
|
|
246
249
|
if (addText) {
|
|
247
|
-
this.
|
|
250
|
+
this.config.systemExtra = "\nOutput results between triple backtick block code tags: \n```\n";
|
|
248
251
|
}
|
|
249
252
|
const response = await this.message();
|
|
253
|
+
this.config.systemExtra = "";
|
|
250
254
|
const block = response.match(/```(?:\w+)?\s*([\s\S]*?)```/);
|
|
251
255
|
return block ? block[1].trim() : response;
|
|
252
256
|
}
|
|
@@ -315,6 +319,7 @@ class MessageHandler {
|
|
|
315
319
|
async prepareMessages() {
|
|
316
320
|
await this.processImageUrls();
|
|
317
321
|
this.applyTemplate();
|
|
322
|
+
this.messages = this.messages.slice(-this.config.max_history);
|
|
318
323
|
this.messages = this.groupByRoles(this.messages);
|
|
319
324
|
this.options.messages = this.messages;
|
|
320
325
|
}
|
|
@@ -331,7 +336,6 @@ class MessageHandler {
|
|
|
331
336
|
try {
|
|
332
337
|
const result = await this.modelEntry.create({ options: this.options, config: this.config });
|
|
333
338
|
this.messages.push({ role: "assistant", content: result.message });
|
|
334
|
-
this.messages = this.messages.slice(-this.config.max_history);
|
|
335
339
|
return result;
|
|
336
340
|
} catch (error) {
|
|
337
341
|
// If there are fallback models available, try the next one
|
|
@@ -359,6 +363,7 @@ class MessageHandler {
|
|
|
359
363
|
|
|
360
364
|
// Keep same system and replacements
|
|
361
365
|
nextHandler.setSystem(this.config.system);
|
|
366
|
+
nextHandler.config.systemExtra = this.config.systemExtra;
|
|
362
367
|
if (this.config.replace) {
|
|
363
368
|
nextHandler.replace(this.config.replace);
|
|
364
369
|
}
|
|
@@ -527,7 +532,8 @@ class MixOpenAI extends MixCustom {
|
|
|
527
532
|
delete args.options.temperature;
|
|
528
533
|
}
|
|
529
534
|
|
|
530
|
-
|
|
535
|
+
const content = args.config.system + args.config.systemExtra;
|
|
536
|
+
args.options.messages = [{ role: 'system', content }, ...args.options.messages || []];
|
|
531
537
|
args.options.messages = MixOpenAI.convertMessages(args.options.messages);
|
|
532
538
|
return super.create(args);
|
|
533
539
|
}
|
|
@@ -568,7 +574,7 @@ class MixAnthropic extends MixCustom {
|
|
|
568
574
|
throw new Error('Anthropic API key not found. Please provide it in config or set ANTHROPIC_API_KEY environment variable.');
|
|
569
575
|
}
|
|
570
576
|
|
|
571
|
-
args.options.system = args.config.system;
|
|
577
|
+
args.options.system = args.config.system + args.config.systemExtra;
|
|
572
578
|
return super.create(args);
|
|
573
579
|
}
|
|
574
580
|
|
|
@@ -605,7 +611,8 @@ class MixPerplexity extends MixCustom {
|
|
|
605
611
|
throw new Error('Perplexity API key not found. Please provide it in config or set PPLX_API_KEY environment variable.');
|
|
606
612
|
}
|
|
607
613
|
|
|
608
|
-
|
|
614
|
+
const content = args.config.system + args.config.systemExtra;
|
|
615
|
+
args.options.messages = [{ role: 'system', content }, ...args.options.messages || []];
|
|
609
616
|
return super.create(args);
|
|
610
617
|
}
|
|
611
618
|
}
|
|
@@ -633,7 +640,8 @@ class MixOllama extends MixCustom {
|
|
|
633
640
|
create(args = { config: {}, options: {} }) {
|
|
634
641
|
|
|
635
642
|
args.options.messages = MixOllama.convertMessages(args.options.messages);
|
|
636
|
-
|
|
643
|
+
const content = args.config.system + args.config.systemExtra;
|
|
644
|
+
args.options.messages = [{ role: 'system', content }, ...args.options.messages || []];
|
|
637
645
|
return super.create(args);
|
|
638
646
|
}
|
|
639
647
|
|
|
@@ -683,7 +691,8 @@ class MixLMStudio extends MixCustom {
|
|
|
683
691
|
}
|
|
684
692
|
|
|
685
693
|
create(args = { config: {}, options: {} }) {
|
|
686
|
-
|
|
694
|
+
const content = args.config.system + args.config.systemExtra;
|
|
695
|
+
args.options.messages = [{ role: 'system', content }, ...args.options.messages || []];
|
|
687
696
|
args.options.messages = MixOpenAI.convertMessages(args.options.messages);
|
|
688
697
|
return super.create(args);
|
|
689
698
|
}
|
|
@@ -704,7 +713,8 @@ class MixGroq extends MixCustom {
|
|
|
704
713
|
throw new Error('Groq API key not found. Please provide it in config or set GROQ_API_KEY environment variable.');
|
|
705
714
|
}
|
|
706
715
|
|
|
707
|
-
|
|
716
|
+
const content = args.config.system + args.config.systemExtra;
|
|
717
|
+
args.options.messages = [{ role: 'system', content }, ...args.options.messages || []];
|
|
708
718
|
args.options.messages = MixOpenAI.convertMessages(args.options.messages);
|
|
709
719
|
return super.create(args);
|
|
710
720
|
}
|
|
@@ -741,7 +751,8 @@ class MixTogether extends MixCustom {
|
|
|
741
751
|
throw new Error('Together API key not found. Please provide it in config or set TOGETHER_API_KEY environment variable.');
|
|
742
752
|
}
|
|
743
753
|
|
|
744
|
-
|
|
754
|
+
const content = args.config.system + args.config.systemExtra;
|
|
755
|
+
args.options.messages = [{ role: 'system', content }, ...args.options.messages || []];
|
|
745
756
|
args.options.messages = MixTogether.convertMessages(args.options.messages);
|
|
746
757
|
|
|
747
758
|
return super.create(args);
|
|
@@ -759,7 +770,8 @@ class MixCerebras extends MixCustom {
|
|
|
759
770
|
}
|
|
760
771
|
|
|
761
772
|
create(args = { config: {}, options: {} }) {
|
|
762
|
-
|
|
773
|
+
const content = args.config.system + args.config.systemExtra;
|
|
774
|
+
args.options.messages = [{ role: 'system', content }, ...args.options.messages || []];
|
|
763
775
|
args.options.messages = MixTogether.convertMessages(args.options.messages);
|
|
764
776
|
return super.create(args);
|
|
765
777
|
}
|
package/package.json
CHANGED
package/schema.js
CHANGED
|
@@ -26,17 +26,18 @@ function generateJsonSchema(example, descriptions = {}) {
|
|
|
26
26
|
return schema;
|
|
27
27
|
}
|
|
28
28
|
if (Array.isArray(value)) {
|
|
29
|
-
if (value.length
|
|
30
|
-
|
|
29
|
+
if (value.length === 0) {
|
|
30
|
+
return { type: 'array', items: {} };
|
|
31
|
+
}
|
|
32
|
+
if (typeof value[0] === 'object' && !Array.isArray(value[0])) {
|
|
31
33
|
return {
|
|
32
34
|
type: 'array',
|
|
33
35
|
items: generateJsonSchema(value[0], descriptions[key] || {})
|
|
34
36
|
};
|
|
35
37
|
} else {
|
|
36
|
-
// Es un array de valores simples
|
|
37
38
|
return {
|
|
38
39
|
type: 'array',
|
|
39
|
-
items:
|
|
40
|
+
items: detectType(key, value[0])
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -47,10 +48,12 @@ function generateJsonSchema(example, descriptions = {}) {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
if (Array.isArray(example)) {
|
|
50
|
-
|
|
51
|
+
if (example.length === 0) {
|
|
52
|
+
return { type: 'array', items: {} };
|
|
53
|
+
}
|
|
51
54
|
return {
|
|
52
55
|
type: 'array',
|
|
53
|
-
items:
|
|
56
|
+
items: detectType('', example[0])
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
|