@@ -4,6 +4,11 @@ import { LLMResult } from "../../schema/index.js";
44import  {  LLMChain  }  from  "../llm_chain.js" ; 
55import  {  PromptTemplate  }  from  "../../prompts/index.js" ; 
66import  {  SimpleSequentialChain  }  from  "../simple_sequential_chain.js" ; 
7+ import  {  AnalyzeDocumentChain  }  from  "../analyze_documents_chain.js" ; 
8+ import  {  ConversationalRetrievalQAChain  }  from  "../conversational_retrieval_chain.js" ; 
9+ import  {  VectorStoreRetriever  }  from  "../../vectorstores/base.js" ; 
10+ import  {  FakeEmbeddings  }  from  "../../embeddings/fake.js" ; 
11+ import  {  MemoryVectorStore  }  from  "../../vectorstores/memory.js" ; 
712
813class  FakeLLM1  extends  BaseLLM  { 
914  nrMapCalls  =  0 ; 
@@ -64,3 +69,50 @@ test("Test SimpleSequentialChain", async () => {
6469  const  response  =  await  combinedChain . run ( "initial question" ) ; 
6570  expect ( response ) . toEqual ( "final answer" ) ; 
6671} ) ; 
72+ 
73+ test ( "Test SimpleSequentialChain input chains' single input validation" ,  async  ( )  =>  { 
74+   const  model1  =  new  FakeLLM1 ( { } ) ; 
75+   const  model2  =  new  FakeLLM2 ( { } ) ; 
76+   const  template  =  "Some arbitrary template with fake {input1} and {input2}." ; 
77+   const  prompt  =  new  PromptTemplate ( { 
78+     template, 
79+     inputVariables : [ "input1" ,  "input2" ] , 
80+   } ) ; 
81+   const  chain1  =  new  LLMChain ( {  llm : model1 ,  prompt } ) ; 
82+   const  chain2  =  new  LLMChain ( {  llm : model2 ,  prompt } ) ; 
83+   expect ( ( )  =>  { 
84+     /* eslint-disable no-new */ 
85+     new  SimpleSequentialChain ( {  chains : [ chain1 ,  chain2 ]  } ) ; 
86+   } ) . toThrowErrorMatchingInlineSnapshot ( 
87+     `"Chains used in SimpleSequentialChain should all have one input, got 2 for llm_chain."` 
88+   ) ; 
89+ } ) ; 
90+ 
91+ test ( "Test SimpleSequentialChain input chains' single ouput validation" ,  async  ( )  =>  { 
92+   const  model1  =  new  FakeLLM1 ( { } ) ; 
93+   const  fakeEmbeddings  =  new  FakeEmbeddings ( ) ; 
94+   const  anyStore  =  new  MemoryVectorStore ( fakeEmbeddings ) ; 
95+   const  retriever  =  new  VectorStoreRetriever ( { 
96+     vectorStore : anyStore , 
97+   } ) ; 
98+   const  template  =  "Some arbitrary template with fake {input}." ; 
99+   const  prompt  =  new  PromptTemplate ( {  template,  inputVariables : [ "input" ]  } ) ; 
100+   const  chain1  =  new  LLMChain ( {  llm : model1 ,  prompt } ) ; 
101+   const  chain2  =  new  ConversationalRetrievalQAChain ( { 
102+     retriever, 
103+     combineDocumentsChain : chain1 , 
104+     questionGeneratorChain : chain1 , 
105+     returnSourceDocuments : true , 
106+   } ) ; 
107+   // Chain below is is not meant to work in a real-life scenario. 
108+   // It's only combined this way to get one input/multiple outputs chain. 
109+   const  multipleOutputChain  =  new  AnalyzeDocumentChain ( { 
110+     combineDocumentsChain : chain2 , 
111+   } ) ; 
112+   expect ( ( )  =>  { 
113+     /* eslint-disable no-new */ 
114+     new  SimpleSequentialChain ( {  chains : [ chain1 ,  multipleOutputChain ]  } ) ; 
115+   } ) . toThrowErrorMatchingInlineSnapshot ( 
116+     `"Chains used in SimpleSequentialChain should all have one output, got 2 for analyze_document_chain."` 
117+   ) ; 
118+ } ) ; 
0 commit comments