modelmix 2.4.4 → 2.4.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/README.md +13 -3
- package/index.js +56 -15
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# 🧬 ModelMix: Unified API for Diverse AI
|
|
1
|
+
# 🧬 ModelMix: Unified API for Diverse AI LLM
|
|
2
2
|
|
|
3
3
|
**ModelMix** is a versatile module that enables seamless integration of various language models from different providers through a unified interface. With ModelMix, you can effortlessly manage and utilize multiple AI models while controlling parallel requests to avoid provider restrictions.
|
|
4
4
|
|
|
@@ -82,32 +82,42 @@ Here's a quick example to get you started:
|
|
|
82
82
|
|
|
83
83
|
```javascript
|
|
84
84
|
console.log("\n" + '--------| gpt-4o |--------');
|
|
85
|
-
const gpt = mmix.create('gpt-4o', { temperature: 0.5 })
|
|
85
|
+
const gpt = mmix.create('gpt-4o', { temperature: 0.5 });
|
|
86
|
+
gpt.addText("Have you ever eaten a {animal}?");
|
|
86
87
|
gpt.replace({ '{animal}': 'cat' });
|
|
87
88
|
console.log(await gpt.message());
|
|
89
|
+
```
|
|
88
90
|
|
|
91
|
+
```javascript
|
|
89
92
|
console.log("\n" + '--------| [writer] claude-3-5-sonnet-20240620 |--------');
|
|
90
93
|
const setup = {
|
|
91
94
|
config: { system: "You are a writer like Stephen King" },
|
|
92
95
|
options: { temperature: 0.5 }
|
|
93
96
|
}
|
|
94
97
|
const writer = mmix.create('claude-3-5-sonnet-20240620', setup);
|
|
95
|
-
writer.replace({ '{story_title}': 'The Mysterious Package' })
|
|
98
|
+
writer.replace({ '{story_title}': 'The Mysterious Package' })
|
|
99
|
+
// or write.replaceKeyFromFile('{story_title}', './title.md');
|
|
96
100
|
const story = await writer.addTextFromFile('./prompt.md').message();
|
|
97
101
|
console.log(story);
|
|
102
|
+
```
|
|
98
103
|
|
|
104
|
+
```javascript
|
|
99
105
|
console.log("\n" + '--------| [image] claude-3-5-sonnet-20240620 |--------');
|
|
100
106
|
const claude = mmix.create('claude-3-5-sonnet-20240620', { temperature: 0.5 });
|
|
101
107
|
claude.addImage("./watson.jpg"); // or claude.addImageFromUrl(url)
|
|
102
108
|
const imageDescription = await claude.addText("Describe the image").message();
|
|
103
109
|
console.log(imageDescription);
|
|
110
|
+
```
|
|
104
111
|
|
|
112
|
+
```javascript
|
|
105
113
|
console.log("\n" + '--------| pplx-70b-online |--------');
|
|
106
114
|
const pplx = mmix.create('pplx-70b-online', { max_tokens: 500 });
|
|
107
115
|
pplx.addText('How much is ETH trading in USD?');
|
|
108
116
|
const news = await pplx.addText('What are the 3 most recent Ethereum news?').message();
|
|
109
117
|
console.log(news);
|
|
118
|
+
```
|
|
110
119
|
|
|
120
|
+
```javascript
|
|
111
121
|
console.log("\n" + '--------| ollama (llava:latest) |--------');
|
|
112
122
|
await mmix.create('llava:latest')
|
|
113
123
|
.addImage("./watson.jpg")
|
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.info("config");
|
|
341
|
+
log.info(args.config);
|
|
342
|
+
log.inspect("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
|
+
}
|
|
330
360
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
361
|
+
handleError(error, args) {
|
|
362
|
+
let errorMessage = 'An error occurred in MixCustom';
|
|
363
|
+
let statusCode = null;
|
|
364
|
+
let errorDetails = null;
|
|
365
|
+
|
|
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) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modelmix",
|
|
3
|
-
"version": "2.4.
|
|
4
|
-
"description": "🧬 ModelMix - Unified API for Diverse AI
|
|
3
|
+
"version": "2.4.8",
|
|
4
|
+
"description": "🧬 ModelMix - Unified API for Diverse AI LLM.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -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"
|