@ax-llm/ax 11.0.12 → 11.0.14

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
@@ -4826,12 +4826,12 @@ var AxProgram = class {
4826
4826
 
4827
4827
  // dsp/prompt.ts
4828
4828
  var functionCallInstructions = `
4829
- ### Function Call Instructions
4829
+ ## Function Call Instructions
4830
4830
  - Complete the task, using the functions defined earlier in this prompt.
4831
4831
  - Call functions step-by-step, using the output of one function as input to the next.
4832
4832
  - Use the function results to generate the output fields.`;
4833
4833
  var formattingRules = `
4834
- ### Output Formatting Rules
4834
+ ## Output Formatting Rules
4835
4835
  - Output must strictly follow the defined plain-text \`key: value\` field format.
4836
4836
  - Each output key, value must strictly adhere to the specified output field formatting rules.
4837
4837
  - No preamble, postscript, or supplementary information.
@@ -4845,16 +4845,10 @@ var AxPromptTemplate = class {
4845
4845
  this.sig = sig;
4846
4846
  this.fieldTemplates = fieldTemplates;
4847
4847
  const task = [];
4848
- const desc = this.sig.getDescription();
4849
- if (desc) {
4850
- const capitalized = capitalizeFirstLetter(desc.trim());
4851
- task.push(capitalized.endsWith(".") ? capitalized : capitalized + ".");
4852
- }
4853
4848
  const inArgs = this.renderDescFields(this.sig.getInputFields());
4854
4849
  const outArgs = this.renderDescFields(this.sig.getOutputFields());
4855
4850
  task.push(
4856
- `## Processing Instructions
4857
- You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
4851
+ `You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
4858
4852
  );
4859
4853
  const funcs = functions?.map(
4860
4854
  (f) => "toFunction" in f ? f.toFunction() : f
@@ -4863,19 +4857,26 @@ You will be provided with the following fields: ${inArgs}. Your task is to gener
4863
4857
  (fn) => `- \`${fn.name}\`: ${capitalizeFirstLetter(fn.description)}.`
4864
4858
  ).join("\n");
4865
4859
  if (funcList && funcList.length > 0) {
4866
- task.push(`### Available Functions
4860
+ task.push(`## Available Functions
4867
4861
  ${funcList}`);
4868
4862
  }
4869
4863
  const inputFields = this.renderFields(this.sig.getInputFields());
4870
- task.push(`### Input Fields
4864
+ task.push(`## Input Fields
4871
4865
  ${inputFields}`);
4872
4866
  const outputFields = this.renderFields(this.sig.getOutputFields());
4873
- task.push(`### Output Fields
4867
+ task.push(`## Output Fields
4874
4868
  ${outputFields}`);
4875
4869
  if (funcList && funcList.length > 0) {
4876
4870
  task.push(functionCallInstructions.trim());
4877
4871
  }
4878
4872
  task.push(formattingRules.trim());
4873
+ const desc = this.sig.getDescription();
4874
+ if (desc) {
4875
+ const capitalized = capitalizeFirstLetter(desc.trim());
4876
+ const text = capitalized.endsWith(".") ? capitalized : capitalized + ".";
4877
+ task.push(`---
4878
+ ${text}`);
4879
+ }
4879
4880
  this.task = {
4880
4881
  type: "text",
4881
4882
  text: task.join("\n\n")
@@ -5120,7 +5121,7 @@ ${outputFields}`);
5120
5121
  const type = field.type?.name ? toFieldType(field.type) : "string";
5121
5122
  const required = field.isOptional ? "optional" : "required";
5122
5123
  const description = field.description ? `: ${capitalizeFirstLetter(field.description)}` : "";
5123
- return `- \`${name}\` (${type}, ${required})${description}.`.trim();
5124
+ return `- \`${name}:\` (${type}, ${required}) ${description}.`.trim();
5124
5125
  });
5125
5126
  return rows.join("\n");
5126
5127
  };
@@ -5219,8 +5220,8 @@ var ValidationError = class extends Error {
5219
5220
  getFixingInstructions = () => {
5220
5221
  return this.fields.map((field) => ({
5221
5222
  name: "outputError",
5222
- title: "Errors In Output Fields",
5223
- description: `Please fix and return the field \`${field.title}\` of type \`${toFieldType(field.type)}\`, ${this.message}.`
5223
+ title: "Output Correction Required",
5224
+ description: `The section labeled '${field.title}' either was not generated by the LLM or does not match the expected format of '${toFieldType(field.type)}'. ${this.message} Please revise your response to ensure it conforms to the specified format.`
5224
5225
  }));
5225
5226
  };
5226
5227
  };
@@ -5817,7 +5818,7 @@ var AxGen = class extends AxProgramWithSignature {
5817
5818
  mem,
5818
5819
  options
5819
5820
  }) {
5820
- const { sessionId, traceId, model, functions } = options ?? {};
5821
+ const { sessionId, traceId, model, functions, earlyFail } = options ?? {};
5821
5822
  const usageInfo = {
5822
5823
  ai: ai.getName(),
5823
5824
  model: ai.getModelInfo().name
@@ -5836,7 +5837,8 @@ var AxGen = class extends AxProgramWithSignature {
5836
5837
  mem,
5837
5838
  traceId,
5838
5839
  sessionId,
5839
- functions
5840
+ functions,
5841
+ earlyFail
5840
5842
  });
5841
5843
  } else {
5842
5844
  yield await this.processResponse({
@@ -5859,9 +5861,10 @@ var AxGen = class extends AxProgramWithSignature {
5859
5861
  mem,
5860
5862
  sessionId,
5861
5863
  traceId,
5862
- functions
5864
+ functions,
5865
+ earlyFail
5863
5866
  }) {
5864
- const streamingValidation = ai.getFeatures().functionCot !== true;
5867
+ const streamingValidation = earlyFail ?? ai.getFeatures().functionCot !== true;
5865
5868
  const functionCalls = [];
5866
5869
  const values = {};
5867
5870
  const xstate = {