modelmix 3.0.4 → 3.0.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.
Files changed (2) hide show
  1. package/index.js +5 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -237,7 +237,7 @@ class MessageHandler {
237
237
  this.options.response_format = { type: "json_object" };
238
238
  if (schemaExample) {
239
239
  const schema = generateJsonSchema(schemaExample, schemaDescription);
240
- this.addText("Output expected JSON Schema: \n```\n" + JSON.stringify(schema, null, 2) + "\n```");
240
+ this.addText("Output expected JSON Schema: \n```\n" + JSON.stringify(schema) + "\n```");
241
241
  }
242
242
  return JSON.parse(await this.message());
243
243
  }
@@ -315,7 +315,6 @@ class MessageHandler {
315
315
  async prepareMessages() {
316
316
  await this.processImageUrls();
317
317
  this.applyTemplate();
318
- this.messages = this.messages.slice(-this.config.max_history);
319
318
  this.messages = this.groupByRoles(this.messages);
320
319
  this.options.messages = this.messages;
321
320
  }
@@ -332,6 +331,7 @@ class MessageHandler {
332
331
  try {
333
332
  const result = await this.modelEntry.create({ options: this.options, config: this.config });
334
333
  this.messages.push({ role: "assistant", content: result.message });
334
+ this.messages = this.messages.slice(-this.config.max_history);
335
335
  return result;
336
336
  } catch (error) {
337
337
  // If there are fallback models available, try the next one
@@ -727,7 +727,7 @@ class MixTogether extends MixCustom {
727
727
  };
728
728
  }
729
729
 
730
- convertMessages(messages) {
730
+ static convertMessages(messages) {
731
731
  return messages.map(message => {
732
732
  if (message.content instanceof Array) {
733
733
  message.content = message.content.map(content => content.text).join("\n\n");
@@ -742,7 +742,7 @@ class MixTogether extends MixCustom {
742
742
  }
743
743
 
744
744
  args.options.messages = [{ role: 'system', content: args.config.system }, ...args.options.messages || []];
745
- args.options.messages = this.convertMessages(args.options.messages);
745
+ args.options.messages = MixTogether.convertMessages(args.options.messages);
746
746
 
747
747
  return super.create(args);
748
748
  }
@@ -760,6 +760,7 @@ class MixCerebras extends MixCustom {
760
760
 
761
761
  create(args = { config: {}, options: {} }) {
762
762
  args.options.messages = [{ role: 'system', content: args.config.system }, ...args.options.messages || []];
763
+ args.options.messages = MixTogether.convertMessages(args.options.messages);
763
764
  return super.create(args);
764
765
  }
765
766
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modelmix",
3
- "version": "3.0.4",
3
+ "version": "3.0.8",
4
4
  "description": "🧬 ModelMix - Unified API for Diverse AI LLM.",
5
5
  "main": "index.js",
6
6
  "repository": {