Skip to content

Instantly share code, notes, and snippets.

@sukanyabag
Created September 10, 2023 15:40
Show Gist options
  • Save sukanyabag/9cd82b4143347ad789037f60e3f88234 to your computer and use it in GitHub Desktop.
Save sukanyabag/9cd82b4143347ad789037f60e3f88234 to your computer and use it in GitHub Desktop.
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