# Fixed multi input prompt for MapReduceChain
Added `kwargs` support for inner chains of `MapReduceChain` via
`from_params` method
Currently the `from_method` method of intialising `MapReduceChain` chain
doesn't work if prompt has multiple inputs. It happens because it uses
`StuffDocumentsChain` and `MapReduceDocumentsChain` underneath, both of
them require specifying `document_variable_name` if `prompt` of their
`llm_chain` has more than one `input`.
With this PR, I have added support for passing their respective `kwargs`
via the `from_params` method.
## Fixes https://github.com/hwchase17/langchain/issues/4752
## Who can review?
@dev2049 @hwchase17 @agola11
---------
Co-authored-by: imeckr <chandanroutray2012@gmail.com>
"map_template_string = \"\"\"Give the following python code information, generate a description that explains what the code does and also mention the time complexity.\n",
"Code:\n",
"{code}\n",
"\n",
"Return the the description in the following format:\n",
"name of the function: description of the function\n",
"\"\"\"\n",
"\n",
"\n",
"reduce_template_string = \"\"\"Give the following following python fuctions name and their descritpion, answer the following question\n",
" while (InputList[j] > nxt_element) and (j >= 0):\n",
" InputList[j+1] = InputList[j]\n",
" j=j-1\n",
" InputList[j+1] = nxt_element\n",
" return InputList\n",
"##\n",
"def shellSort(input_list):\n",
" gap = len(input_list) // 2\n",
" while gap > 0:\n",
" for i in range(gap, len(input_list)):\n",
" temp = input_list[i]\n",
" j = i\n",
" while j >= gap and input_list[j - gap] > temp:\n",
" input_list[j] = input_list[j - gap]\n",
" j = j-gap\n",
" input_list[j] = temp\n",
" gap = gap//2\n",
" return input_list\n",
"\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "d5a9a35b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Created a chunk of size 247, which is longer than the specified 100\n",
"Created a chunk of size 267, which is longer than the specified 100\n"
]
},
{
"data": {
"text/plain": [
"'shellSort has a better time complexity than both bubblesort and insertion_sort, as it has a time complexity of O(n^2), while the other two have a time complexity of O(n^2).'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"map_reduce.run(input_text=code, question=\"Which function has a better time complexity?\")"