modelmix 2.4.8 → 2.5.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/README.md +11 -14
- package/demo/demo.mjs +8 -10
- package/index.js +18 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,45 +80,42 @@ Here's a quick example to get you started:
|
|
|
80
80
|
|
|
81
81
|
3. **Generate responses from different models**:
|
|
82
82
|
|
|
83
|
+
#### gpt-4o-mini
|
|
83
84
|
```javascript
|
|
84
|
-
|
|
85
|
-
const gpt = mmix.create('gpt-4o', { temperature: 0.5 });
|
|
85
|
+
const gpt = mmix.create('gpt-4o-mini', { options: { temperature: 0 } });
|
|
86
86
|
gpt.addText("Have you ever eaten a {animal}?");
|
|
87
87
|
gpt.replace({ '{animal}': 'cat' });
|
|
88
88
|
console.log(await gpt.message());
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
#### claude-3-5-sonnet-20240620 (writer)
|
|
91
92
|
```javascript
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
config: { system: "You are a writer like Stephen King" },
|
|
95
|
-
options: { temperature: 0.5 }
|
|
96
|
-
}
|
|
97
|
-
const writer = mmix.create('claude-3-5-sonnet-20240620', setup);
|
|
93
|
+
const writer = mmix.create('claude-3-5-sonnet-20240620', { options: { temperature: 0.5 } });
|
|
94
|
+
writer.setSystem('You are a writer like Stephen King'); // or setSystemFromFile
|
|
98
95
|
writer.replace({ '{story_title}': 'The Mysterious Package' })
|
|
99
96
|
// or write.replaceKeyFromFile('{story_title}', './title.md');
|
|
100
97
|
const story = await writer.addTextFromFile('./prompt.md').message();
|
|
101
98
|
console.log(story);
|
|
102
99
|
```
|
|
103
|
-
|
|
100
|
+
#### claude-3-5-sonnet-20240620 (image)
|
|
104
101
|
```javascript
|
|
105
|
-
console.log("\n" + '--------|
|
|
106
|
-
const claude = mmix.create('claude-3-5-sonnet-20240620', { temperature: 0
|
|
102
|
+
console.log("\n" + '--------| |--------');
|
|
103
|
+
const claude = mmix.create('claude-3-5-sonnet-20240620', { options: { temperature: 0 } });
|
|
107
104
|
claude.addImage("./watson.jpg"); // or claude.addImageFromUrl(url)
|
|
108
105
|
const imageDescription = await claude.addText("Describe the image").message();
|
|
109
106
|
console.log(imageDescription);
|
|
110
107
|
```
|
|
111
108
|
|
|
109
|
+
#### pplx-70b-online
|
|
112
110
|
```javascript
|
|
113
|
-
|
|
114
|
-
const pplx = mmix.create('pplx-70b-online', { max_tokens: 500 });
|
|
111
|
+
const pplx = mmix.create('pplx-70b-online', { config: { max_tokens: 500 } });
|
|
115
112
|
pplx.addText('How much is ETH trading in USD?');
|
|
116
113
|
const news = await pplx.addText('What are the 3 most recent Ethereum news?').message();
|
|
117
114
|
console.log(news);
|
|
118
115
|
```
|
|
119
116
|
|
|
117
|
+
#### ollama (llava:latest)
|
|
120
118
|
```javascript
|
|
121
|
-
console.log("\n" + '--------| ollama (llava:latest) |--------');
|
|
122
119
|
await mmix.create('llava:latest')
|
|
123
120
|
.addImage("./watson.jpg")
|
|
124
121
|
.addText("What is the predominant color?")
|
package/demo/demo.mjs
CHANGED
|
@@ -17,9 +17,10 @@ mmix.attach(new MixOpenAI());
|
|
|
17
17
|
mmix.attach(new MixAnthropic());
|
|
18
18
|
mmix.attach(new MixPerplexity({
|
|
19
19
|
config: {
|
|
20
|
-
apiKey: process.env.PPLX_API_KEY
|
|
20
|
+
apiKey: process.env.PPLX_API_KEY,
|
|
21
|
+
system: 'You are my personal assistant.'
|
|
21
22
|
},
|
|
22
|
-
|
|
23
|
+
|
|
23
24
|
}));
|
|
24
25
|
mmix.attach(new MixOllama({
|
|
25
26
|
config: {
|
|
@@ -33,28 +34,25 @@ mmix.attach(new MixOllama({
|
|
|
33
34
|
mmix.replace({ '{name}': 'ALF' });
|
|
34
35
|
|
|
35
36
|
console.log("\n" + '--------| gpt-4o |--------');
|
|
36
|
-
const gpt = mmix.create('gpt-4o', { temperature: 0
|
|
37
|
+
const gpt = mmix.create('gpt-4o', { options: { temperature: 0 } }).addText("Have you ever eaten a {animal}?");
|
|
37
38
|
gpt.replace({ '{animal}': 'cat' });
|
|
38
39
|
console.log(await gpt.message());
|
|
39
40
|
|
|
40
41
|
console.log("\n" + '--------| claude-3-5-sonnet-20240620 |--------');
|
|
41
|
-
const claude = mmix.create('claude-3-5-sonnet-20240620', { temperature: 0
|
|
42
|
+
const claude = mmix.create('claude-3-5-sonnet-20240620', { options: { temperature: 0 } });
|
|
42
43
|
claude.addImageFromUrl('https://pbs.twimg.com/media/F6-GsjraAAADDGy?format=jpg');
|
|
43
44
|
const imageDescription = await claude.addText('describe the image').message();
|
|
44
45
|
console.log(imageDescription);
|
|
45
46
|
|
|
46
47
|
console.log("\n" + '--------| claude-3-5-sonnet-20240620 |--------');
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
options: { temperature: 0.5 }
|
|
50
|
-
}
|
|
51
|
-
const writer = mmix.create('claude-3-5-sonnet-20240620', setup);
|
|
48
|
+
const writer = mmix.create('claude-3-5-sonnet-20240620', { options: { temperature: 0.5 } });
|
|
49
|
+
writer.setSystem('You are a writer like Stephen King');
|
|
52
50
|
writer.replaceKeyFromFile('{story_title}', './title.md');
|
|
53
51
|
const story = await writer.addTextFromFile('./prompt.md').message();
|
|
54
52
|
console.log(story);
|
|
55
53
|
|
|
56
54
|
console.log("\n" + '--------| llama-3-sonar-large-32k-online |--------');
|
|
57
|
-
const pplx = mmix.create('llama-3-sonar-large-32k-online', { max_tokens: 500 });
|
|
55
|
+
const pplx = mmix.create('llama-3-sonar-large-32k-online', { config: { max_tokens: 500 } });
|
|
58
56
|
pplx.addText('How much is ETH trading in USD?');
|
|
59
57
|
const news = await pplx.addText('What are the 3 most recent Ethereum news?').message();
|
|
60
58
|
console.log(news);
|
package/index.js
CHANGED
|
@@ -133,7 +133,7 @@ class MessageHandler {
|
|
|
133
133
|
console.error(`Error reading system message file ${filePath}:`, error);
|
|
134
134
|
}
|
|
135
135
|
return this;
|
|
136
|
-
}
|
|
136
|
+
}
|
|
137
137
|
|
|
138
138
|
addImage(filePath, config = { role: "user" }) {
|
|
139
139
|
try {
|
|
@@ -245,12 +245,14 @@ class MessageHandler {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
groupByRoles(messages) {
|
|
248
|
-
return messages.reduce((acc,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
248
|
+
return messages.reduce((acc, currentMessage, index) => {
|
|
249
|
+
if (index === 0 || currentMessage.role !== messages[index - 1].role) {
|
|
250
|
+
acc.push({
|
|
251
|
+
role: currentMessage.role,
|
|
252
|
+
content: currentMessage.content
|
|
253
|
+
});
|
|
252
254
|
} else {
|
|
253
|
-
acc.
|
|
255
|
+
acc[acc.length - 1].content = acc[acc.length - 1].content.concat(currentMessage.content);
|
|
254
256
|
}
|
|
255
257
|
return acc;
|
|
256
258
|
}, []);
|
|
@@ -337,9 +339,9 @@ class MixCustom {
|
|
|
337
339
|
async create(args = { config: {}, options: {} }) {
|
|
338
340
|
try {
|
|
339
341
|
if (args.config.debug) {
|
|
340
|
-
log.
|
|
342
|
+
log.debug("config");
|
|
341
343
|
log.info(args.config);
|
|
342
|
-
log.
|
|
344
|
+
log.debug("options");
|
|
343
345
|
log.inspect(args.options);
|
|
344
346
|
}
|
|
345
347
|
|
|
@@ -379,7 +381,7 @@ class MixCustom {
|
|
|
379
381
|
};
|
|
380
382
|
|
|
381
383
|
return formattedError;
|
|
382
|
-
}
|
|
384
|
+
}
|
|
383
385
|
|
|
384
386
|
processStream(response) {
|
|
385
387
|
return new Promise((resolve, reject) => {
|
|
@@ -475,11 +477,11 @@ class MixAnthropic extends MixCustom {
|
|
|
475
477
|
});
|
|
476
478
|
}
|
|
477
479
|
|
|
478
|
-
getDefaultHeaders(
|
|
480
|
+
getDefaultHeaders(customHeaders) {
|
|
479
481
|
return super.getDefaultHeaders({
|
|
480
482
|
'x-api-key': this.config.apiKey,
|
|
481
483
|
'anthropic-version': '2023-06-01',
|
|
482
|
-
...
|
|
484
|
+
...customHeaders
|
|
483
485
|
});
|
|
484
486
|
}
|
|
485
487
|
|
|
@@ -491,6 +493,11 @@ class MixAnthropic extends MixCustom {
|
|
|
491
493
|
processResponse(response) {
|
|
492
494
|
return { response: response.data, message: response.data.content[0].text };
|
|
493
495
|
}
|
|
496
|
+
|
|
497
|
+
create(args = { config: {}, options: {} }) {
|
|
498
|
+
args.options.system = args.config.system;
|
|
499
|
+
return super.create(args);
|
|
500
|
+
}
|
|
494
501
|
}
|
|
495
502
|
|
|
496
503
|
class MixPerplexity extends MixCustom {
|