@ax-llm/ax 12.0.5 → 12.0.6
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 +65 -71
- package/index.cjs.map +1 -1
- package/index.d.cts +12 -2
- package/index.d.ts +12 -2
- package/index.js +65 -71
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -3500,7 +3500,7 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
3500
3500
|
}
|
|
3501
3501
|
];
|
|
3502
3502
|
return {
|
|
3503
|
-
role: "
|
|
3503
|
+
role: "user",
|
|
3504
3504
|
parts
|
|
3505
3505
|
};
|
|
3506
3506
|
}
|
|
@@ -4223,8 +4223,11 @@ var AxAIMistral = class extends AxAIOpenAIBase {
|
|
|
4223
4223
|
for (const message of messages) {
|
|
4224
4224
|
if (message.role === "user" && Array.isArray(message.content)) {
|
|
4225
4225
|
const contentUpdated = message.content.map((item) => {
|
|
4226
|
-
if (typeof item === "object" && item !== null &&
|
|
4227
|
-
return {
|
|
4226
|
+
if (typeof item === "object" && item !== null && "image_url" in item) {
|
|
4227
|
+
return {
|
|
4228
|
+
type: "image_url",
|
|
4229
|
+
image_url: { url: item.image_url?.url }
|
|
4230
|
+
};
|
|
4228
4231
|
}
|
|
4229
4232
|
return item;
|
|
4230
4233
|
});
|
|
@@ -4897,8 +4900,6 @@ var AxAIOpenAIResponsesImpl = class {
|
|
|
4897
4900
|
baseResult.content = event.delta;
|
|
4898
4901
|
break;
|
|
4899
4902
|
case "response.output_text.done":
|
|
4900
|
-
baseResult.id = event.item_id;
|
|
4901
|
-
baseResult.content = event.text;
|
|
4902
4903
|
break;
|
|
4903
4904
|
case "response.function_call_arguments.delta":
|
|
4904
4905
|
baseResult.id = event.item_id;
|
|
@@ -5717,9 +5718,6 @@ var MemoryImpl = class {
|
|
|
5717
5718
|
functionCalls
|
|
5718
5719
|
}) {
|
|
5719
5720
|
const isContentEmpty = typeof content === "string" && content.trim() === "";
|
|
5720
|
-
if (isContentEmpty && (!functionCalls || functionCalls.length === 0)) {
|
|
5721
|
-
return;
|
|
5722
|
-
}
|
|
5723
5721
|
if (isContentEmpty) {
|
|
5724
5722
|
this.addMemory({ name, role: "assistant", functionCalls });
|
|
5725
5723
|
} else {
|
|
@@ -5744,17 +5742,16 @@ var MemoryImpl = class {
|
|
|
5744
5742
|
}) {
|
|
5745
5743
|
const lastItem = this.data.at(-1);
|
|
5746
5744
|
if (!lastItem || lastItem.chat.role !== "assistant") {
|
|
5747
|
-
|
|
5748
|
-
}
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
}
|
|
5745
|
+
throw new Error("No assistant message to update");
|
|
5746
|
+
}
|
|
5747
|
+
if (typeof content === "string" && content.trim() !== "") {
|
|
5748
|
+
lastItem.chat.content = content;
|
|
5749
|
+
}
|
|
5750
|
+
if (name && name.trim() !== "") {
|
|
5751
|
+
lastItem.chat.name = name;
|
|
5752
|
+
}
|
|
5753
|
+
if (functionCalls && functionCalls.length > 0) {
|
|
5754
|
+
lastItem.chat.functionCalls = functionCalls;
|
|
5758
5755
|
}
|
|
5759
5756
|
if (this.options?.debug) {
|
|
5760
5757
|
if (delta && typeof delta === "string") {
|
|
@@ -6284,6 +6281,12 @@ ${outputFields}`);
|
|
|
6284
6281
|
text: task.join("\n\n")
|
|
6285
6282
|
};
|
|
6286
6283
|
}
|
|
6284
|
+
renderSingleValueUserContent = (values, renderedExamples, renderedDemos, examplesInSystemPrompt) => {
|
|
6285
|
+
const completion = this.renderInputFields(values);
|
|
6286
|
+
const promptList = examplesInSystemPrompt ? completion : [...renderedExamples, ...renderedDemos, ...completion];
|
|
6287
|
+
const prompt = promptList.filter((v) => v !== void 0);
|
|
6288
|
+
return prompt.every((v) => v.type === "text") ? prompt.map((v) => v.text).join("\n") : prompt.reduce(combineConsecutiveStrings("\n"), []);
|
|
6289
|
+
};
|
|
6287
6290
|
render = (values, {
|
|
6288
6291
|
examples,
|
|
6289
6292
|
demos
|
|
@@ -6312,60 +6315,49 @@ ${outputFields}`);
|
|
|
6312
6315
|
role: "system",
|
|
6313
6316
|
content: systemContent
|
|
6314
6317
|
};
|
|
6315
|
-
let userMessages = [];
|
|
6316
6318
|
if (Array.isArray(values)) {
|
|
6319
|
+
let userMessages = [];
|
|
6317
6320
|
const history = values;
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6321
|
+
for (const [index, message] of history.entries()) {
|
|
6322
|
+
let content;
|
|
6323
|
+
if (index === 0) {
|
|
6324
|
+
content = this.renderSingleValueUserContent(
|
|
6325
|
+
message.values,
|
|
6326
|
+
renderedExamples,
|
|
6327
|
+
renderedDemos,
|
|
6328
|
+
examplesInSystemPrompt
|
|
6325
6329
|
);
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6330
|
+
} else {
|
|
6331
|
+
content = this.renderSingleValueUserContent(
|
|
6332
|
+
message.values,
|
|
6333
|
+
[],
|
|
6334
|
+
[],
|
|
6335
|
+
false
|
|
6331
6336
|
);
|
|
6332
|
-
messageContent = assistantMsgParts.map((part) => part.type === "text" ? part.text : "").join("").trim();
|
|
6333
6337
|
}
|
|
6334
|
-
if (
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
if (lastMessage) {
|
|
6338
|
-
lastMessage.content += "\n" + messageContent;
|
|
6339
|
-
}
|
|
6340
|
-
} else {
|
|
6341
|
-
if (message.role === "user") {
|
|
6342
|
-
userMessages.push({ role: "user", content: messageContent });
|
|
6343
|
-
} else if (message.role === "assistant") {
|
|
6344
|
-
userMessages.push({ role: "assistant", content: messageContent });
|
|
6345
|
-
}
|
|
6346
|
-
}
|
|
6347
|
-
lastRole = message.role;
|
|
6338
|
+
if (message.role === "user") {
|
|
6339
|
+
userMessages.push({ role: "user", content });
|
|
6340
|
+
continue;
|
|
6348
6341
|
}
|
|
6342
|
+
if (message.role !== "assistant") {
|
|
6343
|
+
throw new Error("Invalid message role");
|
|
6344
|
+
}
|
|
6345
|
+
if (typeof content !== "string") {
|
|
6346
|
+
throw new Error(
|
|
6347
|
+
"Assistant message cannot contain non-text content like images, files,etc"
|
|
6348
|
+
);
|
|
6349
|
+
}
|
|
6350
|
+
userMessages.push({ role: "assistant", content });
|
|
6349
6351
|
}
|
|
6350
|
-
|
|
6351
|
-
const currentValues = values;
|
|
6352
|
-
const completion = this.renderInputFields(currentValues);
|
|
6353
|
-
const promptList = examplesInSystemPrompt ? completion : [...renderedExamples, ...renderedDemos, ...completion];
|
|
6354
|
-
const promptFilter = promptList.filter((v) => v !== void 0);
|
|
6355
|
-
let userContent;
|
|
6356
|
-
if (promptFilter.every((v) => v.type === "text")) {
|
|
6357
|
-
userContent = promptFilter.map((v) => v.text).join("\n");
|
|
6358
|
-
} else {
|
|
6359
|
-
userContent = promptFilter.map((part) => {
|
|
6360
|
-
if (part.type === "text") return part.text;
|
|
6361
|
-
if (part.type === "image") return "[IMAGE]";
|
|
6362
|
-
if (part.type === "audio") return "[AUDIO]";
|
|
6363
|
-
return "";
|
|
6364
|
-
}).join("\n").trim();
|
|
6365
|
-
}
|
|
6366
|
-
userMessages.push({ role: "user", content: userContent });
|
|
6352
|
+
return [systemPrompt, ...userMessages];
|
|
6367
6353
|
}
|
|
6368
|
-
|
|
6354
|
+
const userContent = this.renderSingleValueUserContent(
|
|
6355
|
+
values,
|
|
6356
|
+
renderedExamples,
|
|
6357
|
+
renderedDemos,
|
|
6358
|
+
examplesInSystemPrompt
|
|
6359
|
+
);
|
|
6360
|
+
return [systemPrompt, { role: "user", content: userContent }];
|
|
6369
6361
|
};
|
|
6370
6362
|
renderExtraFields = (extraFields) => {
|
|
6371
6363
|
const prompt = [];
|
|
@@ -6432,9 +6424,6 @@ ${outputFields}`);
|
|
|
6432
6424
|
if ("text" in v) {
|
|
6433
6425
|
v.text = v.text + "\n";
|
|
6434
6426
|
}
|
|
6435
|
-
if ("image" in v) {
|
|
6436
|
-
v.image = v.image;
|
|
6437
|
-
}
|
|
6438
6427
|
list.push(v);
|
|
6439
6428
|
});
|
|
6440
6429
|
}
|
|
@@ -6465,9 +6454,6 @@ ${outputFields}`);
|
|
|
6465
6454
|
if ("text" in v) {
|
|
6466
6455
|
v.text = v.text + "\n";
|
|
6467
6456
|
}
|
|
6468
|
-
if ("image" in v) {
|
|
6469
|
-
v.image = v.image;
|
|
6470
|
-
}
|
|
6471
6457
|
list.push(v);
|
|
6472
6458
|
});
|
|
6473
6459
|
}
|
|
@@ -9118,6 +9104,14 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
9118
9104
|
s: -1
|
|
9119
9105
|
};
|
|
9120
9106
|
let content = "";
|
|
9107
|
+
mem.addResult(
|
|
9108
|
+
{
|
|
9109
|
+
content: "",
|
|
9110
|
+
name: "initial",
|
|
9111
|
+
functionCalls: []
|
|
9112
|
+
},
|
|
9113
|
+
sessionId
|
|
9114
|
+
);
|
|
9121
9115
|
for await (const v of res) {
|
|
9122
9116
|
const result = v.results[0];
|
|
9123
9117
|
if (!result) {
|