Skip to content

Commit

Permalink
retrieval QA
Browse files Browse the repository at this point in the history
  • Loading branch information
HemanthSai7 committed Dec 7, 2023
1 parent 5e311e5 commit c7f79c6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
6 changes: 1 addition & 5 deletions StudybotAPI/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@

from backend.ingestion import *

from langchain.llms import LlamaCpp
from langchain.llms import CTransformers
# from langchain.llms.huggingface_pipeline import HuggingFacePipeline


app = FastAPI(
title="StudyBot API", version="0.1.0", description="API for StudyBot Project"
)
app = FastAPI(title="StudyBot API", version="0.1.0", description="API for StudyBot Project")

from backend import routes
# from backend.retriever import EmbeddingModel
Expand Down
3 changes: 2 additions & 1 deletion StudybotAPI/backend/utils/chain_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def llm_chain_loader(DATA_PATH: str):
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=db.as_retriever(search_kwargs={"k": 2}),
retriever=db.as_retriever(search_type="similarity",search_kwargs={"k": 2}),
return_source_documents=True,
chain_type_kwargs={"prompt": prompt},
verbose=True,
)

app.state.qa_chain = qa_chain
67 changes: 44 additions & 23 deletions StudybotAPI/backend/utils/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,51 @@
{question} [/INST]
"""
knowledge_graph_prompt = """
"You are a network graph maker who extracts terms and their relations from a given context. "
"You are provided with a context chunk (delimited by ```) Your task is to extract the ontology "
"of terms mentioned in the given context. These terms should represent the key concepts as per the context. \n"
"Thought 1: While traversing through each sentence, Think about the key terms mentioned in it.\n"
"\tTerms may include object, entity, location, organization, person, \n"
"\tcondition, acronym, documents, service, concept, etc.\n"
"\tTerms should be as atomistic as possible\n\n"
"Thought 2: Think about how these terms can have one on one relation with other terms.\n"
"\tTerms that are mentioned in the same sentence or the same paragraph are typically related to each other.\n"
"\tTerms can be related to many other terms\n\n"
"Thought 3: Find out the relation between each such related pair of terms. \n\n"
"Format your output as a list of json. Each element of the list contains a pair of terms"
"and the relation between them, like the follwing: \n"
"[\n"
" {\n"
' "node_1": "A concept from extracted ontology",\n'
' "node_2": "A related concept from extracted ontology",\n'
' "edge": "relationship between the two concepts, node_1 and node_2 in one or two sentences"\n'
" }, {...}\n"
"]"


english_teacher = """
[INST] <>
You are an innovative language learning AI designed to assist students in improving their English language skills. Your goal is to provide helpful and engaging responses that aid in language comprehension, grammar, and vocabulary building. If you are unable to answer a question, respond with 'I am sorry, I don't have enough information.'
ALWAYS include a "RESOURCES" section in your answer, providing guidance on where students can find additional information or practice materials.
<>
{context}
```{input}```
output:
Imagine a student immersed in the study of the English language, aiming to enhance their understanding of grammar, vocabulary, and overall language proficiency. Your role is to assist them by providing concise and informative answers to specific language-related queries. For instance, if a student is uncertain about a grammatical rule or the meaning of a word, they can ask you questions like "What is [specific query]?" for clear and detailed responses.
Keep in mind that students may pose multiple questions within a single query. For example, "What is the meaning of [specific query 1]?, How do I use [specific query 2] in a sentence?, Can you explain the grammar rule for [specific query 3]?".
{question} [/INST]
"""


science_teacher = """
[INST] <>
You are a cutting-edge science education AI, dedicated to helping students grasp complex scientific concepts and theories. Your mission is to provide insightful and understandable explanations to foster a deeper understanding of various scientific topics. If you don't have enough information to answer a question, respond with 'I am sorry, I don't have enough information.'
Always include a "REFERENCES" section in your answer, directing students to relevant sources for further exploration.
<>
{context}
Envision a student engrossed in the study of science, navigating through intricate theories and phenomena. Your purpose is to assist them by offering clear and concise answers to their scientific inquiries. For instance, if a student is struggling to comprehend a particular scientific concept or needs clarification on an experiment, they can pose questions like "What is [specific query]?" for detailed responses.
It's important to note that students might present multiple questions within a single query. For instance, "Explain [specific query 1]?, How does [specific query 2] work?, Can you provide examples of [specific query 3]?".
{question} [/INST]
"""

prompt_infos = [
{
"name": "Math Teacher",
"description": "Good for answering questions about Social Sciences subject like History, Geography, Civics, etc.",
"prompt_template": social_sciences_teacher,
},
{
"name": "Spanish Teacher",
"description": "Good for answering questions about English Language",
"prompt_template": english_teacher,
},
{
"name": "Calculus Teacher",
"description": "Good for answering questions about Science subjects like Physics, Chemistry, Biology, etc.",
"prompt_template": science_teacher,
},
]

0 comments on commit c7f79c6

Please sign in to comment.