@langchain/core 0.3.3 → 0.3.4
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/prompts/prompt.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ type NonAlphanumeric = " " | "\t" | "\n" | "\r" | '"' | "'" | "{" | "[" | "(" |
|
|
|
38
38
|
*/
|
|
39
39
|
type ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;
|
|
40
40
|
export type ParamsFromFString<T extends string> = {
|
|
41
|
-
[Key in ExtractTemplateParamsRecursive<T>[number] | (string & Record<never, never>)]:
|
|
41
|
+
[Key in ExtractTemplateParamsRecursive<T>[number] | (string & Record<never, never>)]: any;
|
|
42
42
|
};
|
|
43
43
|
export type ExtractedFStringParams<T extends string, RunInput extends InputValues = Symbol> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;
|
|
44
44
|
/**
|
|
@@ -86,15 +86,20 @@ const parseMustache = (template) => {
|
|
|
86
86
|
return mustacheTemplateToNodes(parsed);
|
|
87
87
|
};
|
|
88
88
|
exports.parseMustache = parseMustache;
|
|
89
|
-
const interpolateFString = (template, values) =>
|
|
90
|
-
|
|
91
|
-
if (node.
|
|
92
|
-
|
|
89
|
+
const interpolateFString = (template, values) => {
|
|
90
|
+
return (0, exports.parseFString)(template).reduce((res, node) => {
|
|
91
|
+
if (node.type === "variable") {
|
|
92
|
+
if (node.name in values) {
|
|
93
|
+
const stringValue = typeof values[node.name] === "string"
|
|
94
|
+
? values[node.name]
|
|
95
|
+
: JSON.stringify(values[node.name]);
|
|
96
|
+
return res + stringValue;
|
|
97
|
+
}
|
|
98
|
+
throw new Error(`(f-string) Missing value for input ${node.name}`);
|
|
93
99
|
}
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
}, "");
|
|
100
|
+
return res + node.text;
|
|
101
|
+
}, "");
|
|
102
|
+
};
|
|
98
103
|
exports.interpolateFString = interpolateFString;
|
|
99
104
|
const interpolateMustache = (template, values) => {
|
|
100
105
|
configureMustache();
|
package/dist/prompts/template.js
CHANGED
|
@@ -78,15 +78,20 @@ export const parseMustache = (template) => {
|
|
|
78
78
|
const parsed = mustache.parse(template);
|
|
79
79
|
return mustacheTemplateToNodes(parsed);
|
|
80
80
|
};
|
|
81
|
-
export const interpolateFString = (template, values) =>
|
|
82
|
-
|
|
83
|
-
if (node.
|
|
84
|
-
|
|
81
|
+
export const interpolateFString = (template, values) => {
|
|
82
|
+
return parseFString(template).reduce((res, node) => {
|
|
83
|
+
if (node.type === "variable") {
|
|
84
|
+
if (node.name in values) {
|
|
85
|
+
const stringValue = typeof values[node.name] === "string"
|
|
86
|
+
? values[node.name]
|
|
87
|
+
: JSON.stringify(values[node.name]);
|
|
88
|
+
return res + stringValue;
|
|
89
|
+
}
|
|
90
|
+
throw new Error(`(f-string) Missing value for input ${node.name}`);
|
|
85
91
|
}
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}, "");
|
|
92
|
+
return res + node.text;
|
|
93
|
+
}, "");
|
|
94
|
+
};
|
|
90
95
|
export const interpolateMustache = (template, values) => {
|
|
91
96
|
configureMustache();
|
|
92
97
|
return mustache.render(template, values);
|