@ax-llm/ax 10.0.49 → 10.0.50
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 +39 -27
- package/index.cjs.map +1 -1
- package/index.js +39 -27
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -5234,7 +5234,7 @@ var checkMissingRequiredFields = (xstate, values, currentIndex) => {
|
|
|
5234
5234
|
});
|
|
5235
5235
|
}
|
|
5236
5236
|
};
|
|
5237
|
-
var streamingExtractValues = (sig, values, xstate, content) => {
|
|
5237
|
+
var streamingExtractValues = (sig, values, xstate, content, streamingValidation = false) => {
|
|
5238
5238
|
const fields = sig.getOutputFields();
|
|
5239
5239
|
for (const [index, field] of fields.entries()) {
|
|
5240
5240
|
if (field.name in values) {
|
|
@@ -5244,6 +5244,12 @@ var streamingExtractValues = (sig, values, xstate, content) => {
|
|
|
5244
5244
|
let e = matchesContent(content, prefix, xstate.s + 1);
|
|
5245
5245
|
switch (e) {
|
|
5246
5246
|
case -1:
|
|
5247
|
+
if (streamingValidation && xstate.s == -1 && !field.isOptional) {
|
|
5248
|
+
throw new ValidationError({
|
|
5249
|
+
message: "Required field not found",
|
|
5250
|
+
fields: [field]
|
|
5251
|
+
});
|
|
5252
|
+
}
|
|
5247
5253
|
continue;
|
|
5248
5254
|
// Field is not found, continue to the next field
|
|
5249
5255
|
case -2:
|
|
@@ -5260,6 +5266,7 @@ var streamingExtractValues = (sig, values, xstate, content) => {
|
|
|
5260
5266
|
checkMissingRequiredFields(xstate, values, index);
|
|
5261
5267
|
xstate.s = e + prefixLen;
|
|
5262
5268
|
xstate.currField = field;
|
|
5269
|
+
xstate.currFieldIndex = index;
|
|
5263
5270
|
if (!xstate.extractedFields.includes(field)) {
|
|
5264
5271
|
xstate.extractedFields.push(field);
|
|
5265
5272
|
}
|
|
@@ -5273,8 +5280,8 @@ var streamingExtractFinalValue = (sig, values, xstate, content) => {
|
|
|
5273
5280
|
values[xstate.currField.name] = parsedValue;
|
|
5274
5281
|
}
|
|
5275
5282
|
}
|
|
5276
|
-
const
|
|
5277
|
-
checkMissingRequiredFields(xstate, values,
|
|
5283
|
+
const sigFields = sig.getOutputFields();
|
|
5284
|
+
checkMissingRequiredFields(xstate, values, sigFields.length);
|
|
5278
5285
|
};
|
|
5279
5286
|
var convertValueToType = (field, val) => {
|
|
5280
5287
|
switch (field.type?.name) {
|
|
@@ -5759,6 +5766,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5759
5766
|
traceId,
|
|
5760
5767
|
functions
|
|
5761
5768
|
}) {
|
|
5769
|
+
const streamingValidation = !functions || functions.length == 0;
|
|
5762
5770
|
const functionCalls = [];
|
|
5763
5771
|
const values = {};
|
|
5764
5772
|
const xstate = {
|
|
@@ -5774,14 +5782,21 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5774
5782
|
if (v.modelUsage) {
|
|
5775
5783
|
this.usage.push({ ...usageInfo, ...v.modelUsage });
|
|
5776
5784
|
}
|
|
5777
|
-
if (result.
|
|
5785
|
+
if (result.functionCalls) {
|
|
5786
|
+
mergeFunctionCalls(functionCalls, result.functionCalls);
|
|
5787
|
+
mem.updateResult(
|
|
5788
|
+
{ name: result.name, content, functionCalls },
|
|
5789
|
+
sessionId
|
|
5790
|
+
);
|
|
5791
|
+
} else if (result.content) {
|
|
5778
5792
|
content += result.content;
|
|
5779
5793
|
mem.updateResult({ name: result.name, content }, sessionId);
|
|
5780
5794
|
const skip = streamingExtractValues(
|
|
5781
5795
|
this.signature,
|
|
5782
5796
|
values,
|
|
5783
5797
|
xstate,
|
|
5784
|
-
content
|
|
5798
|
+
content,
|
|
5799
|
+
streamingValidation
|
|
5785
5800
|
);
|
|
5786
5801
|
if (skip) {
|
|
5787
5802
|
continue;
|
|
@@ -5796,13 +5811,6 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5796
5811
|
assertAssertions(this.asserts, values);
|
|
5797
5812
|
yield* streamValues(this.signature, values, xstate, content);
|
|
5798
5813
|
}
|
|
5799
|
-
if (result.functionCalls) {
|
|
5800
|
-
mergeFunctionCalls(functionCalls, result.functionCalls);
|
|
5801
|
-
mem.updateResult(
|
|
5802
|
-
{ name: result.name, content, functionCalls },
|
|
5803
|
-
sessionId
|
|
5804
|
-
);
|
|
5805
|
-
}
|
|
5806
5814
|
if (result.finishReason === "length") {
|
|
5807
5815
|
throw new Error("Max tokens reached before completion");
|
|
5808
5816
|
}
|
|
@@ -5821,17 +5829,18 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5821
5829
|
traceId
|
|
5822
5830
|
);
|
|
5823
5831
|
this.functionsExecuted = /* @__PURE__ */ new Set([...this.functionsExecuted, ...fx]);
|
|
5832
|
+
} else {
|
|
5833
|
+
streamingExtractFinalValue(this.signature, values, xstate, content);
|
|
5834
|
+
assertStreamingAssertions(
|
|
5835
|
+
this.streamingAsserts,
|
|
5836
|
+
values,
|
|
5837
|
+
xstate,
|
|
5838
|
+
content,
|
|
5839
|
+
true
|
|
5840
|
+
);
|
|
5841
|
+
assertAssertions(this.asserts, values);
|
|
5842
|
+
yield* streamValues(this.signature, values, xstate, content, true);
|
|
5824
5843
|
}
|
|
5825
|
-
streamingExtractFinalValue(this.signature, values, xstate, content);
|
|
5826
|
-
assertStreamingAssertions(
|
|
5827
|
-
this.streamingAsserts,
|
|
5828
|
-
values,
|
|
5829
|
-
xstate,
|
|
5830
|
-
content,
|
|
5831
|
-
true
|
|
5832
|
-
);
|
|
5833
|
-
assertAssertions(this.asserts, values);
|
|
5834
|
-
yield* streamValues(this.signature, values, xstate, content, true);
|
|
5835
5844
|
}
|
|
5836
5845
|
async processResponse({
|
|
5837
5846
|
ai,
|
|
@@ -5843,15 +5852,15 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5843
5852
|
functions
|
|
5844
5853
|
}) {
|
|
5845
5854
|
const values = {};
|
|
5846
|
-
|
|
5855
|
+
let results = res.results ?? [];
|
|
5856
|
+
if (res.results.length > 1) {
|
|
5857
|
+
results = res.results.filter((r) => r.functionCalls);
|
|
5858
|
+
}
|
|
5859
|
+
for (const result of results) {
|
|
5847
5860
|
if (res.modelUsage) {
|
|
5848
5861
|
this.usage.push({ ...usageInfo, ...res.modelUsage });
|
|
5849
5862
|
}
|
|
5850
5863
|
mem.addResult(result, sessionId);
|
|
5851
|
-
if (result.content) {
|
|
5852
|
-
extractValues(this.signature, values, result.content);
|
|
5853
|
-
assertAssertions(this.asserts, values);
|
|
5854
|
-
}
|
|
5855
5864
|
if (result.functionCalls) {
|
|
5856
5865
|
const funcs = parseFunctionCalls(ai, result.functionCalls, values);
|
|
5857
5866
|
if (funcs) {
|
|
@@ -5868,6 +5877,9 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
5868
5877
|
);
|
|
5869
5878
|
this.functionsExecuted = /* @__PURE__ */ new Set([...this.functionsExecuted, ...fx]);
|
|
5870
5879
|
}
|
|
5880
|
+
} else if (result.content) {
|
|
5881
|
+
extractValues(this.signature, values, result.content);
|
|
5882
|
+
assertAssertions(this.asserts, values);
|
|
5871
5883
|
}
|
|
5872
5884
|
if (result.finishReason === "length") {
|
|
5873
5885
|
throw new Error("Max tokens reached before completion");
|