Spaces:
Sleeping
Sleeping
File size: 821 Bytes
c2b7eb3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import { patchConfig, pickRunnableConfigKeys } from "@langchain/core/runnables";
import { DynamicTool } from "@langchain/core/tools";
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
//#region src/tools/custom.ts
function customTool(func, fields) {
return new DynamicTool({
...fields,
description: "",
metadata: { customTool: fields },
func: async (input, runManager, config) => new Promise((resolve, reject) => {
const childConfig = patchConfig(config, { callbacks: runManager?.getChild() });
AsyncLocalStorageProviderSingleton.runWithConfig(pickRunnableConfigKeys(childConfig), async () => {
try {
resolve(func(input, childConfig));
} catch (e) {
reject(e);
}
});
})
});
}
//#endregion
export { customTool };
//# sourceMappingURL=custom.js.map |