agsamantha/node_modules/langchain/dist/tools/retriever.js

14 lines
589 B
JavaScript
Raw Permalink 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";
export function createRetrieverTool(retriever, input) {
const func = async ({ query }, runManager) => {
const docs = await retriever.getRelevantDocuments(query, runManager?.getChild("retriever"));
return formatDocumentsAsString(docs);
};
const schema = z.object({
query: z.string().describe("query to look up in retriever"),
});
return new DynamicStructuredTool({ ...input, func, schema });
}