@ax-llm/ax 11.0.59 → 11.0.60

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) {
@@ -10225,6 +10213,23 @@ var getTopInPercent = (entries, percent = 0.1) => {
10225
10213
  return sortedEntries.slice(0, topTenPercentCount);
10226
10214
  };
10227
10215
 
10216
+ // docs/rewriter.ts
10217
+ var AxDefaultQueryRewriter = class extends AxGen {
10218
+ constructor(options) {
10219
+ 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."
10220
+ query: string -> rewrittenQuery: string`;
10221
+ super(signature, options);
10222
+ }
10223
+ };
10224
+ var AxRewriter = class extends AxGen {
10225
+ constructor(options) {
10226
+ super(
10227
+ '"Rewrite a given text to be clear and concise" original -> rewritten "improved text"',
10228
+ options
10229
+ );
10230
+ }
10231
+ };
10232
+
10228
10233
  // funcs/docker.ts
10229
10234
  var AxDockerSession = class {
10230
10235
  apiUrl;
@@ -11858,15 +11863,6 @@ var AxChainOfThought = class extends AxGen {
11858
11863
  }
11859
11864
  };
11860
11865
 
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
11866
  // dsp/strutil.ts
11871
11867
  var trimNonAlphaNum = (str) => {
11872
11868
  return str.replace(/^\W+|\W+$/g, "");
@@ -13700,20 +13696,16 @@ var AxRAG = class extends AxChainOfThought {
13700
13696
  this.register(this.genQuery);
13701
13697
  }
13702
13698
  async forward(ai, { question }, options) {
13699
+ let hop = 0;
13703
13700
  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]);
13701
+ while (hop < this.maxHops) {
13702
+ const query = await this.genQuery.forward(ai, { context: context3, question });
13703
+ const queryResult = await this.queryFn(query.query);
13704
+ context3 = AxStringUtil.dedup([...context3, queryResult]);
13705
+ hop++;
13715
13706
  }
13716
- return super.forward(ai, { context: context3, question }, options);
13707
+ const res = await super.forward(ai, { context: context3, question }, options);
13708
+ return res;
13717
13709
  }
13718
13710
  };
13719
13711
  // Annotate the CommonJS export names for ESM import in node:
@@ -13804,6 +13796,7 @@ var AxRAG = class extends AxChainOfThought {
13804
13796
  AxPromptTemplate,
13805
13797
  AxRAG,
13806
13798
  AxRateLimiterTokenUsage,
13799
+ AxRewriter,
13807
13800
  AxSignature,
13808
13801
  AxSimpleClassifier,
13809
13802
  AxSimpleClassifierClass,