Skip to content

Commit

Permalink
qa chain modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
HemanthSai7 committed Dec 19, 2023
1 parent d969120 commit 30f7c43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
34 changes: 18 additions & 16 deletions StudybotAPI/backend/utils/chain_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def llm_chain_loader(DATA_PATH: str):
prompt = f.read()

prompt = PromptTemplate(
template=prompt, input_variables=["context", "chat_history", "question"]
template=prompt, input_variables=["context", "question"]
)

llm = Clarifai(
Expand All @@ -32,24 +32,26 @@ async def llm_chain_loader(DATA_PATH: str):
model_version_id=config.MODEL_VERSION_ID,
)

# qa_chain = RetrievalQA.from_chain_type(
# llm=llm,
# chain_type="stuff",
# retriever=db.as_retriever(search_type="similarity",search_kwargs={"k": 2}),
# return_source_documents=True,
# chain_type_kwargs={"prompt": prompt},
# )

memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
qa_chain = ConversationalRetrievalChain.from_llm(
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=db.as_retriever(
search_type="mmr", search_kwargs={"k": 2, "fetch_k": 4}),
# return_source_documents=True,
# chain_type_kwargs={"prompt": prompt},
condense_question_prompt=prompt,
memory=memory,
search_type="mmr", search_kwargs={"k": 2, "fetch_k": 4}
),
return_source_documents=True,
chain_type_kwargs={"prompt": prompt},
)

# memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
# qa_chain = ConversationalRetrievalChain.from_llm(
# llm=llm,
# chain_type="stuff",
# retriever=db.as_retriever(
# search_type="mmr", search_kwargs={"k": 2, "fetch_k": 4}),
# # return_source_documents=True,
# # chain_type_kwargs={"prompt": prompt},
# condense_question_prompt=prompt,
# memory=memory,
# )

app.state.qa_chain = qa_chain
5 changes: 1 addition & 4 deletions StudybotAPI/backend/utils/prompt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ The "SOURCES" part should be a reference to the source of the document from whic
Consider a student engaged in the study of any theoretical subject, where the abundance of concepts and events poses a challenge to memorization. The aim is to overcome this hurdle and be capable of providing brief answers to specific queries. For example, if a student forgets a key concept, date, or event, they can ask the bot a question like "What is [specific query]?" for a concise answer.
Note that students can also ask multiple questions in a single query. For example, "What is [specific query 1]?, What is [specific query 2]?, What is [specific query 3]?".

Chat History:
{chat_history}

Follow Up Input: {question}
Standalone question:
{question}

[/INST]

0 comments on commit 30f7c43

Please sign in to comment.