Update rag.py
Browse files
rag.py
CHANGED
|
@@ -34,7 +34,7 @@ loader = DirectoryLoader('.', glob="all_dialogues.txt")
|
|
| 34 |
docs = loader.load()
|
| 35 |
|
| 36 |
text_splitter = RecursiveCharacterTextSplitter(
|
| 37 |
-
chunk_size=
|
| 38 |
)
|
| 39 |
texts = text_splitter.split_documents(docs)
|
| 40 |
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
|
@@ -49,7 +49,7 @@ 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)
|
|
@@ -76,24 +76,20 @@ 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
|
| 80 |
-
"
|
|
|
|
|
|
|
| 81 |
|
| 82 |
prompt = f"""{system_message}
|
| 83 |
-
|
| 84 |
-
Context:
|
| 85 |
-
{context}
|
| 86 |
-
|
| 87 |
Question:
|
| 88 |
{message}
|
| 89 |
-
|
| 90 |
Rules:
|
| 91 |
-
-
|
| 92 |
-
-
|
| 93 |
- Keep answers under 5 sentences
|
| 94 |
- Include book/season references when possible
|
| 95 |
-
-
|
| 96 |
-
|
| 97 |
"""
|
| 98 |
|
| 99 |
response = model.generate_content(prompt)
|
|
|
|
| 34 |
docs = loader.load()
|
| 35 |
|
| 36 |
text_splitter = RecursiveCharacterTextSplitter(
|
| 37 |
+
chunk_size=300, chunk_overlap=100
|
| 38 |
)
|
| 39 |
texts = text_splitter.split_documents(docs)
|
| 40 |
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
# Vector Store Retriever
|
| 52 |
+
vector_retriever = db.as_retriever(search_kwargs={"k": 10})
|
| 53 |
|
| 54 |
# Keyword Retriever (BM25)
|
| 55 |
bm25_retriever = BM25Retriever.from_documents(texts)
|
|
|
|
| 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 maester and Harry Potter's Dumbledore. " +
|
| 80 |
+
"Answer the given question based on your knowledge, providing accurate details without mentioning any specific sources or context used. " +
|
| 81 |
+
"State how much you know about the topic, and do not provide faulty answers. " +
|
| 82 |
+
"If the answer is unclear, clarify what you mean rather than saying 'I do not know.'")
|
| 83 |
|
| 84 |
prompt = f"""{system_message}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
Question:
|
| 86 |
{message}
|
|
|
|
| 87 |
Rules:
|
| 88 |
+
- Do not mention the context or where the information comes from
|
| 89 |
+
- State how much you know about the topic (e.g., 'I have detailed knowledge,' 'I have some knowledge,' or 'My knowledge is limited')
|
| 90 |
- Keep answers under 5 sentences
|
| 91 |
- Include book/season references when possible
|
| 92 |
+
- Answer based on relevant knowledge from Game of Thrones and Harry Potter
|
|
|
|
| 93 |
"""
|
| 94 |
|
| 95 |
response = model.generate_content(prompt)
|