llm-exe 2.1.7 → 2.1.8
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/dist/index.js +56 -3
- package/dist/index.mjs +56 -3
- package/package.json +1 -1
- package/readme.md +1 -1
package/dist/index.js
CHANGED
|
@@ -1723,7 +1723,7 @@ var _ListToArrayParser = class _ListToArrayParser extends BaseParser {
|
|
|
1723
1723
|
super("listToArray");
|
|
1724
1724
|
}
|
|
1725
1725
|
parse(text) {
|
|
1726
|
-
const lines = text.split("\n").map((s) => s.replace(
|
|
1726
|
+
const lines = text.split("\n").map((s) => s.replace(/^- /, "").replace(/\'/g, "'").trim());
|
|
1727
1727
|
return lines;
|
|
1728
1728
|
}
|
|
1729
1729
|
};
|
|
@@ -2236,11 +2236,27 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2236
2236
|
}
|
|
2237
2237
|
if (first.role === "system" && messages.length > 0) {
|
|
2238
2238
|
_outputObj.system = first.content;
|
|
2239
|
-
return messages
|
|
2239
|
+
return messages.map((m) => {
|
|
2240
|
+
if (m.role === "system") {
|
|
2241
|
+
return {
|
|
2242
|
+
...m,
|
|
2243
|
+
role: "user"
|
|
2244
|
+
};
|
|
2245
|
+
}
|
|
2246
|
+
return m;
|
|
2247
|
+
});
|
|
2240
2248
|
}
|
|
2241
2249
|
return [
|
|
2242
2250
|
first,
|
|
2243
|
-
...messages
|
|
2251
|
+
...messages.map((m) => {
|
|
2252
|
+
if (m.role === "system") {
|
|
2253
|
+
return {
|
|
2254
|
+
...m,
|
|
2255
|
+
role: "user"
|
|
2256
|
+
};
|
|
2257
|
+
}
|
|
2258
|
+
return m;
|
|
2259
|
+
})
|
|
2244
2260
|
];
|
|
2245
2261
|
}
|
|
2246
2262
|
__name(anthropicPromptSanitize, "anthropicPromptSanitize");
|
|
@@ -3088,6 +3104,42 @@ function getOutputParser(config, response) {
|
|
|
3088
3104
|
}
|
|
3089
3105
|
__name(getOutputParser, "getOutputParser");
|
|
3090
3106
|
|
|
3107
|
+
// src/utils/modules/debug.ts
|
|
3108
|
+
function debug(...args) {
|
|
3109
|
+
const debugValue = getEnvironmentVariable("LLM_EXE_DEBUG");
|
|
3110
|
+
const logs = [];
|
|
3111
|
+
for (const arg of args) {
|
|
3112
|
+
if (arg && typeof arg === "object") {
|
|
3113
|
+
if (arg instanceof Error) {
|
|
3114
|
+
} else if (arg instanceof Array) {
|
|
3115
|
+
logs.push(arg.map((item) => JSON.stringify(item, null, 2)));
|
|
3116
|
+
} else if (arg instanceof Map) {
|
|
3117
|
+
logs.push(Array.from(arg.entries()).map(([key, value]) => `${key}: ${JSON.stringify(value, null, 2)}`));
|
|
3118
|
+
} else if (arg instanceof Set) {
|
|
3119
|
+
logs.push(Array.from(arg).map((item) => JSON.stringify(item, null, 2)));
|
|
3120
|
+
} else if (arg instanceof Date) {
|
|
3121
|
+
logs.push(arg.toISOString());
|
|
3122
|
+
} else if (arg instanceof RegExp) {
|
|
3123
|
+
logs.push(arg.toString());
|
|
3124
|
+
} else {
|
|
3125
|
+
try {
|
|
3126
|
+
logs.push(JSON.stringify(arg, null, 2));
|
|
3127
|
+
} catch (error) {
|
|
3128
|
+
console.error("Error parsing object:", error);
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
} else if (typeof arg === "string") {
|
|
3132
|
+
logs.push(arg);
|
|
3133
|
+
} else {
|
|
3134
|
+
logs.push(arg);
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
if (typeof debugValue === "string" && debugValue !== "" && debugValue.toLowerCase() !== "undefined" && debugValue.toLowerCase() !== "null") {
|
|
3138
|
+
console.debug(...logs);
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
__name(debug, "debug");
|
|
3142
|
+
|
|
3091
3143
|
// src/utils/modules/isValidUrl.ts
|
|
3092
3144
|
function isValidUrl(input) {
|
|
3093
3145
|
try {
|
|
@@ -3105,6 +3157,7 @@ async function apiRequest(url, options) {
|
|
|
3105
3157
|
...options
|
|
3106
3158
|
};
|
|
3107
3159
|
try {
|
|
3160
|
+
debug(url, finalOptions);
|
|
3108
3161
|
if (!url || !isValidUrl(url)) {
|
|
3109
3162
|
throw new Error("Invalid URL");
|
|
3110
3163
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1675,7 +1675,7 @@ var _ListToArrayParser = class _ListToArrayParser extends BaseParser {
|
|
|
1675
1675
|
super("listToArray");
|
|
1676
1676
|
}
|
|
1677
1677
|
parse(text) {
|
|
1678
|
-
const lines = text.split("\n").map((s) => s.replace(
|
|
1678
|
+
const lines = text.split("\n").map((s) => s.replace(/^- /, "").replace(/\'/g, "'").trim());
|
|
1679
1679
|
return lines;
|
|
1680
1680
|
}
|
|
1681
1681
|
};
|
|
@@ -2188,11 +2188,27 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2188
2188
|
}
|
|
2189
2189
|
if (first.role === "system" && messages.length > 0) {
|
|
2190
2190
|
_outputObj.system = first.content;
|
|
2191
|
-
return messages
|
|
2191
|
+
return messages.map((m) => {
|
|
2192
|
+
if (m.role === "system") {
|
|
2193
|
+
return {
|
|
2194
|
+
...m,
|
|
2195
|
+
role: "user"
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
return m;
|
|
2199
|
+
});
|
|
2192
2200
|
}
|
|
2193
2201
|
return [
|
|
2194
2202
|
first,
|
|
2195
|
-
...messages
|
|
2203
|
+
...messages.map((m) => {
|
|
2204
|
+
if (m.role === "system") {
|
|
2205
|
+
return {
|
|
2206
|
+
...m,
|
|
2207
|
+
role: "user"
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
return m;
|
|
2211
|
+
})
|
|
2196
2212
|
];
|
|
2197
2213
|
}
|
|
2198
2214
|
__name(anthropicPromptSanitize, "anthropicPromptSanitize");
|
|
@@ -3040,6 +3056,42 @@ function getOutputParser(config, response) {
|
|
|
3040
3056
|
}
|
|
3041
3057
|
__name(getOutputParser, "getOutputParser");
|
|
3042
3058
|
|
|
3059
|
+
// src/utils/modules/debug.ts
|
|
3060
|
+
function debug(...args) {
|
|
3061
|
+
const debugValue = getEnvironmentVariable("LLM_EXE_DEBUG");
|
|
3062
|
+
const logs = [];
|
|
3063
|
+
for (const arg of args) {
|
|
3064
|
+
if (arg && typeof arg === "object") {
|
|
3065
|
+
if (arg instanceof Error) {
|
|
3066
|
+
} else if (arg instanceof Array) {
|
|
3067
|
+
logs.push(arg.map((item) => JSON.stringify(item, null, 2)));
|
|
3068
|
+
} else if (arg instanceof Map) {
|
|
3069
|
+
logs.push(Array.from(arg.entries()).map(([key, value]) => `${key}: ${JSON.stringify(value, null, 2)}`));
|
|
3070
|
+
} else if (arg instanceof Set) {
|
|
3071
|
+
logs.push(Array.from(arg).map((item) => JSON.stringify(item, null, 2)));
|
|
3072
|
+
} else if (arg instanceof Date) {
|
|
3073
|
+
logs.push(arg.toISOString());
|
|
3074
|
+
} else if (arg instanceof RegExp) {
|
|
3075
|
+
logs.push(arg.toString());
|
|
3076
|
+
} else {
|
|
3077
|
+
try {
|
|
3078
|
+
logs.push(JSON.stringify(arg, null, 2));
|
|
3079
|
+
} catch (error) {
|
|
3080
|
+
console.error("Error parsing object:", error);
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
} else if (typeof arg === "string") {
|
|
3084
|
+
logs.push(arg);
|
|
3085
|
+
} else {
|
|
3086
|
+
logs.push(arg);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
if (typeof debugValue === "string" && debugValue !== "" && debugValue.toLowerCase() !== "undefined" && debugValue.toLowerCase() !== "null") {
|
|
3090
|
+
console.debug(...logs);
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
__name(debug, "debug");
|
|
3094
|
+
|
|
3043
3095
|
// src/utils/modules/isValidUrl.ts
|
|
3044
3096
|
function isValidUrl(input) {
|
|
3045
3097
|
try {
|
|
@@ -3057,6 +3109,7 @@ async function apiRequest(url, options) {
|
|
|
3057
3109
|
...options
|
|
3058
3110
|
};
|
|
3059
3111
|
try {
|
|
3112
|
+
debug(url, finalOptions);
|
|
3060
3113
|
if (!url || !isValidUrl(url)) {
|
|
3061
3114
|
throw new Error("Invalid URL");
|
|
3062
3115
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-exe",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.8",
|
|
4
4
|
"description": "Simplify building LLM-powered apps with easy-to-use base components, supporting text and chat-based prompts with handlebars template engine, output parsers, and flexible function calling capabilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
package/readme.md
CHANGED
|
@@ -52,7 +52,7 @@ export async function YesOrNoBot<I extends string>(input: I) {
|
|
|
52
52
|
const prompt = llmExe
|
|
53
53
|
.createChatPrompt(instruction)
|
|
54
54
|
.addUserMessage(input)
|
|
55
|
-
.
|
|
55
|
+
.addUserMessage(`yes or no:`);
|
|
56
56
|
|
|
57
57
|
const parser = llmExe.createParser("stringExtract", { enum: ["yes", "no"] });
|
|
58
58
|
return llmExe.createLlmExecutor({ llm, prompt, parser }).execute({ input });
|