@ax-llm/ax 11.0.59 → 11.0.61

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
@@ -116,6 +116,7 @@ __export(index_exports, {
116
116
  AxPromptTemplate: () => AxPromptTemplate,
117
117
  AxRAG: () => AxRAG,
118
118
  AxRateLimiterTokenUsage: () => AxRateLimiterTokenUsage,
119
+ AxRewriter: () => AxRewriter,
119
120
  AxSignature: () => AxSignature,
120
121
  AxSimpleClassifier: () => AxSimpleClassifier,
121
122
  AxSimpleClassifierClass: () => AxSimpleClassifierClass,
@@ -6165,24 +6166,11 @@ ${outputFields}`);
6165
6166
  );
6166
6167
  messageContent = userMsgParts.map((part) => part.type === "text" ? part.text : "").join("").trim();
6167
6168
  } else if (message.role === "assistant") {
6168
- const assistantValues = message.values;
6169
- let assistantContentParts = [];
6170
- const outputFields = this.sig.getOutputFields();
6171
- for (const field of outputFields) {
6172
- const value = assistantValues[field.name];
6173
- if (value !== void 0 && value !== null && (typeof value === "string" ? value !== "" : true)) {
6174
- const renderedValue = processValue(field, value);
6175
- assistantContentParts.push(`${field.name}: ${renderedValue}`);
6176
- } else {
6177
- const isThoughtField = field.name === this.thoughtFieldName;
6178
- if (!field.isOptional && !field.isInternal && !isThoughtField) {
6179
- throw new Error(
6180
- `Value for output field '${field.name}' ('${field.title}') is required in assistant message history but was not found or was empty.`
6181
- );
6182
- }
6183
- }
6184
- }
6185
- messageContent = assistantContentParts.join("\n");
6169
+ const assistantMsgParts = this.renderInputFields(
6170
+ message.values
6171
+ // Cast message.values (AxGenIn) to T (which extends AxGenIn)
6172
+ );
6173
+ messageContent = assistantMsgParts.map((part) => part.type === "text" ? part.text : "").join("").trim();
6186
6174
  }
6187
6175
  if (messageContent) {
6188
6176
  if (lastRole === message.role && userMessages.length > 0) {
@@ -8716,9 +8704,21 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
8716
8704
  );
8717
8705
  const originalFunc = processedFunction.func;
8718
8706
  processedFunction.func = async (childArgs, funcOptions) => {
8707
+ let valuesToInject = {};
8708
+ if (Array.isArray(parentValues)) {
8709
+ const lastUserMessage = parentValues.filter((msg) => msg.role === "user").pop();
8710
+ if (lastUserMessage) {
8711
+ valuesToInject = pick(
8712
+ lastUserMessage.values,
8713
+ injectionKeys
8714
+ );
8715
+ }
8716
+ } else {
8717
+ valuesToInject = pick(parentValues, injectionKeys);
8718
+ }
8719
8719
  const updatedChildArgs = {
8720
8720
  ...childArgs,
8721
- ...pick(parentValues, injectionKeys)
8721
+ ...valuesToInject
8722
8722
  };
8723
8723
  if (options.debug && injectionKeys.length > 0) {
8724
8724
  const ai = funcOptions?.ai;
@@ -10225,6 +10225,23 @@ var getTopInPercent = (entries, percent = 0.1) => {
10225
10225
  return sortedEntries.slice(0, topTenPercentCount);
10226
10226
  };
10227
10227
 
10228
+ // docs/rewriter.ts
10229
+ var AxDefaultQueryRewriter = class extends AxGen {
10230
+ constructor(options) {
10231
+ const signature = `"You are a query rewriter assistant tasked with rewriting a given query to improve its clarity, specificity, and relevance. Your role involves analyzing the query to identify any ambiguities, generalizations, or irrelevant information and then rephrasing it to make it more focused and precise. The rewritten query should be concise, easy to understand, and directly related to the original query. Output only the rewritten query."
10232
+ query: string -> rewrittenQuery: string`;
10233
+ super(signature, options);
10234
+ }
10235
+ };
10236
+ var AxRewriter = class extends AxGen {
10237
+ constructor(options) {
10238
+ super(
10239
+ '"Rewrite a given text to be clear and concise" original -> rewritten "improved text"',
10240
+ options
10241
+ );
10242
+ }
10243
+ };
10244
+
10228
10245
  // funcs/docker.ts
10229
10246
  var AxDockerSession = class {
10230
10247
  apiUrl;
@@ -11858,15 +11875,6 @@ var AxChainOfThought = class extends AxGen {
11858
11875
  }
11859
11876
  };
11860
11877
 
11861
- // docs/rewriter.ts
11862
- var AxDefaultQueryRewriter = class extends AxGen {
11863
- constructor(options) {
11864
- const signature = `"You are a query rewriter assistant tasked with rewriting a given query to improve its clarity, specificity, and relevance. Your role involves analyzing the query to identify any ambiguities, generalizations, or irrelevant information and then rephrasing it to make it more focused and precise. The rewritten query should be concise, easy to understand, and directly related to the original query. Output only the rewritten query."
11865
- query: string -> rewrittenQuery: string`;
11866
- super(signature, options);
11867
- }
11868
- };
11869
-
11870
11878
  // dsp/strutil.ts
11871
11879
  var trimNonAlphaNum = (str) => {
11872
11880
  return str.replace(/^\W+|\W+$/g, "");
@@ -13699,21 +13707,27 @@ var AxRAG = class extends AxChainOfThought {
13699
13707
  this.queryFn = queryFn;
13700
13708
  this.register(this.genQuery);
13701
13709
  }
13702
- async forward(ai, { question }, options) {
13710
+ async forward(ai, values, options) {
13711
+ let question;
13712
+ if (Array.isArray(values)) {
13713
+ const lastUserMessage = values.filter((msg) => msg.role === "user").pop();
13714
+ if (!lastUserMessage) {
13715
+ throw new Error("No user message found in values array");
13716
+ }
13717
+ question = lastUserMessage.values.question;
13718
+ } else {
13719
+ question = values.question;
13720
+ }
13721
+ let hop = 0;
13703
13722
  let context3 = [];
13704
- for (let i = 0; i < this.maxHops; i++) {
13705
- const { query } = await this.genQuery.forward(
13706
- ai,
13707
- {
13708
- context: context3,
13709
- question
13710
- },
13711
- options
13712
- );
13713
- const val = await this.queryFn(query);
13714
- context3 = AxStringUtil.dedup([...context3, val]);
13723
+ while (hop < this.maxHops) {
13724
+ const query = await this.genQuery.forward(ai, { context: context3, question });
13725
+ const queryResult = await this.queryFn(query.query);
13726
+ context3 = AxStringUtil.dedup([...context3, queryResult]);
13727
+ hop++;
13715
13728
  }
13716
- return super.forward(ai, { context: context3, question }, options);
13729
+ const res = await super.forward(ai, { context: context3, question }, options);
13730
+ return res;
13717
13731
  }
13718
13732
  };
13719
13733
  // Annotate the CommonJS export names for ESM import in node:
@@ -13804,6 +13818,7 @@ var AxRAG = class extends AxChainOfThought {
13804
13818
  AxPromptTemplate,
13805
13819
  AxRAG,
13806
13820
  AxRateLimiterTokenUsage,
13821
+ AxRewriter,
13807
13822
  AxSignature,
13808
13823
  AxSimpleClassifier,
13809
13824
  AxSimpleClassifierClass,