File size: 733 Bytes
328b268
 
 
 
 
 
 
 
 
 
2826548
e182c41
328b268
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from langchain.chains import ConversationalRetrievalChain
from langchain.chains.base import Chain
from langchain.vectorstores.base import VectorStore

from app_modules.llm_inference import LLMInference


class QAChain(LLMInference):
    vectorstore: VectorStore

    def __init__(self, vectorstore, llm_loader):
        super().__init__(llm_loader)
        self.vectorstore = vectorstore

    def create_chain(self) -> Chain:
        qa = ConversationalRetrievalChain.from_llm(
            self.llm_loader.llm,
            self.vectorstore.as_retriever(search_kwargs=self.llm_loader.search_kwargs),
            max_tokens_limit=self.llm_loader.max_tokens_limit,
            return_source_documents=True,
        )

        return qa