@langchain/community
Version:
Third-party integrations for LangChain.js
1 lines • 6.79 kB
Source Map (JSON)
{"version":3,"file":"apify_dataset.d.cts","names":["ActorCallOptions","ApifyClient","ApifyClientOptions","TaskCallOptions","Document","AsyncCaller","AsyncCallerParams","BaseDocumentLoader","DocumentLoader","ApifyDatasetMappingFunction","Metadata","Record","Array","Promise","ApifyDatasetLoaderConfig","ApifyDatasetLoader"],"sources":["../../../src/document_loaders/web/apify_dataset.d.ts"],"sourcesContent":["import { ActorCallOptions, ApifyClient, ApifyClientOptions, TaskCallOptions } from \"apify-client\";\nimport { Document } from \"@langchain/core/documents\";\nimport { AsyncCaller, AsyncCallerParams } from \"@langchain/core/utils/async_caller\";\nimport { BaseDocumentLoader, DocumentLoader } from \"@langchain/core/document_loaders/base\";\n/**\n * A type that represents a function that takes a single object (an Apify\n * dataset item) and converts it to an instance of the Document class.\n *\n * Change function signature to only be asynchronous for simplicity in v0.1.0\n * https://github.com/langchain-ai/langchainjs/pull/3262\n */\nexport type ApifyDatasetMappingFunction<Metadata extends Record<string, any>> = (item: Record<string | number, unknown>) => Document<Metadata> | Array<Document<Metadata>> | Promise<Document<Metadata> | Array<Document<Metadata>>>;\nexport interface ApifyDatasetLoaderConfig<Metadata extends Record<string, any>> extends AsyncCallerParams {\n datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>;\n clientOptions?: ApifyClientOptions;\n}\n/**\n * A class that extends the BaseDocumentLoader and implements the\n * DocumentLoader interface. It represents a document loader that loads\n * documents from an Apify dataset.\n * @example\n * ```typescript\n * const loader = new ApifyDatasetLoader(\"your-dataset-id\", {\n * datasetMappingFunction: (item) =>\n * new Document({\n * pageContent: item.text || \"\",\n * metadata: { source: item.url },\n * }),\n * clientOptions: {\n * token: \"your-apify-token\",\n * },\n * });\n *\n * const docs = await loader.load();\n *\n * const chain = new RetrievalQAChain();\n * const res = await chain.invoke({ query: \"What is LangChain?\" });\n *\n * console.log(res.text);\n * console.log(res.sourceDocuments.map((d) => d.metadata.source));\n * ```\n */\nexport declare class ApifyDatasetLoader<Metadata extends Record<string, any>> extends BaseDocumentLoader implements DocumentLoader {\n protected apifyClient: ApifyClient;\n protected datasetId: string;\n protected datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>;\n protected caller: AsyncCaller;\n constructor(datasetId: string, config: ApifyDatasetLoaderConfig<Metadata>);\n /**\n * Creates an instance of the ApifyClient class with the provided clientOptions.\n * Adds a User-Agent header to the request config for langchainjs attribution.\n * @param clientOptions\n * @private\n */\n private static _getApifyClient;\n private static _getApifyApiToken;\n /**\n * Adds a User-Agent header to the request config.\n * @param config\n * @private\n */\n private static _addUserAgent;\n /**\n * Retrieves the dataset items from the Apify platform and applies the\n * datasetMappingFunction to each item to create an array of Document\n * instances.\n * @returns An array of Document instances.\n */\n load(): Promise<Document<Metadata>[]>;\n /**\n * Create an ApifyDatasetLoader by calling an Actor on the Apify platform and waiting for its results to be ready.\n * @param actorId The ID or name of the Actor on the Apify platform.\n * @param input The input object of the Actor that you're trying to run.\n * @param config Options specifying settings for the Actor run.\n * @param config.datasetMappingFunction A function that takes a single object (an Apify dataset item) and converts it to an instance of the Document class.\n * @returns An instance of `ApifyDatasetLoader` with the results from the Actor run.\n */\n static fromActorCall<Metadata extends Record<string, any>>(actorId: string, input: Record<string | number, unknown>, config: {\n callOptions?: ActorCallOptions;\n clientOptions?: ApifyClientOptions;\n datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>;\n }): Promise<ApifyDatasetLoader<Metadata>>;\n /**\n * Create an ApifyDatasetLoader by calling a saved Actor task on the Apify platform and waiting for its results to be ready.\n * @param taskId The ID or name of the task on the Apify platform.\n * @param input The input object of the task that you're trying to run. Overrides the task's saved input.\n * @param config Options specifying settings for the task run.\n * @param config.callOptions Options specifying settings for the task run.\n * @param config.clientOptions Options specifying settings for the Apify client.\n * @param config.datasetMappingFunction A function that takes a single object (an Apify dataset item) and converts it to an instance of the Document class.\n * @returns An instance of `ApifyDatasetLoader` with the results from the task's run.\n */\n static fromActorTaskCall<Metadata extends Record<string, any>>(taskId: string, input: Record<string | number, unknown>, config: {\n callOptions?: TaskCallOptions;\n clientOptions?: ApifyClientOptions;\n datasetMappingFunction: ApifyDatasetMappingFunction<Metadata>;\n }): Promise<ApifyDatasetLoader<Metadata>>;\n}\n//# sourceMappingURL=apify_dataset.d.ts.map"],"mappings":";;;;;;;;;AAWA;;;;;AAAgKU,KAApJD,2BAAoJC,CAAAA,iBAAvGC,MAAuGD,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,GAAAA,CAAAA,IAAAA,EAAzEC,MAAyED,CAAAA,MAAAA,GAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,GAApCN,QAAoCM,CAA3BA,QAA2BA,CAAAA,GAAfE,KAAeF,CAATN,QAASM,CAAAA,QAAAA,CAAAA,CAAAA,GAAaG,OAAbH,CAAqBN,QAArBM,CAA8BA,QAA9BA,CAAAA,GAA0CE,KAA1CF,CAAgDN,QAAhDM,CAAyDA,QAAzDA,CAAAA,CAAAA,CAAAA;AAATN,UACtIU,wBADsIV,CAAAA,iBAC5FO,MAD4FP,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,SAC/DE,iBAD+DF,CAAAA;EAANQ,sBAAAA,EAErHH,2BAFqHG,CAEzFF,QAFyFE,CAAAA;EAA6CF,aAAAA,CAAAA,EAG1KR,kBAH0KQ;;;;;;AAAV;AACpL;;;;;;AAAyG;AA8BzG;;;;;;;;;;;;;;AAqCwBR,cArCHa,kBAqCGb,CAAAA,iBArCiCS,MAqCjCT,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,SArC8DK,kBAAAA,YAA8BC,cAqC5FN,CAAAA;EACoCQ,UAAAA,WAAAA,EArCjCT,WAqCiCS;EAA5BD,UAAAA,SAAAA,EAAAA,MAAAA;EACGC,UAAAA,sBAAAA,EApCGD,2BAoCHC,CApC+BA,QAoC/BA,CAAAA;EAAnBK,UAAAA,MAAAA,EAnCMV,WAmCNU;EAARF,WAAAA,CAAAA,SAAAA,EAAAA,MAAAA,EAAAA,MAAAA,EAlCmCC,wBAkCnCD,CAlC4DH,QAkC5DG,CAAAA;EAWsCF;;;;;;EAIXD,eAAAA,eAAAA;EAAnBK,eAAAA,iBAAAA;EAARF;;;AAtD0H;;;;;;;;;UA0BtHA,QAAQT,SAASM;;;;;;;;;wCASaC,6CAA6CA;kBACjEX;oBACEE;4BACQO,4BAA4BC;MACpDG,QAAQE,mBAAmBL;;;;;;;;;;;4CAWWC,4CAA4CA;kBACpER;oBACED;4BACQO,4BAA4BC;MACpDG,QAAQE,mBAAmBL"}