mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
Make StuffDocumentsChain doc separator configurable (#3718)
This PR makes the `"\n\n"` string with which `StuffDocumentsChain` joins formatted documents a property so it can be configured. The new `document_separator` property defaults to `"\n\n"` so the change is backwards compatible.
This commit is contained in:
parent
64ba24292d
commit
22770f5202
@ -30,6 +30,8 @@ class StuffDocumentsChain(BaseCombineDocumentsChain):
|
|||||||
document_variable_name: str
|
document_variable_name: str
|
||||||
"""The variable name in the llm_chain to put the documents in.
|
"""The variable name in the llm_chain to put the documents in.
|
||||||
If only one variable in the llm_chain, this need not be provided."""
|
If only one variable in the llm_chain, this need not be provided."""
|
||||||
|
document_separator: str = "\n\n"
|
||||||
|
"""The string with which to join the formatted documents"""
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
"""Configuration for this pydantic object."""
|
"""Configuration for this pydantic object."""
|
||||||
@ -66,7 +68,7 @@ class StuffDocumentsChain(BaseCombineDocumentsChain):
|
|||||||
for k, v in kwargs.items()
|
for k, v in kwargs.items()
|
||||||
if k in self.llm_chain.prompt.input_variables
|
if k in self.llm_chain.prompt.input_variables
|
||||||
}
|
}
|
||||||
inputs[self.document_variable_name] = "\n\n".join(doc_strings)
|
inputs[self.document_variable_name] = self.document_separator.join(doc_strings)
|
||||||
return inputs
|
return inputs
|
||||||
|
|
||||||
def prompt_length(self, docs: List[Document], **kwargs: Any) -> Optional[int]:
|
def prompt_length(self, docs: List[Document], **kwargs: Any) -> Optional[int]:
|
||||||
|
Loading…
Reference in New Issue
Block a user