modelmix 3.6.4 → 3.6.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 +56 -0
- package/index.js +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -212,6 +212,62 @@ This would replace `article_file_contents` with the entire content of 'article.t
|
|
|
212
212
|
|
|
213
213
|
Both methods allow for flexible content insertion, enabling you to create dynamic and customizable prompts for your AI model interactions.
|
|
214
214
|
|
|
215
|
+
## 🧩 JSON Export Options
|
|
216
|
+
|
|
217
|
+
The `json` method signature includes these options:
|
|
218
|
+
|
|
219
|
+
```javascript
|
|
220
|
+
async json(schemaExample = null, schemaDescription = {}, {
|
|
221
|
+
type = 'json_object',
|
|
222
|
+
addExample = false,
|
|
223
|
+
addSchema = true,
|
|
224
|
+
addNote = false
|
|
225
|
+
} = {})
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Option Details
|
|
229
|
+
|
|
230
|
+
**`addSchema` (default: `true`)**
|
|
231
|
+
- When set to `true`, includes the generated JSON schema in the system prompt
|
|
232
|
+
|
|
233
|
+
**`addExample` (default: `false`)**
|
|
234
|
+
- When set to `true`, adds the example JSON structure to the system prompt
|
|
235
|
+
|
|
236
|
+
**`addNote` (default: `false`)**
|
|
237
|
+
- When set to `true`, adds a technical note about JSON formatting requirements
|
|
238
|
+
- Specifically adds this instruction to the system prompt:
|
|
239
|
+
```
|
|
240
|
+
Output JSON Note: Escape all unescaped double quotes, backslashes, and ASCII control characters inside JSON strings, and ensure the output contains no comments.
|
|
241
|
+
```
|
|
242
|
+
- Helps prevent common JSON parsing errors
|
|
243
|
+
|
|
244
|
+
### Usage Examples
|
|
245
|
+
|
|
246
|
+
```javascript
|
|
247
|
+
// Basic usage with example and note
|
|
248
|
+
const result = await model.json(
|
|
249
|
+
{ name: "John", age: 30, skills: ["JavaScript", "Python"] },
|
|
250
|
+
{ name: "Person's full name", age: "Age in years" },
|
|
251
|
+
{ addExample: true, addNote: true }
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
// Only add the example, skip the technical note
|
|
255
|
+
const result = await model.json(
|
|
256
|
+
{ status: "success", data: [] },
|
|
257
|
+
{},
|
|
258
|
+
{ addExample: true, addNote: false }
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
// Add note for robust JSON parsing
|
|
262
|
+
const result = await model.json(
|
|
263
|
+
{ message: "Hello \"world\"" },
|
|
264
|
+
{},
|
|
265
|
+
{ addNote: true }
|
|
266
|
+
);
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
These options give you fine-grained control over how much guidance you provide to the model for generating properly formatted JSON responses.
|
|
270
|
+
|
|
215
271
|
## 🐛 Enabling Debug Mode
|
|
216
272
|
|
|
217
273
|
To activate debug mode in ModelMix and view detailed request information, follow these two steps:
|
package/index.js
CHANGED
|
@@ -306,7 +306,7 @@ class ModelMix {
|
|
|
306
306
|
return raw.message;
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
async json(schemaExample = null, schemaDescription = {}, { type = 'json_object', addExample = false, addSchema = true } = {}) {
|
|
309
|
+
async json(schemaExample = null, schemaDescription = {}, { type = 'json_object', addExample = false, addSchema = true, addNote = false } = {}) {
|
|
310
310
|
|
|
311
311
|
let options = {
|
|
312
312
|
response_format: { type },
|
|
@@ -321,10 +321,13 @@ class ModelMix {
|
|
|
321
321
|
config.schema = generateJsonSchema(schemaExample, schemaDescription);
|
|
322
322
|
|
|
323
323
|
if (addSchema) {
|
|
324
|
-
config.system += "\nOutput JSON Schema: \n```\n" + JSON.stringify(
|
|
324
|
+
config.system += "\n\nOutput JSON Schema: \n```\n" + JSON.stringify(config.schema) + "\n```";
|
|
325
325
|
}
|
|
326
326
|
if (addExample) {
|
|
327
|
-
config.system += "\nOutput JSON Example: \n```\n" + JSON.stringify(schemaExample) + "\n```";
|
|
327
|
+
config.system += "\n\nOutput JSON Example: \n```\n" + JSON.stringify(schemaExample) + "\n```";
|
|
328
|
+
}
|
|
329
|
+
if (addNote) {
|
|
330
|
+
config.system += `\n\nOutput JSON Note: Escape all unescaped double quotes, backslashes, and ASCII control characters inside JSON strings, and ensure the output contains no comments.`;
|
|
328
331
|
}
|
|
329
332
|
}
|
|
330
333
|
const { message } = await this.execute({ options, config });
|