@ax-llm/ax 10.0.29 → 10.0.30

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/index.cjs CHANGED
@@ -796,11 +796,11 @@ var logChatRequest = (req) => {
796
796
  return `${colorLog.blueBright("System:")}
797
797
  ${colorLog.whiteBright(msg.content)}`;
798
798
  case "function":
799
- return `${colorLog.blueBright("Function Result:")}
799
+ return `${colorLog.blueBright("\nFunction Result:")}
800
800
  ${colorLog.whiteBright(msg.result)}`;
801
801
  case "user": {
802
802
  if (typeof msg.content === "string") {
803
- return `${colorLog.blueBright("User:")}
803
+ return `${colorLog.blueBright("\nUser:")}
804
804
  ${colorLog.whiteBright(msg.content)}`;
805
805
  }
806
806
  const items2 = msg.content.map((v) => {
@@ -813,7 +813,7 @@ ${colorLog.whiteBright(msg.content)}`;
813
813
  throw new Error("Invalid content type");
814
814
  }
815
815
  });
816
- return `${colorLog.blueBright("User:")}
816
+ return `${colorLog.blueBright("\nUser:")}
817
817
  ${items2.join("\n")}`;
818
818
  }
819
819
  case "assistant": {
@@ -822,10 +822,10 @@ ${items2.join("\n")}`;
822
822
  const args = typeof fn.params !== "string" ? JSON.stringify(fn.params, null, 2) : fn.params;
823
823
  return `${fn.name}(${args})`;
824
824
  });
825
- return `${colorLog.blueBright("Functions:")}
825
+ return `${colorLog.blueBright("\nFunctions:")}
826
826
  ${colorLog.whiteBright(fns.join("\n"))}`;
827
827
  }
828
- return `${colorLog.blueBright("Assistant:")}
828
+ return `${colorLog.blueBright("\nAssistant:")}
829
829
  ${colorLog.whiteBright(msg.content ?? "<empty>")}`;
830
830
  }
831
831
  default:
@@ -4101,6 +4101,15 @@ var AxProgram = class {
4101
4101
  };
4102
4102
 
4103
4103
  // dsp/prompt.ts
4104
+ var formattingRules = `
4105
+ When providing responses:
4106
+ 1. Only output the exact requested content - no additional text, commentary, explanations, or clarifications
4107
+ 2. Each key's value must strictly adhere to the formatting rules specified in the reference documentation
4108
+ 3. Follow all formatting conventions precisely as defined
4109
+ 4. Do not add any extra content beyond what is explicitly requested
4110
+ 5. Match the exact structure and format specifications for each field
4111
+ 6. No preamble, postscript, or supplementary information
4112
+ 7. Pure output only - conforming exactly to the documented requirements`;
4104
4113
  var AxPromptTemplate = class {
4105
4114
  sig;
4106
4115
  fieldTemplates;
@@ -4113,22 +4122,17 @@ var AxPromptTemplate = class {
4113
4122
  const task = [
4114
4123
  `You will be provided with the following fields: ${inArgs}. Your task is to generate two new fields: ${outArgs}.`
4115
4124
  ];
4116
- const fnNames = functions?.map((f) => {
4117
- if ("toFunction" in f) {
4118
- return f.toFunction().name;
4119
- }
4120
- return f.name;
4121
- });
4122
- const funcList = fnNames?.map((fname) => `\`${fname}\``).join(", ");
4125
+ const funcs = functions?.map(
4126
+ (f) => "toFunction" in f ? f.toFunction() : f
4127
+ );
4128
+ const funcList = funcs?.map((fn) => `\`${fn.name}\`: ${capitalizeFirstLetter(fn.description)}`).join("\n");
4123
4129
  if (funcList && funcList.length > 0) {
4130
+ task.push(`## Available Functions
4131
+ ${funcList}`);
4124
4132
  task.push(
4125
- `Complete the task, using the following functions as needed: ${funcList}. Refer to the function descriptions for proper usage. The output field values may be generated by applying these functions if appropriate for the task.`
4133
+ `Complete the task, using the functions defined earlier in this prompt, as needed. The output field values may be generated by applying these functions if appropriate for the task.`
4126
4134
  );
4127
4135
  }
4128
- const desc = this.sig.getDescription();
4129
- if (desc) {
4130
- task.push(capitalizeFirstLetter(desc.endsWith(".") ? desc : desc + "."));
4131
- }
4132
4136
  const inputFields = this.renderFields(this.sig.getInputFields());
4133
4137
  task.push(`## Input Fields
4134
4138
  ${inputFields}`);
