@ax-llm/ax 10.0.29 → 10.0.30
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 +38 -34
- package/index.cjs.map +1 -1
- package/index.js +38 -34
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -702,11 +702,11 @@ var logChatRequest = (req) => {
|
|
|
702
702
|
return `${colorLog.blueBright("System:")}
|
|
703
703
|
${colorLog.whiteBright(msg.content)}`;
|
|
704
704
|
case "function":
|
|
705
|
-
return `${colorLog.blueBright("
|
|
705
|
+
return `${colorLog.blueBright("\nFunction Result:")}
|
|
706
706
|
${colorLog.whiteBright(msg.result)}`;
|
|
707
707
|
case "user": {
|
|
708
708
|
if (typeof msg.content === "string") {
|
|
709
|
-
return `${colorLog.blueBright("
|
|
709
|
+
return `${colorLog.blueBright("\nUser:")}
|
|
710
710
|
${colorLog.whiteBright(msg.content)}`;
|
|
711
711
|
}
|
|
712
712
|
const items2 = msg.content.map((v) => {
|
|
@@ -719,7 +719,7 @@ ${colorLog.whiteBright(msg.content)}`;
|
|
|
719
719
|
throw new Error("Invalid content type");
|
|
720
720
|
}
|
|
721
721
|
});
|
|
722
|
-
return `${colorLog.blueBright("
|
|
722
|
+
return `${colorLog.blueBright("\nUser:")}
|
|
723
723
|
${items2.join("\n")}`;
|
|
724
724
|
}
|
|
725
725
|
case "assistant": {
|
|
@@ -728,10 +728,10 @@ ${items2.join("\n")}`;
|
|
|
728
728
|
const args = typeof fn.params !== "string" ? JSON.stringify(fn.params, null, 2) : fn.params;
|
|
729
729
|
return `${fn.name}(${args})`;
|
|
730
730
|
});
|
|
731
|
-
return `${colorLog.blueBright("
|
|
731
|
+
return `${colorLog.blueBright("\nFunctions:")}
|
|
732
732
|
${colorLog.whiteBright(fns.join("\n"))}`;
|
|
733
733
|
}
|
|
734
|
-
return `${colorLog.blueBright("
|
|
734
|
+
return `${colorLog.blueBright("\nAssistant:")}
|
|
735
735
|
${colorLog.whiteBright(msg.content ?? "<empty>")}`;
|
|
736
736
|
}
|
|
737
737
|
default:
|
|
@@ -4007,6 +4007,15 @@ var AxProgram = class {
|
|
|
4007
4007
|
};
|
|
4008
4008
|
|
|
4009
4009
|
// dsp/prompt.ts
|
|
4010
|
+
var formattingRules = `
|
|
4011
|
+
When providing responses:
|
|
4012
|
+
1. Only output the exact requested content - no additional text, commentary, explanations, or clarifications
|
|
4013
|
+
2. Each key's value must strictly adhere to the formatting rules specified in the reference documentation
|
|
4014
|
+
3. Follow all formatting conventions precisely as defined
|
|
4015
|
+
4. Do not add any extra content beyond what is explicitly requested
|
|
4016
|
+
5. Match the exact structure and format specifications for each field
|
|
4017
|
+
6. No preamble, postscript, or supplementary information
|
|
4018
|
+
7. Pure output only - conforming exactly to the documented requirements`;
|
|
4010
4019
|
var AxPromptTemplate = class {
|
|
4011
4020
|
sig;
|
|
4012
4021
|
fieldTemplates;
|
|
@@ -4019,22 +4028,17 @@ var AxPromptTemplate = class {
|
|
|
4019
4028
|
const task = [
|
|
4020
4029
|
`You will be provided with the following fields: ${inArgs}. Your task is to generate two new fields: ${outArgs}.`
|
|
4021
4030
|
];
|
|
4022
|
-
const
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
return f.name;
|
|
4027
|
-
});
|
|
4028
|
-
const funcList = fnNames?.map((fname) => `\`${fname}\``).join(", ");
|
|
4031
|
+
const funcs = functions?.map(
|
|
4032
|
+
(f) => "toFunction" in f ? f.toFunction() : f
|
|
4033
|
+
);
|
|
4034
|
+
const funcList = funcs?.map((fn) => `\`${fn.name}\`: ${capitalizeFirstLetter(fn.description)}`).join("\n");
|
|
4029
4035
|
if (funcList && funcList.length > 0) {
|
|
4036
|
+
task.push(`## Available Functions
|
|
4037
|
+
${funcList}`);
|
|
4030
4038
|
task.push(
|
|
4031
|
-
`Complete the task, using the
|
|
4039
|
+
`Complete the task, using the functions defined earlier in this prompt, as needed. The output field values may be generated by applying these functions if appropriate for the task.`
|
|
4032
4040
|
);
|
|
4033
4041
|
}
|
|
4034
|
-
const desc = this.sig.getDescription();
|
|
4035
|
-
if (desc) {
|
|
4036
|
-
task.push(capitalizeFirstLetter(desc.endsWith(".") ? desc : desc + "."));
|
|
4037
|
-
}
|
|
4038
4042
|
const inputFields = this.renderFields(this.sig.getInputFields());
|
|
4039
4043
|
task.push(`## Input Fields
|
|
4040
4044
|
${inputFields}`);
|
|
@@ -4044,9 +4048,14 @@ ${outputFields}`);
|
|
|
4044
4048
|
task.push(
|
|
4045
4049
|
"Output must be in plain text, with each `key: value` pair on a new line. The format of each `value` should strictly adhere to the formatting instructions for its corresponding `key`, as defined earlier in this prompt."
|
|
4046
4050
|
);
|
|
4047
|
-
task.push(
|
|
4048
|
-
|
|
4049
|
-
)
|
|
4051
|
+
task.push(formattingRules);
|
|
4052
|
+
const desc = this.sig.getDescription();
|
|
4053
|
+
if (desc) {
|
|
4054
|
+
task.push(
|
|
4055
|
+
`## TASK DESCRIPTION
|
|
4056
|
+
${capitalizeFirstLetter(desc.endsWith(".") ? desc : desc + ".")}`
|
|
4057
|
+
);
|
|
4058
|
+
}
|
|
4050
4059
|
this.task = {
|
|
4051
4060
|
type: "text",
|
|
4052
4061
|
text: task.join("\n\n")
|
|
@@ -4057,21 +4066,22 @@ ${outputFields}`);
|
|
|
4057
4066
|
demos
|
|
4058
4067
|
}) => {
|
|
4059
4068
|
const renderedExamples = examples ? [
|
|
4060
|
-
{ type: "text", text: "
|
|
4069
|
+
{ type: "text", text: "## Examples:\n" },
|
|
4061
4070
|
...this.renderExamples(examples)
|
|
4062
4071
|
] : [];
|
|
4063
4072
|
const renderedDemos = demos ? this.renderDemos(demos) : [];
|
|
4064
4073
|
const completion = this.renderInputFields(values);
|
|
4065
4074
|
const allTextExamples = renderedExamples.every((v) => v.type === "text");
|
|
4066
4075
|
const allTextDemos = renderedDemos.every((v) => v.type === "text");
|
|
4076
|
+
const examplesInSystemPrompt = allTextExamples && allTextDemos;
|
|
4067
4077
|
let systemContent = this.task.text;
|
|
4068
|
-
if (
|
|
4078
|
+
if (examplesInSystemPrompt) {
|
|
4069
4079
|
const combinedItems = [
|
|
4070
|
-
{ type: "text", text:
|
|
4080
|
+
{ type: "text", text: systemContent + "\n\n" },
|
|
4071
4081
|
...renderedExamples,
|
|
4072
4082
|
...renderedDemos
|
|
4073
4083
|
];
|
|
4074
|
-
combinedItems.reduce(combineConsecutiveStrings("
|
|
4084
|
+
combinedItems.reduce(combineConsecutiveStrings(""), []);
|
|
4075
4085
|
if (combinedItems && combinedItems[0]) {
|
|
4076
4086
|
systemContent = combinedItems[0].text;
|
|
4077
4087
|
}
|
|
@@ -4080,7 +4090,7 @@ ${outputFields}`);
|
|
|
4080
4090
|
role: "system",
|
|
4081
4091
|
content: systemContent
|
|
4082
4092
|
};
|
|
4083
|
-
const promptList =
|
|
4093
|
+
const promptList = examplesInSystemPrompt ? completion : [...renderedExamples, ...renderedDemos, ...completion];
|
|
4084
4094
|
const prompt = promptList.filter((v) => v !== void 0);
|
|
4085
4095
|
const userContent = prompt.every((v) => v.type === "text") ? prompt.map((v) => v.text).join("\n") : prompt.reduce(combineConsecutiveStrings("\n"), []);
|
|
4086
4096
|
const userPrompt = {
|
|
@@ -4115,16 +4125,13 @@ ${outputFields}`);
|
|
|
4115
4125
|
const renderedItem = [...renderedInputItem, ...renderedOutputItem];
|
|
4116
4126
|
renderedItem.forEach((v) => {
|
|
4117
4127
|
if ("text" in v) {
|
|
4118
|
-
v.text = v.text;
|
|
4128
|
+
v.text = v.text + "\n";
|
|
4119
4129
|
}
|
|
4120
4130
|
if ("image" in v) {
|
|
4121
4131
|
v.image = v.image;
|
|
4122
4132
|
}
|
|
4123
4133
|
list.push(v);
|
|
4124
4134
|
});
|
|
4125
|
-
if (renderedItem.length > 0) {
|
|
4126
|
-
list.push({ type: "text", text: "\n" });
|
|
4127
|
-
}
|
|
4128
4135
|
}
|
|
4129
4136
|
return list;
|
|
4130
4137
|
};
|
|
@@ -4135,23 +4142,20 @@ ${outputFields}`);
|
|
|
4135
4142
|
const renderedItem = fields.map((field) => this.renderInField(field, item, true)).filter((v) => v !== void 0).flat();
|
|
4136
4143
|
renderedItem.slice(0, -1).forEach((v) => {
|
|
4137
4144
|
if ("text" in v) {
|
|
4138
|
-
v.text = v.text;
|
|
4145
|
+
v.text = v.text + "\n";
|
|
4139
4146
|
}
|
|
4140
4147
|
if ("image" in v) {
|
|
4141
4148
|
v.image = v.image;
|
|
4142
4149
|
}
|
|
4143
4150
|
list.push(v);
|
|
4144
4151
|
});
|
|
4145
|
-
if (renderedItem.length > 0) {
|
|
4146
|
-
list.push({ type: "text", text: "\n" });
|
|
4147
|
-
}
|
|
4148
4152
|
}
|
|
4149
4153
|
return list;
|
|
4150
4154
|
};
|
|
4151
4155
|
renderInputFields = (values) => {
|
|
4152
4156
|
const renderedItems = this.sig.getInputFields().map((field) => this.renderInField(field, values)).filter((v) => v !== void 0).flat();
|
|
4153
4157
|
renderedItems.filter((v) => v.type === "text").forEach((v) => {
|
|
4154
|
-
v.text = v.text + "\n
|
|
4158
|
+
v.text = v.text + "\n";
|
|
4155
4159
|
});
|
|
4156
4160
|
return renderedItems;
|
|
4157
4161
|
};
|