modelmix 3.1.0 → 3.1.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.
Files changed (2) hide show
  1. package/index.js +19 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -234,25 +234,34 @@ class MessageHandler {
234
234
  return response.message;
235
235
  }
236
236
 
237
- async json(schemaExample = null, schemaDescription = {}) {
238
- this.options.response_format = { type: "json_object" };
237
+ async json(schemaExample = null, schemaDescription = {}, { type = 'json_object', addExample = false } = {}) {
238
+ this.options.response_format = { type };
239
239
  if (schemaExample) {
240
240
  const schema = generateJsonSchema(schemaExample, schemaDescription);
241
241
  this.config.systemExtra = "\nOutput JSON Schema: \n```\n" + JSON.stringify(schema) + "\n```";
242
+
243
+ if (addExample) {
244
+ this.config.systemExtra += "\nOutput Example: \n```\n" + JSON.stringify(schemaExample) + "\n```";
245
+ }
242
246
  }
243
247
  const response = await this.message();
244
248
  this.config.systemExtra = "";
245
- return JSON.parse(response);
249
+ console.log(response);
250
+ return JSON.parse(this._extractBlock(response));
246
251
  }
247
252
 
248
- async block({ addText = true } = {}) {
249
- if (addText) {
250
- this.config.systemExtra = "\nOutput results between triple backtick block code tags: \n```\n";
253
+ _extractBlock(response) {
254
+ const block = response.match(/```(?:\w+)?\s*([\s\S]*?)```/);
255
+ return block ? block[1].trim() : response;
256
+ }
257
+
258
+ async block({ addSystemExtra = true } = {}) {
259
+ if (addSystemExtra) {
260
+ this.config.systemExtra = "\nReturn the result of the task between triple backtick block code tags ```";
251
261
  }
252
262
  const response = await this.message();
253
263
  this.config.systemExtra = "";
254
- const block = response.match(/```(?:\w+)?\s*([\s\S]*?)```/);
255
- return block ? block[1].trim() : response;
264
+ return this._extractBlock(response);
256
265
  }
257
266
 
258
267
  async raw() {
@@ -574,6 +583,8 @@ class MixAnthropic extends MixCustom {
574
583
  throw new Error('Anthropic API key not found. Please provide it in config or set ANTHROPIC_API_KEY environment variable.');
575
584
  }
576
585
 
586
+ delete args.options.response_format;
587
+
577
588
  args.options.system = args.config.system + args.config.systemExtra;
578
589
  return super.create(args);
579
590
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modelmix",
3
- "version": "3.1.0",
3
+ "version": "3.1.6",
4
4
  "description": "🧬 ModelMix - Unified API for Diverse AI LLM.",
5
5
  "main": "index.js",
6
6
  "repository": {