@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.js CHANGED
@@ -6003,24 +6003,11 @@ ${outputFields}`);
6003
6003
  );
6004
6004
  messageContent = userMsgParts.map((part) => part.type === "text" ? part.text : "").join("").trim();
6005
6005
  } else if (message.role === "assistant") {
6006
- const assistantValues = message.values;
6007
- let assistantContentParts = [];
6008
- const outputFields = this.sig.getOutputFields();
6009
- for (const field of outputFields) {
6010
- const value = assistantValues[field.name];
6011
- if (value !== void 0 && value !== null && (typeof value === "string" ? value !== "" : true)) {
6012
- const renderedValue = processValue(field, value);
6013
- assistantContentParts.push(`${field.name}: ${renderedValue}`);
6014
- } else {
6015
- const isThoughtField = field.name === this.thoughtFieldName;
6016
- if (!field.isOptional && !field.isInternal && !isThoughtField) {
6017
- throw new Error(
6018
- `Value for output field '${field.name}' ('${field.title}') is required in assistant message history but was not found or was empty.`
6019
- );
6020
- }
6021
- }
6022
- }
6023
- messageContent = assistantContentParts.join("\n");
6006
+ const assistantMsgParts = this.renderInputFields(
6007
+ message.values
6008
+ // Cast message.values (AxGenIn) to T (which extends AxGenIn)
6009
+ );
6010
+ messageContent = assistantMsgParts.map((part) => part.type === "text" ? part.text : "").join("").trim();
6024
6011
  }
6025
6012
  if (messageContent) {
6026
6013
  if (lastRole === message.role && userMessages.length > 0) {
@@ -10063,6 +10050,23 @@ var getTopInPercent = (entries, percent = 0.1) => {
10063
10050
  return sortedEntries.slice(0, topTenPercentCount);
10064
10051
  };
10065
10052
 
10053
+ // docs/rewriter.ts
10054
+ var AxDefaultQueryRewriter = class extends AxGen {
10055
+ constructor(options) {
10056
+ 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."
10057
+ query: string -> rewrittenQuery: string`;
10058
+ super(signature, options);
10059
+ }
10060
+ };
10061
+ var AxRewriter = class extends AxGen {
10062
+ constructor(options) {
10063
+ super(
10064
+ '"Rewrite a given text to be clear and concise" original -> rewritten "improved text"',
10065
+ options
10066
+ );
10067
+ }
10068
+ };
10069
+
10066
10070
  // funcs/docker.ts
10067
10071
  var AxDockerSession = class {
10068
10072
  apiUrl;
@@ -11696,15 +11700,6 @@ var AxChainOfThought = class extends AxGen {
11696
11700
  }
11697
11701
  };
11698
11702
 
11699
- // docs/rewriter.ts
11700
- var AxDefaultQueryRewriter = class extends AxGen {
11701
- constructor(options) {
11702
- 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."
11703
- query: string -> rewrittenQuery: string`;
11704
- super(signature, options);
11705
- }
11706
- };
11707
-
11708
11703
  // dsp/strutil.ts
11709
11704
  var trimNonAlphaNum = (str) => {
11710
11705
  return str.replace(/^\W+|\W+$/g, "");
@@ -13538,20 +13533,16 @@ var AxRAG = class extends AxChainOfThought {
13538
13533
  this.register(this.genQuery);
13539
13534
  }
13540
13535
  async forward(ai, { question }, options) {
13536
+ let hop = 0;
13541
13537
  let context3 = [];
13542
- for (let i = 0; i < this.maxHops; i++) {
13543
- const { query } = await this.genQuery.forward(
13544
- ai,
13545
- {
13546
- context: context3,
13547
- question
13548
- },
13549
- options
13550
- );
13551
- const val = await this.queryFn(query);
13552
- context3 = AxStringUtil.dedup([...context3, val]);
13538
+ while (hop < this.maxHops) {
13539
+ const query = await this.genQuery.forward(ai, { context: context3, question });
13540
+ const queryResult = await this.queryFn(query.query);
13541
+ context3 = AxStringUtil.dedup([...context3, queryResult]);
13542
+ hop++;
13553
13543
  }
13554
- return super.forward(ai, { context: context3, question }, options);
13544
+ const res = await super.forward(ai, { context: context3, question }, options);
13545
+ return res;
13555
13546
  }
13556
13547
  };
13557
13548
  export {
@@ -13641,6 +13632,7 @@ export {
13641
13632
  AxPromptTemplate,
13642
13633
  AxRAG,
13643
13634
  AxRateLimiterTokenUsage,
13635
+ AxRewriter,
13644
13636
  AxSignature,
13645
13637
  AxSimpleClassifier,
13646
13638
  AxSimpleClassifierClass,