@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.cjs
CHANGED
|
@@ -796,11 +796,11 @@ var logChatRequest = (req) => {
|
|
|
796
796
|
return `${colorLog.blueBright("System:")}
|
|
797
797
|
${colorLog.whiteBright(msg.content)}`;
|
|
798
798
|
case "function":
|
|
799
|
-
return `${colorLog.blueBright("
|
|
799
|
+
return `${colorLog.blueBright("\nFunction Result:")}
|
|
800
800
|
${colorLog.whiteBright(msg.result)}`;
|
|
801
801
|
case "user": {
|
|
802
802
|
if (typeof msg.content === "string") {
|
|
803
|
-
return `${colorLog.blueBright("
|
|
803
|
+
return `${colorLog.blueBright("\nUser:")}
|
|
804
804
|
${colorLog.whiteBright(msg.content)}`;
|
|
805
805
|
}
|
|
806
806
|
const items2 = msg.content.map((v) => {
|
|
@@ -813,7 +813,7 @@ ${colorLog.whiteBright(msg.content)}`;
|
|
|
813
813
|
throw new Error("Invalid content type");
|
|
814
814
|
}
|
|
815
815
|
});
|
|
816
|
-
return `${colorLog.blueBright("
|
|
816
|
+
return `${colorLog.blueBright("\nUser:")}
|
|
817
817
|
${items2.join("\n")}`;
|
|
818
818
|
}
|
|
819
819
|
case "assistant": {
|
|
@@ -822,10 +822,10 @@ ${items2.join("\n")}`;
|
|
|
822
822
|
const args = typeof fn.params !== "string" ? JSON.stringify(fn.params, null, 2) : fn.params;
|
|
823
823
|
return `${fn.name}(${args})`;
|
|
824
824
|
});
|
|
825
|
-
return `${colorLog.blueBright("
|
|
825
|
+
return `${colorLog.blueBright("\nFunctions:")}
|
|
826
826
|
${colorLog.whiteBright(fns.join("\n"))}`;
|
|
827
827
|
}
|
|
828
|
-
return `${colorLog.blueBright("
|
|
828
|
+
return `${colorLog.blueBright("\nAssistant:")}
|
|
829
829
|
${colorLog.whiteBright(msg.content ?? "<empty>")}`;
|
|
830
830
|
}
|
|
831
831
|
default:
|
|
@@ -848,15 +848,16 @@ var logResponse = (resp) => {
|
|
|
848
848
|
if (r.functionCalls) {
|
|
849
849
|
for (const [i, f] of r.functionCalls.entries()) {
|
|
850
850
|
if (f.function.name) {
|
|
851
|
+
if (i > 0) {
|
|
852
|
+
process.stdout.write("\n\n");
|
|
853
|
+
}
|
|
851
854
|
process.stdout.write(
|
|
852
|
-
`
|
|
853
|
-
Function ${i + 1} -> ${colorLog.greenBright(f.function.name)} `
|
|
855
|
+
`Function ${i + 1} -> ${colorLog.greenBright(f.function.name)} `
|
|
854
856
|
);
|
|
855
857
|
}
|
|
856
858
|
if (f.function.params) {
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
);
|
|
859
|
+
const params = typeof f.function.params === "string" ? f.function.params : JSON.stringify(f.function.params, null, 2);
|
|
860
|
+
process.stdout.write(`${colorLog.greenBright(params)}`);
|
|
860
861
|
}
|
|
861
862
|
}
|
|
862
863
|
}
|
|
@@ -4101,6 +4102,15 @@ var AxProgram = class {
|
|
|
4101
4102
|
};
|
|
4102
4103
|
|
|
4103
4104
|
// dsp/prompt.ts
|
|
4105
|
+
var formattingRules = `
|
|
4106
|
+
When providing responses:
|
|
4107
|
+
1. Only output the exact requested content - no additional text, commentary, explanations, or clarifications
|
|
4108
|
+
2. Each key's value must strictly adhere to the formatting rules specified in the reference documentation
|
|
4109
|
+
3. Follow all formatting conventions precisely as defined
|
|
4110
|
+
4. Do not add any extra content beyond what is explicitly requested
|
|
4111
|
+
5. Match the exact structure and format specifications for each field
|
|
4112
|
+
6. No preamble, postscript, or supplementary information
|
|
4113
|
+
7. Pure output only - conforming exactly to the documented requirements`;
|
|
4104
4114
|
var AxPromptTemplate = class {
|
|
4105
4115
|
sig;
|
|
4106
4116
|
fieldTemplates;
|
|
@@ -4113,22 +4123,19 @@ var AxPromptTemplate = class {
|
|
|
4113
4123
|
const task = [
|
|
4114
4124
|
`You will be provided with the following fields: ${inArgs}. Your task is to generate two new fields: ${outArgs}.`
|
|
4115
4125
|
];
|
|
4116
|
-
const
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
const funcList = fnNames?.map((fname) => `\`${fname}\``).join(", ");
|
|
4126
|
+
const funcs = functions?.map(
|
|
4127
|
+
(f) => "toFunction" in f ? f.toFunction() : f
|
|
4128
|
+
);
|
|
4129
|
+
const funcList = funcs?.map(
|
|
4130
|
+
(fn) => `- \`${fn.name}\`: ${capitalizeFirstLetter(fn.description)}`
|
|
4131
|
+
).join("\n");
|
|
4123
4132
|
if (funcList && funcList.length > 0) {
|
|
4133
|
+
task.push(`## Available Functions
|
|
4134
|
+
${funcList}`);
|
|
4124
4135
|
task.push(
|
|
4125
|
-
`Complete the task, using the
|
|
4136
|
+
`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.`
|
|
4126
4137
|
);
|
|
4127
4138
|
}
|
|
4128
|
-
const desc = this.sig.getDescription();
|
|
4129
|
-
if (desc) {
|
|
4130
|
-
task.push(capitalizeFirstLetter(desc.endsWith(".") ? desc : desc + "."));
|
|
4131
|
-
}
|
|
4132
4139
|
const inputFields = this.renderFields(this.sig.getInputFields());
|
|
4133
4140
|
task.push(`## Input Fields
|
|
4134
4141
|
${inputFields}`);
|
|
@@ -4138,9 +4145,14 @@ ${outputFields}`);
|
|
|
4138
4145
|
task.push(
|
|
4139
4146
|
"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."
|
|
4140
4147
|
);
|
|
4141
|
-
task.push(
|
|
4142
|
-
|
|
4143
|
-
)
|
|
4148
|
+
task.push(formattingRules);
|
|
4149
|
+
const desc = this.sig.getDescription();
|
|
4150
|
+
if (desc) {
|
|
4151
|
+
task.push(
|
|
4152
|
+
`## TASK DESCRIPTION
|
|
4153
|
+
${capitalizeFirstLetter(desc.endsWith(".") ? desc : desc + ".")}`
|
|
4154
|
+
);
|
|
4155
|
+
}
|
|
4144
4156
|
this.task = {
|
|
4145
4157
|
type: "text",
|
|
4146
4158
|
text: task.join("\n\n")
|
|
@@ -4151,21 +4163,22 @@ ${outputFields}`);
|
|
|
4151
4163
|
demos
|
|
4152
4164
|
}) => {
|
|
4153
4165
|
const renderedExamples = examples ? [
|
|
4154
|
-
{ type: "text", text: "
|
|
4166
|
+
{ type: "text", text: "## Examples:\n" },
|
|
4155
4167
|
...this.renderExamples(examples)
|
|
4156
4168
|
] : [];
|
|
4157
4169
|
const renderedDemos = demos ? this.renderDemos(demos) : [];
|
|
4158
4170
|
const completion = this.renderInputFields(values);
|
|
4159
4171
|
const allTextExamples = renderedExamples.every((v) => v.type === "text");
|
|
4160
4172
|
const allTextDemos = renderedDemos.every((v) => v.type === "text");
|
|
4173
|
+
const examplesInSystemPrompt = allTextExamples && allTextDemos;
|
|
4161
4174
|
let systemContent = this.task.text;
|
|
4162
|
-
if (
|
|
4175
|
+
if (examplesInSystemPrompt) {
|
|
4163
4176
|
const combinedItems = [
|
|
4164
|
-
{ type: "text", text:
|
|
4177
|
+
{ type: "text", text: systemContent + "\n\n" },
|
|
4165
4178
|
...renderedExamples,
|
|
4166
4179
|
...renderedDemos
|
|
4167
4180
|
];
|
|
4168
|
-
combinedItems.reduce(combineConsecutiveStrings("
|
|
4181
|
+
combinedItems.reduce(combineConsecutiveStrings(""), []);
|
|
4169
4182
|
if (combinedItems && combinedItems[0]) {
|
|
4170
4183
|
systemContent = combinedItems[0].text;
|
|
4171
4184
|
}
|
|
@@ -4174,7 +4187,7 @@ ${outputFields}`);
|
|
|
4174
4187
|
role: "system",
|
|
4175
4188
|
content: systemContent
|
|
4176
4189
|
};
|
|
4177
|
-
const promptList =
|
|
4190
|
+
const promptList = examplesInSystemPrompt ? completion : [...renderedExamples, ...renderedDemos, ...completion];
|
|
4178
4191
|
const prompt = promptList.filter((v) => v !== void 0);
|
|
4179
4192
|
const userContent = prompt.every((v) => v.type === "text") ? prompt.map((v) => v.text).join("\n") : prompt.reduce(combineConsecutiveStrings("\n"), []);
|
|
4180
4193
|
const userPrompt = {
|
|
@@ -4209,16 +4222,13 @@ ${outputFields}`);
|
|
|
4209
4222
|
const renderedItem = [...renderedInputItem, ...renderedOutputItem];
|
|
4210
4223
|
renderedItem.forEach((v) => {
|
|
4211
4224
|
if ("text" in v) {
|
|
4212
|
-
v.text = v.text;
|
|
4225
|
+
v.text = v.text + "\n";
|
|
4213
4226
|
}
|
|
4214
4227
|
if ("image" in v) {
|
|
4215
4228
|
v.image = v.image;
|
|
4216
4229
|
}
|
|
4217
4230
|
list.push(v);
|
|
4218
4231
|
});
|
|
4219
|
-
if (renderedItem.length > 0) {
|
|
4220
|
-
list.push({ type: "text", text: "\n" });
|
|
4221
|
-
}
|
|
4222
4232
|
}
|
|
4223
4233
|
return list;
|
|
4224
4234
|
};
|
|
@@ -4229,23 +4239,20 @@ ${outputFields}`);
|
|
|
4229
4239
|
const renderedItem = fields.map((field) => this.renderInField(field, item, true)).filter((v) => v !== void 0).flat();
|
|
4230
4240
|
renderedItem.slice(0, -1).forEach((v) => {
|
|
4231
4241
|
if ("text" in v) {
|
|
4232
|
-
v.text = v.text;
|
|
4242
|
+
v.text = v.text + "\n";
|
|
4233
4243
|
}
|
|
4234
4244
|
if ("image" in v) {
|
|
4235
4245
|
v.image = v.image;
|
|
4236
4246
|
}
|
|
4237
4247
|
list.push(v);
|
|
4238
4248
|
});
|
|
4239
|
-
if (renderedItem.length > 0) {
|
|
4240
|
-
list.push({ type: "text", text: "\n" });
|
|
4241
|
-
}
|
|
4242
4249
|
}
|
|
4243
4250
|
return list;
|
|
4244
4251
|
};
|
|
4245
4252
|
renderInputFields = (values) => {
|
|
4246
4253
|
const renderedItems = this.sig.getInputFields().map((field) => this.renderInField(field, values)).filter((v) => v !== void 0).flat();
|
|
4247
4254
|
renderedItems.filter((v) => v.type === "text").forEach((v) => {
|
|
4248
|
-
v.text = v.text + "\n
|
|
4255
|
+
v.text = v.text + "\n";
|
|
4249
4256
|
});
|
|
4250
4257
|
return renderedItems;
|
|
4251
4258
|
};
|