Update rag.py
Browse files
rag.py
CHANGED
|
@@ -49,11 +49,11 @@ db = FAISS.load_local(
|
|
| 49 |
|
| 50 |
|
| 51 |
# Vector Store Retriever
|
| 52 |
-
vector_retriever = db.as_retriever(search_kwargs={"k":
|
| 53 |
|
| 54 |
# Keyword Retriever (BM25)
|
| 55 |
bm25_retriever = BM25Retriever.from_documents(texts)
|
| 56 |
-
bm25_retriever.k =
|
| 57 |
|
| 58 |
# Combine both
|
| 59 |
def ensemble_retriever(query):
|
|
@@ -76,7 +76,8 @@ def respond_rag_huggingface(message: str):
|
|
| 76 |
context = "\n\n".join(doc.page_content for doc in docs)
|
| 77 |
|
| 78 |
system_message = os.environ.get("SYSTEM_MESSAGE",
|
| 79 |
-
"You are a Game of Thrones measter
|
|
|
|
| 80 |
|
| 81 |
prompt = f"""{system_message}
|
| 82 |
|
|
@@ -87,9 +88,13 @@ Question:
|
|
| 87 |
{message}
|
| 88 |
|
| 89 |
Rules:
|
| 90 |
-
- If the answer isn't in the context, respond with
|
|
|
|
| 91 |
- Keep answers under 5 sentences
|
| 92 |
-
- Include book/season references when possible
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
response = model.generate_content(prompt)
|
| 95 |
return response.text
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
# Vector Store Retriever
|
| 52 |
+
vector_retriever = db.as_retriever(search_kwargs={"k": 5})
|
| 53 |
|
| 54 |
# Keyword Retriever (BM25)
|
| 55 |
bm25_retriever = BM25Retriever.from_documents(texts)
|
| 56 |
+
bm25_retriever.k = 5
|
| 57 |
|
| 58 |
# Combine both
|
| 59 |
def ensemble_retriever(query):
|
|
|
|
| 76 |
context = "\n\n".join(doc.page_content for doc in docs)
|
| 77 |
|
| 78 |
system_message = os.environ.get("SYSTEM_MESSAGE",
|
| 79 |
+
"You are a Game of Thrones measter and harry potter's dumbledore"+
|
| 80 |
+
". Answer the given question based on the context understand the context and try to answer based upon the context.do not give faulty answers and if any dialogue or description mention them ")
|
| 81 |
|
| 82 |
prompt = f"""{system_message}
|
| 83 |
|
|
|
|
| 88 |
{message}
|
| 89 |
|
| 90 |
Rules:
|
| 91 |
+
- If the answer isn't in the context, respond with something you know about them and do not mention about about context
|
| 92 |
+
- try to say that i exactly mean different than i do not know
|
| 93 |
- Keep answers under 5 sentences
|
| 94 |
+
- Include book/season references when possible
|
| 95 |
+
- vector store contains both game of thrones and harry potter vectors so answer based on relevant context
|
| 96 |
+
|
| 97 |
+
"""
|
| 98 |
|
| 99 |
response = model.generate_content(prompt)
|
| 100 |
return response.text
|