@ax-llm/ax 10.0.28 → 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 +54 -50
- package/index.cjs.map +1 -1
- package/index.js +54 -50
- 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;
|
|
@@ -4017,43 +4026,39 @@ var AxPromptTemplate = class {
|
|
|
4017
4026
|
const inArgs = this.renderDescFields(this.sig.getInputFields());
|
|
4018
4027
|
const outArgs = this.renderDescFields(this.sig.getOutputFields());
|
|
4019
4028
|
const task = [
|
|
4020
|
-
|
|
4021
|
-
Given the fields ${inArgs}, produce the fields ${outArgs}.`
|
|
4029
|
+
`You will be provided with the following fields: ${inArgs}. Your task is to generate two new fields: ${outArgs}.`
|
|
4022
4030
|
];
|
|
4023
|
-
const
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
return f.name;
|
|
4028
|
-
});
|
|
4029
|
-
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");
|
|
4030
4035
|
if (funcList && funcList.length > 0) {
|
|
4036
|
+
task.push(`## Available Functions
|
|
4037
|
+
${funcList}`);
|
|
4031
4038
|
task.push(
|
|
4032
|
-
`
|
|
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.`
|
|
4033
4040
|
);
|
|
4034
4041
|
}
|
|
4035
|
-
const desc = this.sig.getDescription();
|
|
4036
|
-
if (desc) {
|
|
4037
|
-
task.push(desc.endsWith(".") ? desc : desc + ".");
|
|
4038
|
-
}
|
|
4039
|
-
task.push(
|
|
4040
|
-
"Ensure the output strictly follows a plain text format, `key: value` separated by a new line."
|
|
4041
|
-
);
|
|
4042
4042
|
const inputFields = this.renderFields(this.sig.getInputFields());
|
|
4043
|
+
task.push(`## Input Fields
|
|
4044
|
+
${inputFields}`);
|
|
4043
4045
|
const outputFields = this.renderFields(this.sig.getOutputFields());
|
|
4046
|
+
task.push(`## Output Fields
|
|
4047
|
+
${outputFields}`);
|
|
4044
4048
|
task.push(
|
|
4045
|
-
|
|
4046
|
-
"\n",
|
|
4047
|
-
"## Input Fields",
|
|
4048
|
-
inputFields,
|
|
4049
|
-
"\n",
|
|
4050
|
-
"## Output Fields",
|
|
4051
|
-
outputFields
|
|
4052
|
-
].join("\n")
|
|
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."
|
|
4053
4050
|
);
|
|
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
|
+
}
|
|
4054
4059
|
this.task = {
|
|
4055
4060
|
type: "text",
|
|
4056
|
-
text: task.join("
|
|
4061
|
+
text: task.join("\n\n")
|
|
4057
4062
|
};
|
|
4058
4063
|
}
|
|
4059
4064
|
render = (values, {
|
|
@@ -4061,21 +4066,22 @@ Given the fields ${inArgs}, produce the fields ${outArgs}.`
|
|
|
4061
4066
|
demos
|
|
4062
4067
|
}) => {
|
|
4063
4068
|
const renderedExamples = examples ? [
|
|
4064
|
-
{ type: "text", text: "Examples:\n" },
|
|
4069
|
+
{ type: "text", text: "## Examples:\n" },
|
|
4065
4070
|
...this.renderExamples(examples)
|
|
4066
4071
|
] : [];
|
|
4067
4072
|
const renderedDemos = demos ? this.renderDemos(demos) : [];
|
|
4068
4073
|
const completion = this.renderInputFields(values);
|
|
4069
4074
|
const allTextExamples = renderedExamples.every((v) => v.type === "text");
|
|
4070
4075
|
const allTextDemos = renderedDemos.every((v) => v.type === "text");
|
|
4076
|
+
const examplesInSystemPrompt = allTextExamples && allTextDemos;
|
|
4071
4077
|
let systemContent = this.task.text;
|
|
4072
|
-
if (
|
|
4078
|
+
if (examplesInSystemPrompt) {
|
|
4073
4079
|
const combinedItems = [
|
|
4074
|
-
{ type: "text", text:
|
|
4080
|
+
{ type: "text", text: systemContent + "\n\n" },
|
|
4075
4081
|
...renderedExamples,
|
|
4076
4082
|
...renderedDemos
|
|
4077
4083
|
];
|
|
4078
|
-
combinedItems.reduce(combineConsecutiveStrings("
|
|
4084
|
+
combinedItems.reduce(combineConsecutiveStrings(""), []);
|
|
4079
4085
|
if (combinedItems && combinedItems[0]) {
|
|
4080
4086
|
systemContent = combinedItems[0].text;
|
|
4081
4087
|
}
|
|
@@ -4084,7 +4090,7 @@ Given the fields ${inArgs}, produce the fields ${outArgs}.`
|
|
|
4084
4090
|
role: "system",
|
|
4085
4091
|
content: systemContent
|
|
4086
4092
|
};
|
|
4087
|
-
const promptList =
|
|
4093
|
+
const promptList = examplesInSystemPrompt ? completion : [...renderedExamples, ...renderedDemos, ...completion];
|
|
4088
4094
|
const prompt = promptList.filter((v) => v !== void 0);
|
|
4089
4095
|
const userContent = prompt.every((v) => v.type === "text") ? prompt.map((v) => v.text).join("\n") : prompt.reduce(combineConsecutiveStrings("\n"), []);
|
|
4090
4096
|
const userPrompt = {
|
|
@@ -4119,16 +4125,13 @@ Given the fields ${inArgs}, produce the fields ${outArgs}.`
|
|
|
4119
4125
|
const renderedItem = [...renderedInputItem, ...renderedOutputItem];
|
|
4120
4126
|
renderedItem.forEach((v) => {
|
|
4121
4127
|
if ("text" in v) {
|
|
4122
|
-
v.text = v.text;
|
|
4128
|
+
v.text = v.text + "\n";
|
|
4123
4129
|
}
|
|
4124
4130
|
if ("image" in v) {
|
|
4125
4131
|
v.image = v.image;
|
|
4126
4132
|
}
|
|
4127
4133
|
list.push(v);
|
|
4128
4134
|
});
|
|
4129
|
-
if (renderedItem.length > 0) {
|
|
4130
|
-
list.push({ type: "text", text: "\n" });
|
|
4131
|
-
}
|
|
4132
4135
|
}
|
|
4133
4136
|
return list;
|
|
4134
4137
|
};
|
|
@@ -4139,23 +4142,20 @@ Given the fields ${inArgs}, produce the fields ${outArgs}.`
|
|
|
4139
4142
|
const renderedItem = fields.map((field) => this.renderInField(field, item, true)).filter((v) => v !== void 0).flat();
|
|
4140
4143
|
renderedItem.slice(0, -1).forEach((v) => {
|
|
4141
4144
|
if ("text" in v) {
|
|
4142
|
-
v.text = v.text;
|
|
4145
|
+
v.text = v.text + "\n";
|
|
4143
4146
|
}
|
|
4144
4147
|
if ("image" in v) {
|
|
4145
4148
|
v.image = v.image;
|
|
4146
4149
|
}
|
|
4147
4150
|
list.push(v);
|
|
4148
4151
|
});
|
|
4149
|
-
if (renderedItem.length > 0) {
|
|
4150
|
-
list.push({ type: "text", text: "\n" });
|
|
4151
|
-
}
|
|
4152
4152
|
}
|
|
4153
4153
|
return list;
|
|
4154
4154
|
};
|
|
4155
4155
|
renderInputFields = (values) => {
|
|
4156
4156
|
const renderedItems = this.sig.getInputFields().map((field) => this.renderInField(field, values)).filter((v) => v !== void 0).flat();
|
|
4157
4157
|
renderedItems.filter((v) => v.type === "text").forEach((v) => {
|
|
4158
|
-
v.text = v.text + "\n
|
|
4158
|
+
v.text = v.text + "\n";
|
|
4159
4159
|
});
|
|
4160
4160
|
return renderedItems;
|
|
4161
4161
|
};
|
|
@@ -4269,16 +4269,14 @@ Given the fields ${inArgs}, produce the fields ${outArgs}.`
|
|
|
4269
4269
|
};
|
|
4270
4270
|
renderDescFields = (list) => list.map((v) => `\`${v.title}\``).join(", ");
|
|
4271
4271
|
renderFields = (fields) => {
|
|
4272
|
-
const header = "Field Name | Field Type | Required/Optional | Description";
|
|
4273
|
-
const separator = "|";
|
|
4274
4272
|
const rows = fields.map((field) => {
|
|
4275
4273
|
const name = field.title;
|
|
4276
4274
|
const type = field.type?.name ? toFieldType(field.type) : "string";
|
|
4277
4275
|
const required = field.isOptional ? "optional" : "required";
|
|
4278
|
-
const description = field.description
|
|
4279
|
-
return
|
|
4276
|
+
const description = field.description ? `: ${capitalizeFirstLetter(field.description)}` : "";
|
|
4277
|
+
return `- \`${name}\` (${type}, ${required})${description}`.trim();
|
|
4280
4278
|
});
|
|
4281
|
-
return
|
|
4279
|
+
return rows.join("\n");
|
|
4282
4280
|
};
|
|
4283
4281
|
};
|
|
4284
4282
|
var processValue = (field, value) => {
|
|
@@ -4353,6 +4351,12 @@ var isEmptyValue = (field, value) => {
|
|
|
4353
4351
|
}
|
|
4354
4352
|
return false;
|
|
4355
4353
|
};
|
|
4354
|
+
function capitalizeFirstLetter(str) {
|
|
4355
|
+
if (str.length === 0) {
|
|
4356
|
+
return "";
|
|
4357
|
+
}
|
|
4358
|
+
return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
|
|
4359
|
+
}
|
|
4356
4360
|
|
|
4357
4361
|
// dsp/validate.ts
|
|
4358
4362
|
var AxValidationError = class extends Error {
|