1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9642],{49642:function(e,t,i){i.d(t,{MapReduceDocumentsChain:function(){return l},RefineDocumentsChain:function(){return s},StuffDocumentsChain:function(){return u}});var n=i(45225),a=i(55547),r=i(83303);class u extends n.l{static lc_name(){return"StuffDocumentsChain"}get inputKeys(){return[this.inputKey,...this.llmChain.inputKeys].filter(e=>e!==this.documentVariableName)}get outputKeys(){return this.llmChain.outputKeys}constructor(e){super(e),Object.defineProperty(this,"llmChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"inputKey",{enumerable:!0,configurable:!0,writable:!0,value:"input_documents"}),Object.defineProperty(this,"documentVariableName",{enumerable:!0,configurable:!0,writable:!0,value:"context"}),this.llmChain=e.llmChain,this.documentVariableName=e.documentVariableName??this.documentVariableName,this.inputKey=e.inputKey??this.inputKey}_prepInputs(e){if(!(this.inputKey in e))throw Error(`Document key ${this.inputKey} not found.`);let{[this.inputKey]:t,...i}=e,n=t.map(({pageContent:e})=>e).join("\n\n");return{...i,[this.documentVariableName]:n}}async _call(e,t){return await this.llmChain.call(this._prepInputs(e),t?.getChild("combine_documents"))}_chainType(){return"stuff_documents_chain"}static async deserialize(e){if(!e.llm_chain)throw Error("Missing llm_chain");return new u({llmChain:await a.LLMChain.deserialize(e.llm_chain)})}serialize(){return{_type:this._chainType(),llm_chain:this.llmChain.serialize()}}}class l extends n.l{static lc_name(){return"MapReduceDocumentsChain"}get inputKeys(){return[this.inputKey,...this.combineDocumentChain.inputKeys]}get outputKeys(){return this.combineDocumentChain.outputKeys}constructor(e){super(e),Object.defineProperty(this,"llmChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"inputKey",{enumerable:!0,configurable:!0,writable:!0,value:"input_documents"}),Object.defineProperty(this,"documentVariableName",{enumerable:!0,configurable:!0,writable:!0,value:"context"}),Object.defineProperty(this,"returnIntermediateSteps",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxTokens",{enumerable:!0,configurable:!0,writable:!0,value:3e3}),Object.defineProperty(this,"maxIterations",{enumerable:!0,configurable:!0,writable:!0,value:10}),Object.defineProperty(this,"ensureMapStep",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"combineDocumentChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.llmChain=e.llmChain,this.combineDocumentChain=e.combineDocumentChain,this.documentVariableName=e.documentVariableName??this.documentVariableName,this.ensureMapStep=e.ensureMapStep??this.ensureMapStep,this.inputKey=e.inputKey??this.inputKey,this.maxTokens=e.maxTokens??this.maxTokens,this.maxIterations=e.maxIterations??this.maxIterations,this.returnIntermediateSteps=e.returnIntermediateSteps??!1}async _call(e,t){if(!(this.inputKey in e))throw Error(`Document key ${this.inputKey} not found.`);let{[this.inputKey]:i,...n}=e,a=i,r=[];for(let e=0;e<this.maxIterations;e+=1){let i=a.map(e=>({[this.documentVariableName]:e.pageContent,...n}));if(0!==e||!this.ensureMapStep){let e=await this.combineDocumentChain.llmChain.prompt.format(this.combineDocumentChain._prepInputs({[this.combineDocumentChain.inputKey]:a,...n}));if(await this.combineDocumentChain.llmChain.llm.getNumTokens(e)<this.maxTokens)break}let u=await this.llmChain.apply(i,t?Array.from({length:i.length},(e,i)=>t.getChild(`map_${i+1}`)):void 0),{outputKey:l}=this.llmChain;this.returnIntermediateSteps&&(r=r.concat(u.map(e=>e[l]))),a=u.map(e=>({pageContent:e[l],metadata:{}}))}let u={[this.combineDocumentChain.inputKey]:a,...n},l=await this.combineDocumentChain.call(u,t?.getChild("combine_documents"));return this.returnIntermediateSteps?{...l,intermediateSteps:r}:l}_chainType(){return"map_reduce_documents_chain"}static async deserialize(e){if(!e.llm_chain)throw Error("Missing llm_chain");if(!e.combine_document_chain)throw Error("Missing combine_document_chain");return new l({llmChain:await a.LLMChain.deserialize(e.llm_chain),combineDocumentChain:await u.deserialize(e.combine_document_chain)})}serialize(){return{_type:this._chainType(),llm_chain:this.llmChain.serialize(),combine_document_chain:this.combineDocumentChain.serialize()}}}class s extends n.l{static lc_name(){return"RefineDocumentsChain"}get defaultDocumentPrompt(){return new r.PromptTemplate({inputVariables:["page_content"],template:"{page_content}"})}get inputKeys(){return[...new Set([this.inputKey,...this.llmChain.inputKeys,...this.refineLLMChain.inputKeys])].filter(e=>e!==this.documentVariableName&&e!==this.initialResponseName)}get outputKeys(){return[this.outputKey]}constructor(e){super(e),Object.defineProperty(this,"llmChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"inputKey",{enumerable:!0,configurable:!0,writable:!0,value:"input_documents"}),Object.defineProperty(this,"outputKey",{enumerable:!0,configurable:!0,writable:!0,value:"output_text"}),Object.defineProperty(this,"documentVariableName",{enumerable:!0,configurable:!0,writable:!0,value:"context"}),Object.defineProperty(this,"initialResponseName",{enumerable:!0,configurable:!0,writable:!0,value:"existing_answer"}),Object.defineProperty(this,"refineLLMChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"documentPrompt",{enumerable:!0,configurable:!0,writable:!0,value:this.defaultDocumentPrompt}),this.llmChain=e.llmChain,this.refineLLMChain=e.refineLLMChain,this.documentVariableName=e.documentVariableName??this.documentVariableName,this.inputKey=e.inputKey??this.inputKey,this.outputKey=e.outputKey??this.outputKey,this.documentPrompt=e.documentPrompt??this.documentPrompt,this.initialResponseName=e.initialResponseName??this.initialResponseName}
1async _constructInitialInputs(e,t){let i={page_content:e.pageContent,...e.metadata},n={};return this.documentPrompt.inputVariables.forEach(e=>{n[e]=i[e]}),{[this.documentVariableName]:await this.documentPrompt.format({...n}),...t}}async _constructRefineInputs(e,t){let i={page_content:e.pageContent,...e.metadata},n={};this.documentPrompt.inputVariables.forEach(e=>{n[e]=i[e]});let a={[this.documentVariableName]:await this.documentPrompt.format({...n})};return{[this.initialResponseName]:t,...a}}async _call(e,t){if(!(this.inputKey in e))throw Error(`Document key ${this.inputKey} not found.`);let{[this.inputKey]:i,...n}=e,a=await this._constructInitialInputs(i[0],n),r=await this.llmChain.predict({...a},t?.getChild("answer")),u=[r];for(let e=1;e<i.length;e+=1){let a={...await this._constructRefineInputs(i[e],r),...n};r=await this.refineLLMChain.predict({...a},t?.getChild("refine")),u.push(r)}return{[this.outputKey]:r}}_chainType(){return"refine_documents_chain"}static async deserialize(e){let t=e.llm_chain;if(!t)throw Error("Missing llm_chain");let i=e.refine_llm_chain;if(!i)throw Error("Missing refine_llm_chain");return new s({llmChain:await a.LLMChain.deserialize(t),refineLLMChain:await a.LLMChain.deserialize(i)})}serialize(){return{_type:this._chainType(),llm_chain:this.llmChain.serialize(),refine_llm_chain:this.refineLLMChain.serialize()}}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.