@ax-llm/ax 11.0.50 → 11.0.51
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 +168 -74
- package/index.cjs.map +1 -1
- package/index.d.cts +31 -16
- package/index.d.ts +31 -16
- package/index.js +164 -70
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -172,6 +172,7 @@ __export(index_exports, {
|
|
|
172
172
|
module.exports = __toCommonJS(index_exports);
|
|
173
173
|
|
|
174
174
|
// ai/base.ts
|
|
175
|
+
var import_crypto2 = __toESM(require("crypto"), 1);
|
|
175
176
|
var import_api2 = require("@opentelemetry/api");
|
|
176
177
|
|
|
177
178
|
// trace/trace.ts
|
|
@@ -239,6 +240,7 @@ var AxSpanKindValues = /* @__PURE__ */ ((AxSpanKindValues2) => {
|
|
|
239
240
|
})(AxSpanKindValues || {});
|
|
240
241
|
|
|
241
242
|
// util/apicall.ts
|
|
243
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
242
244
|
var import_web3 = require("stream/web");
|
|
243
245
|
var import_api = require("@opentelemetry/api");
|
|
244
246
|
|
|
@@ -379,7 +381,7 @@ var AxAIServiceError = class extends Error {
|
|
|
379
381
|
this.responseBody = responseBody;
|
|
380
382
|
this.name = this.constructor.name;
|
|
381
383
|
this.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
382
|
-
this.errorId =
|
|
384
|
+
this.errorId = import_crypto.default.randomUUID();
|
|
383
385
|
this.context = context3;
|
|
384
386
|
this.stack = this.toString();
|
|
385
387
|
}
|
|
@@ -500,7 +502,7 @@ var apiCall = async (api, json) => {
|
|
|
500
502
|
const baseUrl = new URL(process.env["PROXY"] ?? api.url);
|
|
501
503
|
const apiPath = `${[baseUrl.pathname, api.name].filter(Boolean).join("/").replace(/\/+/g, "/")}${baseUrl.search}`;
|
|
502
504
|
const apiUrl = new URL(apiPath, baseUrl);
|
|
503
|
-
const requestId =
|
|
505
|
+
const requestId = import_crypto.default.randomUUID();
|
|
504
506
|
if (api.validateRequest) {
|
|
505
507
|
const isValid = await api.validateRequest(json);
|
|
506
508
|
if (!isValid) {
|
|
@@ -913,7 +915,7 @@ var AxBaseAI = class {
|
|
|
913
915
|
this.tracer = options.tracer;
|
|
914
916
|
this.modelInfo = modelInfo;
|
|
915
917
|
this.models = models;
|
|
916
|
-
this.id =
|
|
918
|
+
this.id = import_crypto2.default.randomUUID();
|
|
917
919
|
const model = this.getModel(defaults.model) ?? defaults.model;
|
|
918
920
|
const embedModel = this.getEmbedModel(defaults.embedModel) ?? defaults.embedModel;
|
|
919
921
|
this.defaults = { model, embedModel };
|
|
@@ -2262,6 +2264,9 @@ var AxAIOpenAIImpl = class {
|
|
|
2262
2264
|
}
|
|
2263
2265
|
if (config.thinkingTokenBudget) {
|
|
2264
2266
|
switch (config.thinkingTokenBudget) {
|
|
2267
|
+
case "none":
|
|
2268
|
+
reqValue.reasoning_effort = void 0;
|
|
2269
|
+
break;
|
|
2265
2270
|
case "minimal":
|
|
2266
2271
|
reqValue.reasoning_effort = "low";
|
|
2267
2272
|
break;
|
|
@@ -3323,6 +3328,9 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
3323
3328
|
}
|
|
3324
3329
|
if (config.thinkingTokenBudget) {
|
|
3325
3330
|
switch (config.thinkingTokenBudget) {
|
|
3331
|
+
case "none":
|
|
3332
|
+
thinkingConfig.thinkingBudget = 0;
|
|
3333
|
+
break;
|
|
3326
3334
|
case "minimal":
|
|
3327
3335
|
thinkingConfig.thinkingBudget = 200;
|
|
3328
3336
|
break;
|
|
@@ -5914,16 +5922,20 @@ var AxPromptTemplate = class {
|
|
|
5914
5922
|
sig;
|
|
5915
5923
|
fieldTemplates;
|
|
5916
5924
|
task;
|
|
5917
|
-
|
|
5925
|
+
thoughtFieldName;
|
|
5926
|
+
functions;
|
|
5927
|
+
constructor(sig, options, fieldTemplates) {
|
|
5918
5928
|
this.sig = sig;
|
|
5919
5929
|
this.fieldTemplates = fieldTemplates;
|
|
5930
|
+
this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
|
|
5931
|
+
this.functions = options?.functions;
|
|
5920
5932
|
const task = [];
|
|
5921
5933
|
const inArgs = renderDescFields(this.sig.getInputFields());
|
|
5922
5934
|
const outArgs = renderDescFields(this.sig.getOutputFields());
|
|
5923
5935
|
task.push(
|
|
5924
5936
|
`You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
|
|
5925
5937
|
);
|
|
5926
|
-
const funcs = functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
|
|
5938
|
+
const funcs = this.functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
|
|
5927
5939
|
const funcList = funcs?.map((fn) => `- \`${fn.name}\`: ${formatDescription(fn.description)}`).join("\n");
|
|
5928
5940
|
if (funcList && funcList.length > 0) {
|
|
5929
5941
|
task.push(`## Available Functions
|
|
@@ -5958,7 +5970,6 @@ ${outputFields}`);
|
|
|
5958
5970
|
...this.renderExamples(examples)
|
|
5959
5971
|
] : [];
|
|
5960
5972
|
const renderedDemos = demos ? this.renderDemos(demos) : [];
|
|
5961
|
-
const completion = this.renderInputFields(values);
|
|
5962
5973
|
const allTextExamples = renderedExamples.every((v) => v.type === "text");
|
|
5963
5974
|
const allTextDemos = renderedDemos.every((v) => v.type === "text");
|
|
5964
5975
|
const examplesInSystemPrompt = allTextExamples && allTextDemos;
|
|
@@ -5978,14 +5989,73 @@ ${outputFields}`);
|
|
|
5978
5989
|
role: "system",
|
|
5979
5990
|
content: systemContent
|
|
5980
5991
|
};
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5992
|
+
let userMessages = [];
|
|
5993
|
+
if (Array.isArray(values)) {
|
|
5994
|
+
const history = values;
|
|
5995
|
+
let lastRole = void 0;
|
|
5996
|
+
for (const message of history) {
|
|
5997
|
+
let messageContent = "";
|
|
5998
|
+
if (message.role === "user") {
|
|
5999
|
+
const userMsgParts = this.renderInputFields(
|
|
6000
|
+
message.values
|
|
6001
|
+
// Cast message.values (AxGenIn) to T (which extends AxGenIn)
|
|
6002
|
+
);
|
|
6003
|
+
messageContent = userMsgParts.map((part) => part.type === "text" ? part.text : "").join("").trim();
|
|
6004
|
+
} else if (message.role === "assistant") {
|
|
6005
|
+
const assistantValues = message.values;
|
|
6006
|
+
let assistantContentParts = [];
|
|
6007
|
+
const outputFields = this.sig.getOutputFields();
|
|
6008
|
+
for (const field of outputFields) {
|
|
6009
|
+
const value = assistantValues[field.name];
|
|
6010
|
+
if (value !== void 0 && value !== null && (typeof value === "string" ? value !== "" : true)) {
|
|
6011
|
+
const renderedValue = processValue(field, value);
|
|
6012
|
+
assistantContentParts.push(`${field.name}: ${renderedValue}`);
|
|
6013
|
+
} else {
|
|
6014
|
+
const isThoughtField = field.name === this.thoughtFieldName;
|
|
6015
|
+
if (!field.isOptional && !field.isInternal && !isThoughtField) {
|
|
6016
|
+
throw new Error(
|
|
6017
|
+
`Value for output field '${field.name}' ('${field.title}') is required in assistant message history but was not found or was empty.`
|
|
6018
|
+
);
|
|
6019
|
+
}
|
|
6020
|
+
}
|
|
6021
|
+
}
|
|
6022
|
+
messageContent = assistantContentParts.join("\n");
|
|
6023
|
+
}
|
|
6024
|
+
if (messageContent) {
|
|
6025
|
+
if (lastRole === message.role && userMessages.length > 0) {
|
|
6026
|
+
const lastMessage = userMessages[userMessages.length - 1];
|
|
6027
|
+
if (lastMessage) {
|
|
6028
|
+
lastMessage.content += "\n" + messageContent;
|
|
6029
|
+
}
|
|
6030
|
+
} else {
|
|
6031
|
+
if (message.role === "user") {
|
|
6032
|
+
userMessages.push({ role: "user", content: messageContent });
|
|
6033
|
+
} else if (message.role === "assistant") {
|
|
6034
|
+
userMessages.push({ role: "assistant", content: messageContent });
|
|
6035
|
+
}
|
|
6036
|
+
}
|
|
6037
|
+
lastRole = message.role;
|
|
6038
|
+
}
|
|
6039
|
+
}
|
|
6040
|
+
} else {
|
|
6041
|
+
const currentValues = values;
|
|
6042
|
+
const completion = this.renderInputFields(currentValues);
|
|
6043
|
+
const promptList = examplesInSystemPrompt ? completion : [...renderedExamples, ...renderedDemos, ...completion];
|
|
6044
|
+
const promptFilter = promptList.filter((v) => v !== void 0);
|
|
6045
|
+
let userContent;
|
|
6046
|
+
if (promptFilter.every((v) => v.type === "text")) {
|
|
6047
|
+
userContent = promptFilter.map((v) => v.text).join("\n");
|
|
6048
|
+
} else {
|
|
6049
|
+
userContent = promptFilter.map((part) => {
|
|
6050
|
+
if (part.type === "text") return part.text;
|
|
6051
|
+
if (part.type === "image") return "[IMAGE]";
|
|
6052
|
+
if (part.type === "audio") return "[AUDIO]";
|
|
6053
|
+
return "";
|
|
6054
|
+
}).join("\n").trim();
|
|
6055
|
+
}
|
|
6056
|
+
userMessages.push({ role: "user", content: userContent });
|
|
6057
|
+
}
|
|
6058
|
+
return [systemPrompt, ...userMessages];
|
|
5989
6059
|
};
|
|
5990
6060
|
renderExtraFields = (extraFields) => {
|
|
5991
6061
|
const prompt = [];
|
|
@@ -6029,8 +6099,8 @@ ${outputFields}`);
|
|
|
6029
6099
|
renderExamples = (data) => {
|
|
6030
6100
|
const list = [];
|
|
6031
6101
|
for (const [index, item] of data.entries()) {
|
|
6032
|
-
const renderedInputItem = this.sig.getInputFields().map((field) => this.renderInField(field, item
|
|
6033
|
-
const renderedOutputItem = this.sig.getOutputFields().map((field) => this.renderInField(field, item
|
|
6102
|
+
const renderedInputItem = this.sig.getInputFields().map((field) => this.renderInField(field, item)).filter((v) => v !== void 0).flat();
|
|
6103
|
+
const renderedOutputItem = this.sig.getOutputFields().map((field) => this.renderInField(field, item)).filter((v) => v !== void 0).flat();
|
|
6034
6104
|
if (renderedOutputItem.length === 0) {
|
|
6035
6105
|
throw new Error(
|
|
6036
6106
|
`Output fields are required in examples: index: ${index}, data: ${JSON.stringify(item)}`
|
|
@@ -6056,7 +6126,7 @@ ${outputFields}`);
|
|
|
6056
6126
|
const list = [];
|
|
6057
6127
|
const fields = [...this.sig.getInputFields(), ...this.sig.getOutputFields()];
|
|
6058
6128
|
for (const item of data) {
|
|
6059
|
-
const renderedItem = fields.map((field) => this.renderInField(field, item
|
|
6129
|
+
const renderedItem = fields.map((field) => this.renderInField(field, item)).filter((v) => v !== void 0).flat();
|
|
6060
6130
|
renderedItem.slice(0, -1).forEach((v) => {
|
|
6061
6131
|
if ("text" in v) {
|
|
6062
6132
|
v.text = v.text + "\n";
|
|
@@ -6076,11 +6146,8 @@ ${outputFields}`);
|
|
|
6076
6146
|
});
|
|
6077
6147
|
return renderedItems;
|
|
6078
6148
|
};
|
|
6079
|
-
renderInField = (field, values
|
|
6149
|
+
renderInField = (field, values) => {
|
|
6080
6150
|
const value = values[field.name];
|
|
6081
|
-
if (skipMissing && !value) {
|
|
6082
|
-
return;
|
|
6083
|
-
}
|
|
6084
6151
|
if (isEmptyValue(field, value)) {
|
|
6085
6152
|
return;
|
|
6086
6153
|
}
|
|
@@ -6117,20 +6184,20 @@ ${outputFields}`);
|
|
|
6117
6184
|
}
|
|
6118
6185
|
result = result.concat(
|
|
6119
6186
|
value.map((v) => {
|
|
6120
|
-
|
|
6187
|
+
const validated = validateImage(v);
|
|
6121
6188
|
return {
|
|
6122
6189
|
type: "image",
|
|
6123
|
-
mimeType:
|
|
6124
|
-
image:
|
|
6190
|
+
mimeType: validated.mimeType,
|
|
6191
|
+
image: validated.data
|
|
6125
6192
|
};
|
|
6126
6193
|
})
|
|
6127
6194
|
);
|
|
6128
6195
|
} else {
|
|
6129
|
-
const
|
|
6196
|
+
const validated = validateImage(value);
|
|
6130
6197
|
result.push({
|
|
6131
6198
|
type: "image",
|
|
6132
|
-
mimeType:
|
|
6133
|
-
image:
|
|
6199
|
+
mimeType: validated.mimeType,
|
|
6200
|
+
image: validated.data
|
|
6134
6201
|
});
|
|
6135
6202
|
}
|
|
6136
6203
|
return result;
|
|
@@ -6153,24 +6220,24 @@ ${outputFields}`);
|
|
|
6153
6220
|
];
|
|
6154
6221
|
if (field.type.isArray) {
|
|
6155
6222
|
if (!Array.isArray(value)) {
|
|
6156
|
-
throw new Error("
|
|
6223
|
+
throw new Error("Audio field value must be an array.");
|
|
6157
6224
|
}
|
|
6158
6225
|
result = result.concat(
|
|
6159
6226
|
value.map((v) => {
|
|
6160
|
-
|
|
6227
|
+
const validated = validateAudio(v);
|
|
6161
6228
|
return {
|
|
6162
6229
|
type: "audio",
|
|
6163
|
-
format:
|
|
6164
|
-
data:
|
|
6230
|
+
format: validated.format ?? "wav",
|
|
6231
|
+
data: validated.data
|
|
6165
6232
|
};
|
|
6166
6233
|
})
|
|
6167
6234
|
);
|
|
6168
6235
|
} else {
|
|
6169
|
-
const
|
|
6236
|
+
const validated = validateAudio(value);
|
|
6170
6237
|
result.push({
|
|
6171
6238
|
type: "audio",
|
|
6172
|
-
format:
|
|
6173
|
-
data:
|
|
6239
|
+
format: validated.format ?? "wav",
|
|
6240
|
+
data: validated.data
|
|
6174
6241
|
});
|
|
6175
6242
|
}
|
|
6176
6243
|
return result;
|
|
@@ -6270,7 +6337,7 @@ var isEmptyValue = (field, value) => {
|
|
|
6270
6337
|
return false;
|
|
6271
6338
|
}
|
|
6272
6339
|
if (!value || (Array.isArray(value) || typeof value === "string") && value.length === 0) {
|
|
6273
|
-
if (field.isOptional) {
|
|
6340
|
+
if (field.isOptional || field.isInternal) {
|
|
6274
6341
|
return true;
|
|
6275
6342
|
}
|
|
6276
6343
|
throw new Error(`Value for input field '${field.name}' is required.`);
|
|
@@ -7010,7 +7077,7 @@ var AxInstanceRegistry = class {
|
|
|
7010
7077
|
};
|
|
7011
7078
|
|
|
7012
7079
|
// dsp/sig.ts
|
|
7013
|
-
var
|
|
7080
|
+
var import_crypto3 = require("crypto");
|
|
7014
7081
|
|
|
7015
7082
|
// dsp/parser.ts
|
|
7016
7083
|
var SignatureParser = class {
|
|
@@ -7452,7 +7519,7 @@ var AxSignature = class _AxSignature {
|
|
|
7452
7519
|
throw new Error("Image type is not supported in output fields.");
|
|
7453
7520
|
}
|
|
7454
7521
|
});
|
|
7455
|
-
this.sigHash = (0,
|
|
7522
|
+
this.sigHash = (0, import_crypto3.createHash)("sha256").update(this.description ?? "").update(JSON.stringify(this.inputFields)).update(JSON.stringify(this.outputFields)).digest("hex");
|
|
7456
7523
|
this.sigString = renderSignature(
|
|
7457
7524
|
this.description,
|
|
7458
7525
|
this.inputFields,
|
|
@@ -7724,12 +7791,18 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
7724
7791
|
streamingFieldProcessors = [];
|
|
7725
7792
|
values = {};
|
|
7726
7793
|
excludeContentFromTrace = false;
|
|
7794
|
+
thoughtFieldName;
|
|
7727
7795
|
constructor(signature, options) {
|
|
7728
7796
|
super(signature, { description: options?.description });
|
|
7729
7797
|
this.options = options;
|
|
7798
|
+
this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
|
|
7799
|
+
const promptTemplateOptions = {
|
|
7800
|
+
functions: options?.functions,
|
|
7801
|
+
thoughtFieldName: this.thoughtFieldName
|
|
7802
|
+
};
|
|
7730
7803
|
this.promptTemplate = new (options?.promptTemplate ?? AxPromptTemplate)(
|
|
7731
7804
|
this.signature,
|
|
7732
|
-
|
|
7805
|
+
promptTemplateOptions
|
|
7733
7806
|
);
|
|
7734
7807
|
this.asserts = this.options?.asserts ?? [];
|
|
7735
7808
|
this.streamingAsserts = this.options?.streamingAsserts ?? [];
|
|
@@ -7901,7 +7974,9 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
7901
7974
|
);
|
|
7902
7975
|
} else if (result.content && result.content.length > 0) {
|
|
7903
7976
|
if (result.thought && result.thought.length > 0) {
|
|
7904
|
-
yield {
|
|
7977
|
+
yield {
|
|
7978
|
+
[this.thoughtFieldName]: result.thought
|
|
7979
|
+
};
|
|
7905
7980
|
}
|
|
7906
7981
|
content += result.content;
|
|
7907
7982
|
mem.updateResult(
|
|
@@ -7943,8 +8018,10 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
7943
8018
|
);
|
|
7944
8019
|
await assertAssertions(this.asserts, this.values);
|
|
7945
8020
|
} else if (result.thought && result.thought.length > 0) {
|
|
7946
|
-
this.values.
|
|
7947
|
-
yield {
|
|
8021
|
+
this.values[this.thoughtFieldName] = (this.values[this.thoughtFieldName] ?? "") + result.thought;
|
|
8022
|
+
yield {
|
|
8023
|
+
[this.thoughtFieldName]: result.thought
|
|
8024
|
+
};
|
|
7948
8025
|
}
|
|
7949
8026
|
if (result.finishReason === "length") {
|
|
7950
8027
|
throw new Error(
|
|
@@ -8044,7 +8121,7 @@ Content: ${content}`
|
|
|
8044
8121
|
}
|
|
8045
8122
|
} else if (result.content) {
|
|
8046
8123
|
if (result.thought && result.thought.length > 0) {
|
|
8047
|
-
this.values.
|
|
8124
|
+
this.values[this.thoughtFieldName] = result.thought;
|
|
8048
8125
|
}
|
|
8049
8126
|
extractValues(this.signature, this.values, result.content);
|
|
8050
8127
|
await assertAssertions(this.asserts, this.values);
|
|
@@ -8081,16 +8158,29 @@ Content: ${result.content}`
|
|
|
8081
8158
|
const mem = options.mem ?? this.options?.mem ?? new AxMemory(1e4, memOptions);
|
|
8082
8159
|
let err;
|
|
8083
8160
|
if (options?.functions && options.functions.length > 0) {
|
|
8084
|
-
const
|
|
8085
|
-
|
|
8161
|
+
const promptTemplateClass = this.options?.promptTemplate ?? AxPromptTemplate;
|
|
8162
|
+
const currentPromptTemplateOptions = {
|
|
8163
|
+
functions: options.functions,
|
|
8164
|
+
thoughtFieldName: this.thoughtFieldName
|
|
8165
|
+
};
|
|
8166
|
+
this.promptTemplate = new promptTemplateClass(
|
|
8086
8167
|
this.signature,
|
|
8087
|
-
|
|
8168
|
+
currentPromptTemplateOptions
|
|
8088
8169
|
);
|
|
8089
8170
|
}
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8171
|
+
let prompt;
|
|
8172
|
+
if (Array.isArray(values)) {
|
|
8173
|
+
prompt = this.promptTemplate.render(values, {
|
|
8174
|
+
examples: this.examples,
|
|
8175
|
+
demos: this.demos
|
|
8176
|
+
});
|
|
8177
|
+
} else {
|
|
8178
|
+
prompt = this.promptTemplate.render(values, {
|
|
8179
|
+
// Cast if necessary
|
|
8180
|
+
examples: this.examples,
|
|
8181
|
+
demos: this.demos
|
|
8182
|
+
});
|
|
8183
|
+
}
|
|
8094
8184
|
mem.add(prompt, options?.sessionId);
|
|
8095
8185
|
multiStepLoop: for (let n = 0; n < maxSteps; n++) {
|
|
8096
8186
|
const firstStep = n === 0;
|
|
@@ -8952,7 +9042,8 @@ var AxBootstrapFewShot = class {
|
|
|
8952
9042
|
if (this.costMonitoring) {
|
|
8953
9043
|
this.stats.estimatedTokenUsage += JSON.stringify(ex).length / 4 + JSON.stringify(res).length / 4;
|
|
8954
9044
|
}
|
|
8955
|
-
const
|
|
9045
|
+
const score = metricFn({ prediction: res, example: ex });
|
|
9046
|
+
const success = score >= 0.5;
|
|
8956
9047
|
if (success) {
|
|
8957
9048
|
this.traces = [...this.traces, ...this.program.getTraces()];
|
|
8958
9049
|
this.stats.successfulDemos++;
|
|
@@ -10940,19 +11031,20 @@ ${dataContext}
|
|
|
10940
11031
|
}
|
|
10941
11032
|
evalSet = minibatchEvalSet;
|
|
10942
11033
|
}
|
|
10943
|
-
let
|
|
11034
|
+
let sumOfScores = 0;
|
|
10944
11035
|
for (const example of evalSet) {
|
|
10945
11036
|
try {
|
|
10946
11037
|
const prediction = await this.program.forward(this.ai, example);
|
|
10947
|
-
const
|
|
10948
|
-
|
|
11038
|
+
const score = metricFn({ prediction, example });
|
|
11039
|
+
sumOfScores += score;
|
|
10949
11040
|
} catch (err) {
|
|
10950
11041
|
if (this.verbose) {
|
|
10951
11042
|
console.error("Error evaluating example:", err);
|
|
10952
11043
|
}
|
|
10953
11044
|
}
|
|
10954
11045
|
}
|
|
10955
|
-
|
|
11046
|
+
if (evalSet.length === 0) return 0;
|
|
11047
|
+
return sumOfScores / evalSet.length;
|
|
10956
11048
|
}
|
|
10957
11049
|
/**
|
|
10958
11050
|
* Run full evaluation on the entire validation set
|
|
@@ -10964,19 +11056,20 @@ ${dataContext}
|
|
|
10964
11056
|
bootstrappedDemos,
|
|
10965
11057
|
labeledExamples
|
|
10966
11058
|
);
|
|
10967
|
-
let
|
|
11059
|
+
let sumOfScores = 0;
|
|
10968
11060
|
for (const example of valset) {
|
|
10969
11061
|
try {
|
|
10970
11062
|
const prediction = await this.program.forward(this.ai, example);
|
|
10971
|
-
const
|
|
10972
|
-
|
|
11063
|
+
const score = metricFn({ prediction, example });
|
|
11064
|
+
sumOfScores += score;
|
|
10973
11065
|
} catch (err) {
|
|
10974
11066
|
if (this.verbose) {
|
|
10975
11067
|
console.error("Error evaluating example:", err);
|
|
10976
11068
|
}
|
|
10977
11069
|
}
|
|
10978
11070
|
}
|
|
10979
|
-
|
|
11071
|
+
if (valset.length === 0) return 0;
|
|
11072
|
+
return sumOfScores / valset.length;
|
|
10980
11073
|
}
|
|
10981
11074
|
/**
|
|
10982
11075
|
* Implements a Bayesian-inspired selection of the next configuration to try
|
|
@@ -11148,10 +11241,11 @@ ${dataContext}
|
|
|
11148
11241
|
};
|
|
11149
11242
|
|
|
11150
11243
|
// ai/mock/api.ts
|
|
11244
|
+
var import_crypto4 = __toESM(require("crypto"), 1);
|
|
11151
11245
|
var AxMockAIService = class {
|
|
11152
11246
|
constructor(config = {}) {
|
|
11153
11247
|
this.config = config;
|
|
11154
|
-
this.config.id = this.config.id ??
|
|
11248
|
+
this.config.id = this.config.id ?? import_crypto4.default.randomUUID();
|
|
11155
11249
|
}
|
|
11156
11250
|
metrics = {
|
|
11157
11251
|
latency: {
|
|
@@ -11362,27 +11456,26 @@ var AxTestPrompt = class {
|
|
|
11362
11456
|
async run(metricFn) {
|
|
11363
11457
|
const st = (/* @__PURE__ */ new Date()).getTime();
|
|
11364
11458
|
const total = this.examples.length;
|
|
11365
|
-
let
|
|
11459
|
+
let sumOfScores = 0;
|
|
11366
11460
|
for (let i = 0; i < total; i++) {
|
|
11367
11461
|
const ex = this.examples[i];
|
|
11368
11462
|
if (!ex) {
|
|
11369
11463
|
throw new Error("Invalid example");
|
|
11370
11464
|
}
|
|
11371
11465
|
const res = await this.program.forward(this.ai, ex);
|
|
11372
|
-
const
|
|
11373
|
-
|
|
11374
|
-
successCount++;
|
|
11375
|
-
}
|
|
11466
|
+
const score = metricFn({ prediction: res, example: ex });
|
|
11467
|
+
sumOfScores += score;
|
|
11376
11468
|
const et = (/* @__PURE__ */ new Date()).getTime() - st;
|
|
11377
|
-
updateProgressBar(i, total,
|
|
11469
|
+
updateProgressBar(i, total, sumOfScores, et, "Testing Prompt", 30);
|
|
11378
11470
|
}
|
|
11471
|
+
const averageScore = total > 0 ? sumOfScores / total : 0;
|
|
11379
11472
|
console.log(
|
|
11380
11473
|
"\nPerformance: ",
|
|
11381
|
-
|
|
11474
|
+
sumOfScores,
|
|
11382
11475
|
"/",
|
|
11383
11476
|
total,
|
|
11384
|
-
"
|
|
11385
|
-
|
|
11477
|
+
"Average Score: ",
|
|
11478
|
+
averageScore,
|
|
11386
11479
|
"\n"
|
|
11387
11480
|
);
|
|
11388
11481
|
}
|
|
@@ -11396,7 +11489,8 @@ var AxChainOfThought = class extends AxGen {
|
|
|
11396
11489
|
sig.setOutputFields([
|
|
11397
11490
|
{
|
|
11398
11491
|
name: "reason",
|
|
11399
|
-
description
|
|
11492
|
+
description,
|
|
11493
|
+
isInternal: options?.setVisibleReasoning !== true
|
|
11400
11494
|
},
|
|
11401
11495
|
...sig.getOutputFields()
|
|
11402
11496
|
]);
|
|
@@ -12725,7 +12819,7 @@ function normalizeText(s) {
|
|
|
12725
12819
|
return s.toLowerCase();
|
|
12726
12820
|
}
|
|
12727
12821
|
function emScore(prediction, groundTruth) {
|
|
12728
|
-
return normalizeText(prediction) === normalizeText(groundTruth);
|
|
12822
|
+
return normalizeText(prediction) === normalizeText(groundTruth) ? 1 : 0;
|
|
12729
12823
|
}
|
|
12730
12824
|
function f1Score(prediction, groundTruth) {
|
|
12731
12825
|
const predictionTokens = normalizeText(prediction).split(" ");
|
|
@@ -12765,12 +12859,12 @@ var AxEvalUtil = {
|
|
|
12765
12859
|
};
|
|
12766
12860
|
|
|
12767
12861
|
// ../../node_modules/uuid/dist/esm-node/rng.js
|
|
12768
|
-
var
|
|
12862
|
+
var import_crypto5 = __toESM(require("crypto"));
|
|
12769
12863
|
var rnds8Pool = new Uint8Array(256);
|
|
12770
12864
|
var poolPtr = rnds8Pool.length;
|
|
12771
12865
|
function rng() {
|
|
12772
12866
|
if (poolPtr > rnds8Pool.length - 16) {
|
|
12773
|
-
|
|
12867
|
+
import_crypto5.default.randomFillSync(rnds8Pool);
|
|
12774
12868
|
poolPtr = 0;
|
|
12775
12869
|
}
|
|
12776
12870
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
@@ -12786,9 +12880,9 @@ function unsafeStringify(arr, offset = 0) {
|
|
|
12786
12880
|
}
|
|
12787
12881
|
|
|
12788
12882
|
// ../../node_modules/uuid/dist/esm-node/native.js
|
|
12789
|
-
var
|
|
12883
|
+
var import_crypto6 = __toESM(require("crypto"));
|
|
12790
12884
|
var native_default = {
|
|
12791
|
-
randomUUID:
|
|
12885
|
+
randomUUID: import_crypto6.default.randomUUID
|
|
12792
12886
|
};
|
|
12793
12887
|
|
|
12794
12888
|
// ../../node_modules/uuid/dist/esm-node/v4.js
|