langflow/src/backend/langflow/components/chains/RetrievalQAWithSourcesChain.py
anovazzi1 fa4a01caed chore(RetrievalQAWithSourcesChain.py): reorder imports to improve readability and maintain consistency
chore(AZLyricsLoader.py): reorder imports to improve readability and maintain consistency

chore(AirbyteJSONLoader.py): reorder imports to improve readability and maintain consistency

chore(CoNLLULoader.py): add import for List from typing module to fix type hinting

chore(CollegeConfidentialLoader.py): add import for List from typing module to fix type hinting

chore(EverNoteLoader.py): reorder imports to improve readability and maintain consistency

chore(FacebookChatLoader.py): add import for List from typing module to fix type hinting

chore(GitbookLoader.py): reorder imports to improve readability and maintain consistency

chore(HNLoader.py): add import for List from typing module to fix type hinting

chore(IMSDbLoader.py): add import for List from typing module to fix type hinting

chore(TextLoader.py): reorder imports to improve readability and maintain consistency

chore(CohereEmbeddings.py): change default value of cohere_api_key parameter to an empty string

chore(OpenAIEmbeddings.py): change default values of allowed_special, disallowed_special, chunk_size, embedding_ctx_length, max_retries, show_progress_bar, skip_empty, and tikToken_enable parameters to their respective types
2024-01-25 19:11:06 -03:00

42 lines
1.5 KiB
Python

from typing import Optional
from langchain.chains import RetrievalQAWithSourcesChain
from langchain.chains.qa_with_sources.base import BaseQAWithSourcesChain
from langchain.chains.combine_documents.base import BaseCombineDocumentsChain
from langflow import CustomComponent
from langflow.field_typing import BaseLanguageModel, BaseMemory, BaseRetriever
class RetrievalQAWithSourcesChainComponent(CustomComponent):
display_name = "RetrievalQAWithSourcesChain"
description = "Question-answering with sources over an index."
def build_config(self):
return {
"llm": {"display_name": "LLM"},
"chain_type": {
"display_name": "Chain Type",
"options": ["stuff", "map_reduce", "map_rerank", "refine"],
},
"memory": {"display_name": "Memory"},
"return_source_documents": {"display_name": "Return Source Documents"},
}
def build(
self,
retriever: BaseRetriever,
llm: BaseLanguageModel,
combine_documents_chain: BaseCombineDocumentsChain,
chain_type: str,
memory: Optional[BaseMemory] = None,
return_source_documents: Optional[bool] = True,
) -> BaseQAWithSourcesChain:
return RetrievalQAWithSourcesChain.from_chain_type(
llm=llm,
chain_type=chain_type,
combine_documents_chain=combine_documents_chain,
memory=memory,
return_source_documents=return_source_documents,
retriever=retriever,
)