agsamantha/node_modules/langchain/dist/agents/toolkits/conversational_retrieval/tool.js

17 lines
705 B
JavaScript
Raw Normal View History

2024-10-02 15:15:21 -05:00
import { z } from "zod";
import { DynamicStructuredTool, } from "@langchain/core/tools";
import { formatDocumentsAsString } from "../../../util/document.js";
/** @deprecated Use "langchain/tools/retriever" instead. */
export function createRetrieverTool(retriever, input) {
const func = async ({ input }, runManager) => {
const docs = await retriever.getRelevantDocuments(input, runManager?.getChild("retriever"));
return formatDocumentsAsString(docs);
};
const schema = z.object({
input: z
.string()
.describe("Natural language query used as input to the retriever"),
});
return new DynamicStructuredTool({ ...input, func, schema });
}