modelmix 2.4.2 → 2.4.6
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 +89 -79
- package/package.json +2 -2
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")
|
|
@@ -115,7 +125,82 @@ Here's a quick example to get you started:
|
|
|
115
125
|
.stream((data) => { console.log(data.message); });
|
|
116
126
|
```
|
|
117
127
|
4. Find the files for this example at: [/ModelMix/demo](https://github.com/clasen/ModelMix/tree/master/demo).
|
|
118
|
-
|
|
128
|
+
|
|
129
|
+
## 🔄 Templating Methods
|
|
130
|
+
|
|
131
|
+
### `replace` Method
|
|
132
|
+
|
|
133
|
+
The `replace` method is used to define key-value pairs for text replacement in the messages and system prompt.
|
|
134
|
+
|
|
135
|
+
#### Usage:
|
|
136
|
+
```javascript
|
|
137
|
+
gpt.replace({ '{{key1}}': 'value1', '{{key2}}': 'value2' });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### How it works:
|
|
141
|
+
1. It updates the `config.replace` object with the provided key-value pairs.
|
|
142
|
+
2. In the template, placeholders like `{{key1}}` will be replaced with 'value1'.
|
|
143
|
+
|
|
144
|
+
#### Example:
|
|
145
|
+
```javascript
|
|
146
|
+
gpt
|
|
147
|
+
.replace({ '{{name}}': 'Alice', '{{age}}': '30' })
|
|
148
|
+
.addText('Hello {{name}}, are you {{age}} years old?');
|
|
149
|
+
```
|
|
150
|
+
This would result in the message: "Hello Alice, are you 30 years old?"
|
|
151
|
+
|
|
152
|
+
### `replaceKeyFromFile` Method
|
|
153
|
+
|
|
154
|
+
The `replaceKeyFromFile` method is similar to `replace`, but it reads the replacement value from a file.
|
|
155
|
+
|
|
156
|
+
#### Usage:
|
|
157
|
+
```javascript
|
|
158
|
+
messageHandler.replaceKeyFromFile('longText', './path/to/file.txt');
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### How it works:
|
|
162
|
+
1. It reads the content of the specified file synchronously.
|
|
163
|
+
2. It then calls the `replace` method, using the provided key and the file content as the value.
|
|
164
|
+
|
|
165
|
+
#### Example:
|
|
166
|
+
```javascript
|
|
167
|
+
messageHandler
|
|
168
|
+
.replaceKeyFromFile('article_file_contents', './article.txt')
|
|
169
|
+
.addText('Please summarize this article: article_file_contents');
|
|
170
|
+
```
|
|
171
|
+
This would replace `article_file_contents` with the entire content of 'article.txt'.
|
|
172
|
+
|
|
173
|
+
### When to use each method:
|
|
174
|
+
- Use `replace` for short, inline replacements or dynamically generated content.
|
|
175
|
+
- Use `replaceKeyFromFile` for longer texts or content that's stored externally.
|
|
176
|
+
|
|
177
|
+
Both methods allow for flexible content insertion, enabling you to create dynamic and customizable prompts for your AI model interactions.
|
|
178
|
+
|
|
179
|
+
## 🐛 Enabling Debug Mode
|
|
180
|
+
|
|
181
|
+
To activate debug mode in ModelMix and view detailed request information, follow these two steps:
|
|
182
|
+
|
|
183
|
+
1. In the ModelMix constructor, include `debug: true` in the configuration:
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
const mix = new ModelMix({
|
|
187
|
+
config: {
|
|
188
|
+
debug: true
|
|
189
|
+
// ... other configuration options ...
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
2. When running your script from the command line, use the `DEBUG=ModelMix*` prefix:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
DEBUG=ModelMix* node your_script.js
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
When you run your script this way, you'll see detailed information about the requests in the console, including the configuration and options used for each AI model request.
|
|
201
|
+
|
|
202
|
+
This information is valuable for debugging and understanding how ModelMix is processing your requests.
|
|
203
|
+
|
|
119
204
|
## 📚 ModelMix Class Overview
|
|
120
205
|
|
|
121
206
|
```javascript
|
|
@@ -234,81 +319,6 @@ new MixLMStudio(args = { config: {}, options: {} })
|
|
|
234
319
|
- `url`: The endpoint URL to which the model sends requests.
|
|
235
320
|
- **options**: Default options for Ollama model instances.
|
|
236
321
|
|
|
237
|
-
## Explanation of `replace` and `replaceKeyFromFile` Methods
|
|
238
|
-
|
|
239
|
-
### `replace` Method
|
|
240
|
-
|
|
241
|
-
The `replace` method is used to define key-value pairs for text replacement in the messages and system prompt.
|
|
242
|
-
|
|
243
|
-
#### Usage:
|
|
244
|
-
```javascript
|
|
245
|
-
gpt.replace({ '{{key1}}': 'value1', '{{key2}}': 'value2' });
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
#### How it works:
|
|
249
|
-
- It updates the `config.replace` object with the provided key-value pairs.
|
|
250
|
-
- In the template, placeholders like `{{key1}}` will be replaced with 'value1'.
|
|
251
|
-
|
|
252
|
-
#### Example:
|
|
253
|
-
```javascript
|
|
254
|
-
gpt
|
|
255
|
-
.replace({ '{{name}}': 'Alice', '{{age}}': '30' })
|
|
256
|
-
.addText('Hello {{name}}, are you {{age}} years old?');
|
|
257
|
-
```
|
|
258
|
-
This would result in the message: "Hello Alice, are you 30 years old?"
|
|
259
|
-
|
|
260
|
-
### `replaceKeyFromFile` Method
|
|
261
|
-
|
|
262
|
-
The `replaceKeyFromFile` method is similar to `replace`, but it reads the replacement value from a file.
|
|
263
|
-
|
|
264
|
-
#### Usage:
|
|
265
|
-
```javascript
|
|
266
|
-
messageHandler.replaceKeyFromFile('longText', './path/to/file.txt');
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
#### How it works:
|
|
270
|
-
1. It reads the content of the specified file synchronously.
|
|
271
|
-
2. It then calls the `replace` method, using the provided key and the file content as the value.
|
|
272
|
-
|
|
273
|
-
#### Example:
|
|
274
|
-
```javascript
|
|
275
|
-
messageHandler
|
|
276
|
-
.replaceKeyFromFile('article_file_contents', './article.txt')
|
|
277
|
-
.addText('Please summarize this article: article_file_contents');
|
|
278
|
-
```
|
|
279
|
-
This would replace `article_file_contents` with the entire content of 'article.txt'.
|
|
280
|
-
|
|
281
|
-
### When to use each method:
|
|
282
|
-
- Use `replace` for short, inline replacements or dynamically generated content.
|
|
283
|
-
- Use `replaceKeyFromFile` for longer texts or content that's stored externally.
|
|
284
|
-
|
|
285
|
-
Both methods allow for flexible content insertion, enabling you to create dynamic and customizable prompts for your AI model interactions.
|
|
286
|
-
|
|
287
|
-
## Enabling Debug Mode in ModelMix
|
|
288
|
-
|
|
289
|
-
To activate debug mode in ModelMix and view detailed request information, follow these two steps:
|
|
290
|
-
|
|
291
|
-
1. In the ModelMix constructor, include `debug: true` in the configuration:
|
|
292
|
-
|
|
293
|
-
```javascript
|
|
294
|
-
const mix = new ModelMix({
|
|
295
|
-
config: {
|
|
296
|
-
debug: true
|
|
297
|
-
// ... other configuration options ...
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
2. When running your script from the command line, use the `DEBUG=ModelMix*` prefix:
|
|
303
|
-
|
|
304
|
-
```
|
|
305
|
-
DEBUG=ModelMix* node your_script.js
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
When you run your script this way, you'll see detailed information about the requests in the console, including the configuration and options used for each AI model request.
|
|
309
|
-
|
|
310
|
-
This information is valuable for debugging and understanding how ModelMix is processing your requests.
|
|
311
|
-
|
|
312
322
|
## 🤝 Contributing
|
|
313
323
|
|
|
314
324
|
Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the [GitHub repository](https://github.com/clasen/ModelMix).
|
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.6",
|
|
4
|
+
"description": "🧬 ModelMix - Unified API for Diverse AI LLM.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|