@@ -4138,9 +4142,14 @@ ${outputFields}`);
4138
4142
  task.push(
4139
4143
  "Output must be in plain text, with each `key: value` pair on a new line. The format of each `value` should strictly adhere to the formatting instructions for its corresponding `key`, as defined earlier in this prompt."
4140
4144
  );
4141
- task.push(
4142
- "No additional text or formatting is permitted. The specific formatting rules for each key are provided above; ensure the corresponding values follow those rules precisely."
4143
- );
4145
+ task.push(formattingRules);
4146
+ const desc = this.sig.getDescription();
4147
+ if (desc) {
4148
+ task.push(
4149
+ `## TASK DESCRIPTION
4150
+ ${capitalizeFirstLetter(desc.endsWith(".") ? desc : desc + ".")}`
4151
+ );
4152
+ }
4144
4153
  this.task = {
4145
4154
  type: "text",
4146
4155
  text: task.join("\n\n")
@@ -4151,21 +4160,22 @@ ${outputFields}`);
4151
4160
  demos
4152
4161
  }) => {
4153
4162
  const renderedExamples = examples ? [
4154
- { type: "text", text: "\n## Examples:\n" },
4163
+ { type: "text", text: "## Examples:\n" },
4155
4164
  ...this.renderExamples(examples)
4156
4165
  ] : [];
4157
4166
  const renderedDemos = demos ? this.renderDemos(demos) : [];
4158
4167
  const completion = this.renderInputFields(values);
4159
4168
  const allTextExamples = renderedExamples.every((v) => v.type === "text");
4160
4169
  const allTextDemos = renderedDemos.every((v) => v.type === "text");
4170
+ const examplesInSystemPrompt = allTextExamples && allTextDemos;
4161
4171
  let systemContent = this.task.text;
4162
- if (allTextExamples && allTextDemos) {
4172
+ if (examplesInSystemPrompt) {
4163
4173
  const combinedItems = [
4164
- { type: "text", text: this.task.text },
4174
+ { type: "text", text: systemContent + "\n\n" },
4165
4175
  ...renderedExamples,
4166
4176
  ...renderedDemos
4167
4177
  ];
4168
- combinedItems.reduce(combineConsecutiveStrings("\n"), []);
4178
+ combinedItems.reduce(combineConsecutiveStrings(""), []);
4169
4179
  if (combinedItems && combinedItems[0]) {
4170
4180
  systemContent = combinedItems[0].text;
4171
4181
  }
@@ -4174,7 +4184,7 @@ ${outputFields}`);
4174
4184
  role: "system",
4175
4185
  content: systemContent
4176
4186
  };
4177
- const promptList = allTextExamples && allTextDemos ? completion : [...renderedExamples, ...renderedDemos, ...completion];
4187
+ const promptList = examplesInSystemPrompt ? completion : [...renderedExamples, ...renderedDemos, ...completion];
4178
4188
  const prompt = promptList.filter((v) => v !== void 0);
4179
4189
  const userContent = prompt.every((v) => v.type === "text") ? prompt.map((v) => v.text).join("\n") : prompt.reduce(combineConsecutiveStrings("\n"), []);
4180
4190
  const userPrompt = {
@@ -4209,16 +4219,13 @@ ${outputFields}`);
4209
4219
  const renderedItem = [...renderedInputItem, ...renderedOutputItem];
4210
4220
  renderedItem.forEach((v) => {
4211
4221
  if ("text" in v) {
4212
- v.text = v.text;
4222
+ v.text = v.text + "\n";
4213
4223
  }
4214
4224
  if ("image" in v) {
4215
4225
  v.image = v.image;
4216
4226
  }
4217
4227
  list.push(v);
4218
4228
  });
4219
- if (renderedItem.length > 0) {
4220
- list.push({ type: "text", text: "\n" });
4221
- }
4222
4229
  }
4223
4230
  return list;
4224
4231
  };
@@ -4229,23 +4236,20 @@ ${outputFields}`);
4229
4236
  const renderedItem = fields.map((field) => this.renderInField(field, item, true)).filter((v) => v !== void 0).flat();
4230
4237
  renderedItem.slice(0, -1).forEach((v) => {
4231
4238
  if ("text" in v) {
4232
- v.text = v.text;
4239
+ v.text = v.text + "\n";
4233
4240
  }
4234
4241
  if ("image" in v) {
4235
4242
  v.image = v.image;
4236
4243
  }
4237
4244
  list.push(v);
4238
4245
  });
4239
- if (renderedItem.length > 0) {
4240
- list.push({ type: "text", text: "\n" });
4241
- }
4242
4246
  }
4243
4247
  return list;
4244
4248
  };
4245
4249
  renderInputFields = (values) => {
4246
4250
  const renderedItems = this.sig.getInputFields().map((field) => this.renderInField(field, values)).filter((v) => v !== void 0).flat();
4247
4251
  renderedItems.filter((v) => v.type === "text").forEach((v) => {
4248
- v.text = v.text + "\n\n";
4252
+ v.text = v.text + "\n";
4249
4253
  });
4250
4254
  return renderedItems;
4251
4255
  };