Optimize code (#3412)

Co-authored-by: assert <zhangchengming@kkguan.com>
This commit is contained in:
张城铭 2023-04-24 12:04:59 +08:00 committed by GitHub
parent 3d8243ec95
commit 487a57ffe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,8 +40,8 @@ class StuffDocumentsChain(BaseCombineDocumentsChain):
@root_validator(pre=True) @root_validator(pre=True)
def get_default_document_variable_name(cls, values: Dict) -> Dict: def get_default_document_variable_name(cls, values: Dict) -> Dict:
"""Get default document variable name, if not provided.""" """Get default document variable name, if not provided."""
llm_chain_variables = values["llm_chain"].prompt.input_variables
if "document_variable_name" not in values: if "document_variable_name" not in values:
llm_chain_variables = values["llm_chain"].prompt.input_variables
if len(llm_chain_variables) == 1: if len(llm_chain_variables) == 1:
values["document_variable_name"] = llm_chain_variables[0] values["document_variable_name"] = llm_chain_variables[0]
else: else:
@ -50,7 +50,6 @@ class StuffDocumentsChain(BaseCombineDocumentsChain):
"multiple llm_chain_variables" "multiple llm_chain_variables"
) )
else: else:
llm_chain_variables = values["llm_chain"].prompt.input_variables
if values["document_variable_name"] not in llm_chain_variables: if values["document_variable_name"] not in llm_chain_variables:
raise ValueError( raise ValueError(
f"document_variable_name {values['document_variable_name']} was " f"document_variable_name {values['document_variable_name']} was "