Created
September 10, 2023 15:40
-
-
Save sukanyabag/9cd82b4143347ad789037f60e3f88234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retrieve_text(self, query): | |
self.text_deeplake_schema = DeepLake( | |
dataset_path=cfg.TEXT_VECTORSTORE_PATH, | |
read_only=True, | |
embedding_function=self.embeddings, | |
) | |
prompt_template = """You are an intelligent AI which analyses text from documents and | |
answers the user's questions. Please answer in as much detail as possible, so that the user does not have to | |
revisit the document. If you don't know the answer, say that you don't know, and avoid making up things. | |
{context} | |
Question: {question} | |
Answer: | |
""" | |
PROMPT = PromptTemplate( | |
template=prompt_template, input_variables=["context", "question"] | |
) | |
chain_type_kwargs = {"prompt": PROMPT} | |
model = ChatOpenAI( | |
model_name="gpt-3.5-turbo", | |
openai_api_key=cfg.OPENAI_API_KEY, | |
) | |
qa = RetrievalQA.from_chain_type( | |
llm=model, | |
chain_type="stuff", | |
retriever=self.text_retriever, | |
return_source_documents=False, | |
verbose=False, | |
chain_type_kwargs=chain_type_kwargs, | |
memory=self.memory, | |
) | |
response = qa({"query": query}) | |
return response["result"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment