This commit is contained in:
Nuno Campos
2023-10-23 15:27:05 +01:00
parent 577bf5205a
commit f363310d80
+13 -13
View File
@@ -25,7 +25,7 @@
"from langchain.schema.document import Document\n",
"from langchain.schema import format_document\n",
"\n",
"from permchain import Channels, Pregel, PregelRead\n"
"from permchain import Channels, Pregel, PregelRead"
]
},
{
@@ -45,7 +45,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.schema.runnable import RunnableLambda\n"
"from langchain.schema.runnable import RunnableLambda"
]
},
{
@@ -59,7 +59,7 @@
"\n",
"_combine_documents = RunnableLambda(\n",
" lambda x: format_document(x, DEFAULT_DOCUMENT_PROMPT)\n",
").map() | (lambda x: \"\\n\\n\".join(x))\n"
").map() | (lambda x: \"\\n\\n\".join(x))"
]
},
{
@@ -72,7 +72,7 @@
"docs = [\n",
" Document(page_content=\"Harrison used to work at Kensho\"),\n",
" Document(page_content=\"Ankush worked at Facebook\"),\n",
"]\n"
"]"
]
},
{
@@ -98,7 +98,7 @@
" )\n",
" | ChatOpenAI()\n",
" | StrOutputParser()\n",
")\n"
")"
]
},
{
@@ -119,7 +119,7 @@
}
],
"source": [
"stuff_chain.invoke({\"question\": \"where did harrison work\", \"docs\": docs})\n"
"stuff_chain.invoke({\"question\": \"where did harrison work\", \"docs\": docs})"
]
},
{
@@ -139,7 +139,7 @@
"metadata": {},
"outputs": [],
"source": [
"many_docs = docs * 5\n"
"many_docs = docs * 5"
]
},
{
@@ -164,7 +164,7 @@
" new_result_doc_list.append(_sub_result_docs[:-1])\n",
" _sub_result_docs = _sub_result_docs[-1:]\n",
" new_result_doc_list.append(_sub_result_docs)\n",
" return new_result_doc_list\n"
" return new_result_doc_list"
]
},
{
@@ -196,7 +196,7 @@
"source": [
"# Just to show what its like split\n",
"split_docs = _split_list_of_docs(many_docs)\n",
"split_docs\n"
"split_docs"
]
},
{
@@ -214,7 +214,7 @@
" \"docs_to_finalize\": Channels.Inbox(Document),\n",
" # output\n",
" \"answer\": Channels.LastValue(str),\n",
"}\n"
"}"
]
},
{
@@ -249,7 +249,7 @@
" Pregel.subscribe_to(\"docs_to_finalize\", key=\"docs\").join([\"question\"])\n",
" | stuff_chain\n",
" | Pregel.write_to(\"answer\")\n",
")\n"
")"
]
},
{
@@ -268,7 +268,7 @@
" input=[\"question\", \"docs\"],\n",
" output=\"answer\",\n",
" debug=True,\n",
")\n"
")"
]
},
{
@@ -332,7 +332,7 @@
}
],
"source": [
"reduce_chain.invoke({\"question\": \"where did harrison work\", \"docs\": many_docs})\n"
"reduce_chain.invoke({\"question\": \"where did harrison work\", \"docs\": many_docs})"
]
},
{