@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 +56 -41
- package/index.cjs.map +1 -1
- package/index.d.cts +243 -250
- package/index.d.ts +243 -250
- package/index.js +55 -41
- package/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
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) {
|
|
@@ -8554,9 +8541,21 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
|
|
|
8554
8541
|
);
|
|
8555
8542
|
const originalFunc = processedFunction.func;
|
|
8556
8543
|
processedFunction.func = async (childArgs, funcOptions) => {
|
|
8544
|
+
let valuesToInject = {};
|
|
8545
|
+
if (Array.isArray(parentValues)) {
|
|
8546
|
+
const lastUserMessage = parentValues.filter((msg) => msg.role === "user").pop();
|
|
8547
|
+
if (lastUserMessage) {
|
|
8548
|
+
valuesToInject = pick(
|
|
8549
|
+
lastUserMessage.values,
|
|
8550
|
+
injectionKeys
|
|
8551
|
+
);
|
|
8552
|
+
}
|
|
8553
|
+
} else {
|
|
8554
|
+
valuesToInject = pick(parentValues, injectionKeys);
|
|
8555
|
+
}
|
|
8557
8556
|
const updatedChildArgs = {
|
|
8558
8557
|
...childArgs,
|
|
8559
|
-
...
|
|
8558
|
+
...valuesToInject
|
|
8560
8559
|
};
|
|
8561
8560
|
if (options.debug && injectionKeys.length > 0) {
|
|
8562
8561
|
const ai = funcOptions?.ai;
|
|
@@ -10063,6 +10062,23 @@ var getTopInPercent = (entries, percent = 0.1) => {
|
|
|
10063
10062
|
return sortedEntries.slice(0, topTenPercentCount);
|
|
10064
10063
|
};
|
|
10065
10064
|
|
|
10065
|
+
// docs/rewriter.ts
|
|
10066
|
+
var AxDefaultQueryRewriter = class extends AxGen {
|
|
10067
|
+
constructor(options) {
|
|
10068
|
+
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."
|
|
10069
|
+
query: string -> rewrittenQuery: string`;
|
|
10070
|
+
super(signature, options);
|
|
10071
|
+
}
|
|
10072
|
+
};
|
|
10073
|
+
var AxRewriter = class extends AxGen {
|
|
10074
|
+
constructor(options) {
|
|
10075
|
+
super(
|
|
10076
|
+
'"Rewrite a given text to be clear and concise" original -> rewritten "improved text"',
|
|
10077
|
+
options
|
|
10078
|
+
);
|
|
10079
|
+
}
|
|
10080
|
+
};
|
|
10081
|
+
|
|
10066
10082
|
// funcs/docker.ts
|
|
10067
10083
|
var AxDockerSession = class {
|
|
10068
10084
|
apiUrl;
|
|
@@ -11696,15 +11712,6 @@ var AxChainOfThought = class extends AxGen {
|
|
|
11696
11712
|
}
|
|
11697
11713
|
};
|
|
11698
11714
|
|
|
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
11715
|
// dsp/strutil.ts
|
|
11709
11716
|
var trimNonAlphaNum = (str) => {
|
|
11710
11717
|
return str.replace(/^\W+|\W+$/g, "");
|
|
@@ -13537,21 +13544,27 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
13537
13544
|
this.queryFn = queryFn;
|
|
13538
13545
|
this.register(this.genQuery);
|
|
13539
13546
|
}
|
|
13540
|
-
async forward(ai,
|
|
13547
|
+
async forward(ai, values, options) {
|
|
13548
|
+
let question;
|
|
13549
|
+
if (Array.isArray(values)) {
|
|
13550
|
+
const lastUserMessage = values.filter((msg) => msg.role === "user").pop();
|
|
13551
|
+
if (!lastUserMessage) {
|
|
13552
|
+
throw new Error("No user message found in values array");
|
|
13553
|
+
}
|
|
13554
|
+
question = lastUserMessage.values.question;
|
|
13555
|
+
} else {
|
|
13556
|
+
question = values.question;
|
|
13557
|
+
}
|
|
13558
|
+
let hop = 0;
|
|
13541
13559
|
let context3 = [];
|
|
13542
|
-
|
|
13543
|
-
const
|
|
13544
|
-
|
|
13545
|
-
|
|
13546
|
-
|
|
13547
|
-
question
|
|
13548
|
-
},
|
|
13549
|
-
options
|
|
13550
|
-
);
|
|
13551
|
-
const val = await this.queryFn(query);
|
|
13552
|
-
context3 = AxStringUtil.dedup([...context3, val]);
|
|
13560
|
+
while (hop < this.maxHops) {
|
|
13561
|
+
const query = await this.genQuery.forward(ai, { context: context3, question });
|
|
13562
|
+
const queryResult = await this.queryFn(query.query);
|
|
13563
|
+
context3 = AxStringUtil.dedup([...context3, queryResult]);
|
|
13564
|
+
hop++;
|
|
13553
13565
|
}
|
|
13554
|
-
|
|
13566
|
+
const res = await super.forward(ai, { context: context3, question }, options);
|
|
13567
|
+
return res;
|
|
13555
13568
|
}
|
|
13556
13569
|
};
|
|
13557
13570
|
export {
|
|
@@ -13641,6 +13654,7 @@ export {
|
|
|
13641
13654
|
AxPromptTemplate,
|
|
13642
13655
|
AxRAG,
|
|
13643
13656
|
AxRateLimiterTokenUsage,
|
|
13657
|
+
AxRewriter,
|
|
13644
13658
|
AxSignature,
|
|
13645
13659
|
AxSimpleClassifier,
|
|
13646
13660
|
AxSimpleClassifierClass,
|