@ax-llm/ax 10.0.29 → 10.0.31
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 +46 -39
- package/index.cjs.map +1 -1
- package/index.js +46 -39
- 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:
|
|
@@ -754,15 +754,16 @@ var logResponse = (resp) => {
|
|
|
754
754
|
if (r.functionCalls) {
|
|
755
755
|
for (const [i, f] of r.functionCalls.entries()) {
|
|
756
756
|
if (f.function.name) {
|
|
757
|
+
if (i > 0) {
|
|
758
|
+
process.stdout.write("\n\n");
|
|
759
|
+
}
|
|
757
760
|
process.stdout.write(
|
|
758
|
-
`
|
|
759
|
-
Function ${i + 1} -> ${colorLog.greenBright(f.function.name)} `
|
|
761
|
+
`Function ${i + 1} -> ${colorLog.greenBright(f.function.name)} `
|
|
760
762
|
);
|
|
761
763
|
}
|
|
762
764
|
if (f.function.params) {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
);
|
|
765
|
+
const params = typeof f.function.params === "string" ? f.function.params : JSON.stringify(f.function.params, null, 2);
|
|
766
|
+
process.stdout.write(`${colorLog.greenBright(params)}`);
|
|
766
767
|
}
|
|
767
768
|
}
|
|
768
769
|
}
|
|
@@ -4007,6 +4008,15 @@ var AxProgram = class {
|
|
|
4007
4008
|
};
|
|
4008
4009
|
|
|
4009
4010
|
// dsp/prompt.ts
|
|
4011
|
+
var formattingRules = `
|
|
4012
|
+
When providing responses:
|
|
4013
|
+
1. Only output the exact requested content - no additional text, commentary, explanations, or clarifications
|
|
4014
|
+
2. Each key's value must strictly adhere to the formatting rules specified in the reference documentation
|
|
4015
|
+
3. Follow all formatting conventions precisely as defined
|
|
4016
|
+
4. Do not add any extra content beyond what is explicitly requested
|
|
4017
|
+
5. Match the exact structure and format specifications for each field
|
|
4018
|
+
6. No preamble, postscript, or supplementary information
|
|
4019
|
+
7. Pure output only - conforming exactly to the documented requirements`;
|
|
4010
4020
|
var AxPromptTemplate = class {
|
|
4011
4021
|
sig;
|
|
4012
4022
|
fieldTemplates;
|
|
@@ -4019,22 +4029,19 @@ var AxPromptTemplate = class {
|
|
|
4019
4029
|
const task = [
|
|
4020
4030
|
`You will be provided with the following fields: ${inArgs}. Your task is to generate two new fields: ${outArgs}.`
|
|
4021
4031
|
];
|
|
4022
|
-
const
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
const funcList = fnNames?.map((fname) => `\`${fname}\``).join(", ");
|
|
4032
|
+
const funcs = functions?.map(
|
|
4033
|
+
(f) => "toFunction" in f ? f.toFunction() : f
|
|
4034
|
+
);
|
|
4035
|
+
const funcList = funcs?.map(
|
|
4036
|
+
(fn) => `- \`${fn.name}\`: ${capitalizeFirstLetter(fn.description)}`
|
|
4037
|
+
).join("\n");
|
|
4029
4038
|
if (funcList && funcList.length > 0) {
|
|
4039
|
+
task.push(`## Available Functions
|
|
4040
|
+
${funcList}`);
|
|
4030
4041
|
task.push(
|
|
4031
|
-
`Complete the task, using the
|
|
4042
|
+
`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
4043
|
);
|
|
4033
4044
|
}
|
|
4034
|
-
const desc = this.sig.getDescription();
|
|
4035
|
-
if (desc) {
|
|
4036
|
-
task.push(capitalizeFirstLetter(desc.endsWith(".") ? desc : desc + "."));
|
|
4037
|
-
}
|
|
4038
4045
|
const inputFields = this.renderFields(this.sig.getInputFields());
|
|
4039
4046
|
task.push(`## Input Fields
|
|
4040
4047
|
${inputFields}`);
|
|
@@ -4044,9 +4051,14 @@ ${outputFields}`);
|
|
|
4044
4051
|
task.push(
|
|
4045
4052
|
"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
4053
|
);
|
|
4047
|
-
task.push(
|
|
4048
|
-
|
|
4049
|
-
)
|
|
4054
|
+
task.push(formattingRules);
|
|
4055
|
+
const desc = this.sig.getDescription();
|
|
4056
|
+
if (desc) {
|
|
4057
|
+
task.push(
|
|
4058
|
+
`## TASK DESCRIPTION
|
|
4059
|
+
${capitalizeFirstLetter(desc.endsWith(".") ? desc : desc + ".")}`
|
|
4060
|
+
);
|
|
4061
|
+
}
|
|
4050
4062
|
this.task = {
|
|
4051
4063
|
type: "text",
|
|
4052
4064
|
text: task.join("\n\n")
|
|
@@ -4057,21 +4069,22 @@ ${outputFields}`);
|
|
|
4057
4069
|
demos
|
|
4058
4070
|
}) => {
|
|
4059
4071
|
const renderedExamples = examples ? [
|
|
4060
|
-
{ type: "text", text: "
|
|
4072
|
+
{ type: "text", text: "## Examples:\n" },
|
|
4061
4073
|
...this.renderExamples(examples)
|
|
4062
4074
|
] : [];
|
|
4063
4075
|
const renderedDemos = demos ? this.renderDemos(demos) : [];
|
|
4064
4076
|
const completion = this.renderInputFields(values);
|
|
4065
4077
|
const allTextExamples = renderedExamples.every((v) => v.type === "text");
|
|
4066
4078
|
const allTextDemos = renderedDemos.every((v) => v.type === "text");
|
|
4079
|
+
const examplesInSystemPrompt = allTextExamples && allTextDemos;
|
|
4067
4080
|
let systemContent = this.task.text;
|
|
4068
|
-
if (
|
|
4081
|
+
if (examplesInSystemPrompt) {
|
|
4069
4082
|
const combinedItems = [
|
|
4070
|
-
{ type: "text", text:
|
|
4083
|
+
{ type: "text", text: systemContent + "\n\n" },
|
|
4071
4084
|
...renderedExamples,
|
|
4072
4085
|
...renderedDemos
|
|
4073
4086
|
];
|
|
4074
|
-
combinedItems.reduce(combineConsecutiveStrings("
|
|
4087
|
+
combinedItems.reduce(combineConsecutiveStrings(""), []);
|
|
4075
4088
|
if (combinedItems && combinedItems[0]) {
|
|
4076
4089
|
systemContent = combinedItems[0].text;
|
|
4077
4090
|
}
|
|
@@ -4080,7 +4093,7 @@ ${outputFields}`);
|
|
|
4080
4093
|
role: "system",
|
|
4081
4094
|
content: systemContent
|
|
4082
4095
|
};
|
|
4083
|
-
const promptList =
|
|
4096
|
+
const promptList = examplesInSystemPrompt ? completion : [...renderedExamples, ...renderedDemos, ...completion];
|
|
4084
4097
|
const prompt = promptList.filter((v) => v !== void 0);
|
|
4085
4098
|
const userContent = prompt.every((v) => v.type === "text") ? prompt.map((v) => v.text).join("\n") : prompt.reduce(combineConsecutiveStrings("\n"), []);
|
|
4086
4099
|
const userPrompt = {
|
|
@@ -4115,16 +4128,13 @@ ${outputFields}`);
|
|
|
4115
4128
|
const renderedItem = [...renderedInputItem, ...renderedOutputItem];
|
|
4116
4129
|
renderedItem.forEach((v) => {
|
|
4117
4130
|
if ("text" in v) {
|
|
4118
|
-
v.text = v.text;
|
|
4131
|
+
v.text = v.text + "\n";
|
|
4119
4132
|
}
|
|
4120
4133
|
if ("image" in v) {
|
|
4121
4134
|
v.image = v.image;
|
|
4122
4135
|
}
|
|
4123
4136
|
list.push(v);
|
|
4124
4137
|
});
|
|
4125
|
-
if (renderedItem.length > 0) {
|
|
4126
|
-
list.push({ type: "text", text: "\n" });
|
|
4127
|
-
}
|
|
4128
4138
|
}
|
|
4129
4139
|
return list;
|
|
4130
4140
|
};
|
|
@@ -4135,23 +4145,20 @@ ${outputFields}`);
|
|
|
4135
4145
|
const renderedItem = fields.map((field) => this.renderInField(field, item, true)).filter((v) => v !== void 0).flat();
|
|
4136
4146
|
renderedItem.slice(0, -1).forEach((v) => {
|
|
4137
4147
|
if ("text" in v) {
|
|
4138
|
-
v.text = v.text;
|
|
4148
|
+
v.text = v.text + "\n";
|
|
4139
4149
|
}
|
|
4140
4150
|
if ("image" in v) {
|
|
4141
4151
|
v.image = v.image;
|
|
4142
4152
|
}
|
|
4143
4153
|
list.push(v);
|
|
4144
4154
|
});
|
|
4145
|
-
if (renderedItem.length > 0) {
|
|
4146
|
-
list.push({ type: "text", text: "\n" });
|
|
4147
|
-
}
|
|
4148
4155
|
}
|
|
4149
4156
|
return list;
|
|
4150
4157
|
};
|
|
4151
4158
|
renderInputFields = (values) => {
|
|
4152
4159
|
const renderedItems = this.sig.getInputFields().map((field) => this.renderInField(field, values)).filter((v) => v !== void 0).flat();
|
|
4153
4160
|
renderedItems.filter((v) => v.type === "text").forEach((v) => {
|
|
4154
|
-
v.text = v.text + "\n
|
|
4161
|
+
v.text = v.text + "\n";
|
|
4155
4162
|
});
|
|
4156
4163
|
return renderedItems;
|
|
4157
4164
|
};
|