@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.d.cts CHANGED
@@ -1374,6 +1374,7 @@ type AxProgramForwardOptions = {
1374
1374
  functions?: AxFunction[];
1375
1375
  functionCall?: AxChatRequest['functionCall'];
1376
1376
  stopFunction?: string;
1377
+ earlyFail?: boolean;
1377
1378
  };
1378
1379
  type AxProgramStreamingForwardOptions = Omit<AxProgramForwardOptions, 'stream'>;
1379
1380
  type AxGenDeltaOut<OUT> = {
@@ -1576,6 +1577,7 @@ interface AxResponseHandlerArgs<T> {
1576
1577
  sessionId?: string;
1577
1578
  traceId?: string;
1578
1579
  functions?: Readonly<AxFunction[]>;
1580
+ earlyFail?: boolean;
1579
1581
  }
1580
1582
  interface AxStreamingEvent<T> {
1581
1583
  event: 'delta' | 'done' | 'error';
package/index.d.ts CHANGED
@@ -1374,6 +1374,7 @@ type AxProgramForwardOptions = {
1374
1374
  functions?: AxFunction[];
1375
1375
  functionCall?: AxChatRequest['functionCall'];
1376
1376
  stopFunction?: string;
1377
+ earlyFail?: boolean;
1377
1378
  };
1378
1379
  type AxProgramStreamingForwardOptions = Omit<AxProgramForwardOptions, 'stream'>;
1379
1380
  type AxGenDeltaOut<OUT> = {
@@ -1576,6 +1577,7 @@ interface AxResponseHandlerArgs<T> {
1576
1577
  sessionId?: string;
1577
1578
  traceId?: string;
1578
1579
  functions?: Readonly<AxFunction[]>;
1580
+ earlyFail?: boolean;
1579
1581
  }
1580
1582
  interface AxStreamingEvent<T> {
1581
1583
  event: 'delta' | 'done' | 'error';
package/index.js CHANGED
@@ -4724,12 +4724,12 @@ var AxProgram = class {
4724
4724
 
4725
4725
  // dsp/prompt.ts
4726
4726
  var functionCallInstructions = `
4727
- ### Function Call Instructions
4727
+ ## Function Call Instructions
4728
4728
  - Complete the task, using the functions defined earlier in this prompt.
4729
4729
  - Call functions step-by-step, using the output of one function as input to the next.
4730
4730
  - Use the function results to generate the output fields.`;
4731
4731
  var formattingRules = `
4732
- ### Output Formatting Rules
4732
+ ## Output Formatting Rules
4733
4733
  - Output must strictly follow the defined plain-text \`key: value\` field format.
4734
4734
  - Each output key, value must strictly adhere to the specified output field formatting rules.
4735
4735
  - No preamble, postscript, or supplementary information.
@@ -4743,16 +4743,10 @@ var AxPromptTemplate = class {
4743
4743
  this.sig = sig;
4744
4744
  this.fieldTemplates = fieldTemplates;
4745
4745
  const task = [];
4746
- const desc = this.sig.getDescription();
4747
- if (desc) {
4748
- const capitalized = capitalizeFirstLetter(desc.trim());
4749
- task.push(capitalized.endsWith(".") ? capitalized : capitalized + ".");
4750
- }
4751
4746
  const inArgs = this.renderDescFields(this.sig.getInputFields());
4752
4747
  const outArgs = this.renderDescFields(this.sig.getOutputFields());
4753
4748
  task.push(
4754
- `## Processing Instructions
4755
- You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
4749
+ `You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
4756
4750
  );
4757
4751
  const funcs = functions?.map(
4758
4752
  (f) => "toFunction" in f ? f.toFunction() : f
@@ -4761,19 +4755,26 @@ You will be provided with the following fields: ${inArgs}. Your task is to gener
4761
4755
  (fn) => `- \`${fn.name}\`: ${capitalizeFirstLetter(fn.description)}.`
4762
4756
  ).join("\n");
4763
4757
  if (funcList && funcList.length > 0) {
4764
- task.push(`### Available Functions
4758
+ task.push(`## Available Functions
4765
4759
  ${funcList}`);
4766
4760
  }
4767
4761
  const inputFields = this.renderFields(this.sig.getInputFields());
4768
- task.push(`### Input Fields
4762
+ task.push(`## Input Fields
4769
4763
  ${inputFields}`);
4770
4764
  const outputFields = this.renderFields(this.sig.getOutputFields());
4771
- task.push(`### Output Fields
4765
+ task.push(`## Output Fields
4772
4766
  ${outputFields}`);
4773
4767
  if (funcList && funcList.length > 0) {
4774
4768
  task.push(functionCallInstructions.trim());
4775
4769
  }
4776
4770
  task.push(formattingRules.trim());
4771
+ const desc = this.sig.getDescription();
4772
+ if (desc) {
4773
+ const capitalized = capitalizeFirstLetter(desc.trim());
4774
+ const text = capitalized.endsWith(".") ? capitalized : capitalized + ".";
4775
+ task.push(`---
4776
+ ${text}`);
4777
+ }
4777
4778
  this.task = {
4778
4779
  type: "text",
4779
4780
  text: task.join("\n\n")
@@ -5018,7 +5019,7 @@ ${outputFields}`);
5018
5019
  const type = field.type?.name ? toFieldType(field.type) : "string";
5019
5020
  const required = field.isOptional ? "optional" : "required";
5020
5021
  const description = field.description ? `: ${capitalizeFirstLetter(field.description)}` : "";
5021
- return `- \`${name}\` (${type}, ${required})${description}.`.trim();
5022
+ return `- \`${name}:\` (${type}, ${required}) ${description}.`.trim();
5022
5023
  });
5023
5024
  return rows.join("\n");
5024
5025
  };
@@ -5117,8 +5118,8 @@ var ValidationError = class extends Error {
5117
5118
  getFixingInstructions = () => {
5118
5119
  return this.fields.map((field) => ({
5119
5120
  name: "outputError",
5120
- title: "Errors In Output Fields",
5121
- description: `Please fix and return the field \`${field.title}\` of type \`${toFieldType(field.type)}\`, ${this.message}.`
5121
+ title: "Output Correction Required",
5122
+ 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.`
5122
5123
  }));
5123
5124
  };
5124
5125
  };
@@ -5715,7 +5716,7 @@ var AxGen = class extends AxProgramWithSignature {
5715
5716
  mem,
5716
5717
  options
5717
5718
  }) {
5718
- const { sessionId, traceId, model, functions } = options ?? {};
5719
+ const { sessionId, traceId, model, functions, earlyFail } = options ?? {};
5719
5720
  const usageInfo = {
5720
5721
  ai: ai.getName(),
5721
5722
  model: ai.getModelInfo().name
@@ -5734,7 +5735,8 @@ var AxGen = class extends AxProgramWithSignature {
5734
5735
  mem,
5735
5736
  traceId,
5736
5737
  sessionId,
5737
- functions
5738
+ functions,
5739
+ earlyFail
5738
5740
  });
5739
5741
  } else {
5740
5742
  yield await this.processResponse({
@@ -5757,9 +5759,10 @@ var AxGen = class extends AxProgramWithSignature {
5757
5759
  mem,
5758
5760
  sessionId,
5759
5761
  traceId,
5760
- functions
5762
+ functions,
5763
+ earlyFail
5761
5764
  }) {
5762
- const streamingValidation = ai.getFeatures().functionCot !== true;
5765
+ const streamingValidation = earlyFail ?? ai.getFeatures().functionCot !== true;
5763
5766
  const functionCalls = [];
5764
5767
  const values = {};
5765
5768
  const xstate = {