modelmix 2.4.6 → 2.5.2
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 +63 -17
- package/package.json +2 -2
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
|
@@ -120,6 +120,21 @@ class MessageHandler {
|
|
|
120
120
|
return this;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
setSystem(text) {
|
|
124
|
+
this.config.system = text;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
setSystemFromFile(filePath) {
|
|
129
|
+
try {
|
|
130
|
+
const content = fs.readFileSync(filePath, { encoding: 'utf8' });
|
|
131
|
+
this.setSystem(content);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error(`Error reading system message file ${filePath}:`, error);
|
|
134
|
+
}
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
|
|
123
138
|
addImage(filePath, config = { role: "user" }) {
|
|
124
139
|
try {
|
|
125
140
|
const imageBuffer = fs.readFileSync(filePath);
|
|
@@ -320,25 +335,51 @@ class MixCustom {
|
|
|
320
335
|
}
|
|
321
336
|
|
|
322
337
|
async create(args = { config: {}, options: {} }) {
|
|
338
|
+
try {
|
|
339
|
+
if (args.config.debug) {
|
|
340
|
+
log.debug("config");
|
|
341
|
+
log.info(args.config);
|
|
342
|
+
log.debug("options");
|
|
343
|
+
log.inspect(args.options);
|
|
344
|
+
}
|
|
323
345
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
346
|
+
if (args.options.stream) {
|
|
347
|
+
return this.processStream(await axios.post(this.config.url, args.options, {
|
|
348
|
+
headers: this.headers,
|
|
349
|
+
responseType: 'stream'
|
|
350
|
+
}));
|
|
351
|
+
} else {
|
|
352
|
+
return this.processResponse(await axios.post(this.config.url, args.options, {
|
|
353
|
+
headers: this.headers
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
} catch (error) {
|
|
357
|
+
throw this.handleError(error, args);
|
|
329
358
|
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
handleError(error, args) {
|
|
362
|
+
let errorMessage = 'An error occurred in MixCustom';
|
|
363
|
+
let statusCode = null;
|
|
364
|
+
let errorDetails = null;
|
|
330
365
|
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}));
|
|
336
|
-
} else {
|
|
337
|
-
return this.processResponse(await axios.post(this.config.url, args.options, {
|
|
338
|
-
headers: this.headers
|
|
339
|
-
}));
|
|
366
|
+
if (error.isAxiosError) {
|
|
367
|
+
statusCode = error.response ? error.response.status : null;
|
|
368
|
+
errorMessage = `Request to ${this.config.url} failed with status code ${statusCode}`;
|
|
369
|
+
errorDetails = error.response ? error.response.data : null;
|
|
340
370
|
}
|
|
341
|
-
|
|
371
|
+
|
|
372
|
+
const formattedError = {
|
|
373
|
+
message: errorMessage,
|
|
374
|
+
statusCode,
|
|
375
|
+
details: errorDetails,
|
|
376
|
+
stack: error.stack,
|
|
377
|
+
config: args.config,
|
|
378
|
+
options: args.options
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
return formattedError;
|
|
382
|
+
}
|
|
342
383
|
|
|
343
384
|
processStream(response) {
|
|
344
385
|
return new Promise((resolve, reject) => {
|
|
@@ -434,11 +475,11 @@ class MixAnthropic extends MixCustom {
|
|
|
434
475
|
});
|
|
435
476
|
}
|
|
436
477
|
|
|
437
|
-
getDefaultHeaders(
|
|
478
|
+
getDefaultHeaders(customHeaders) {
|
|
438
479
|
return super.getDefaultHeaders({
|
|
439
480
|
'x-api-key': this.config.apiKey,
|
|
440
481
|
'anthropic-version': '2023-06-01',
|
|
441
|
-
...
|
|
482
|
+
...customHeaders
|
|
442
483
|
});
|
|
443
484
|
}
|
|
444
485
|
|
|
@@ -450,6 +491,11 @@ class MixAnthropic extends MixCustom {
|
|
|
450
491
|
processResponse(response) {
|
|
451
492
|
return { response: response.data, message: response.data.content[0].text };
|
|
452
493
|
}
|
|
494
|
+
|
|
495
|
+
create(args = { config: {}, options: {} }) {
|
|
496
|
+
args.options.system = args.config.system;
|
|
497
|
+
return super.create(args);
|
|
498
|
+
}
|
|
453
499
|
}
|
|
454
500
|
|
|
455
501
|
class MixPerplexity extends MixCustom {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modelmix",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"description": "🧬 ModelMix - Unified API for Diverse AI LLM.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"chat",
|
|
25
25
|
"multimodal",
|
|
26
26
|
"groq",
|
|
27
|
-
"
|
|
27
|
+
"gpt-4o-mini",
|
|
28
28
|
"4o",
|
|
29
29
|
"ollama",
|
|
30
30
|
"lmstudio"
|