mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-01 02:50:47 +00:00
upstage: Upstage Groundedness Check parameter update (#20914)
* Groundedness Check takes `str` or `list[Document]` as input. * Deprecate `GroundednessCheck` due to its naming. * Added `UpstageGroundednessCheck`. * Hotfix for Groundedness Check parameter. The name `query` was misleading and it should be `answer` instead. --------- Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
@@ -17,15 +17,14 @@
|
||||
"from typing import List\n",
|
||||
"\n",
|
||||
"from langchain_community.vectorstores import DocArrayInMemorySearch\n",
|
||||
"from langchain_core.documents.base import Document\n",
|
||||
"from langchain_core.output_parsers import StrOutputParser\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from langchain_core.runnables import RunnablePassthrough\n",
|
||||
"from langchain_core.runnables.base import RunnableSerializable\n",
|
||||
"from langchain_upstage import (\n",
|
||||
" ChatUpstage,\n",
|
||||
" GroundednessCheck,\n",
|
||||
" UpstageEmbeddings,\n",
|
||||
" UpstageGroundednessCheck,\n",
|
||||
" UpstageLayoutAnalysisLoader,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
@@ -50,7 +49,7 @@
|
||||
"\n",
|
||||
"retrieved_docs = retriever.get_relevant_documents(\"How many parameters in SOLAR model?\")\n",
|
||||
"\n",
|
||||
"groundedness_check = GroundednessCheck()\n",
|
||||
"groundedness_check = UpstageGroundednessCheck()\n",
|
||||
"groundedness = \"\"\n",
|
||||
"while groundedness != \"grounded\":\n",
|
||||
" chain: RunnableSerializable = RunnablePassthrough() | prompt | model | output_parser\n",
|
||||
@@ -62,14 +61,10 @@
|
||||
" }\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # convert all Documents to string\n",
|
||||
" def formatDocumentsAsString(docs: List[Document]) -> str:\n",
|
||||
" return \"\\n\".join([doc.page_content for doc in docs])\n",
|
||||
"\n",
|
||||
" groundedness = groundedness_check.run(\n",
|
||||
" groundedness = groundedness_check.invoke(\n",
|
||||
" {\n",
|
||||
" \"context\": formatDocumentsAsString(retrieved_docs),\n",
|
||||
" \"query\": result,\n",
|
||||
" \"context\": retrieved_docs,\n",
|
||||
" \"answer\": result,\n",
|
||||
" }\n",
|
||||
" )"
|
||||
]
|
||||
|
Reference in New Issue
Block a user