Update rag_chain.py
Browse files- rag_chain.py +14 -4
rag_chain.py
CHANGED
|
@@ -4,7 +4,7 @@ from langchain_core.output_parsers import StrOutputParser
|
|
| 4 |
from langchain_core.runnables import RunnablePassthrough
|
| 5 |
|
| 6 |
def build_rag_chain(vectorstore, groq_api_key):
|
| 7 |
-
retriever = vectorstore.as_retriever(search_kwargs={"k":
|
| 8 |
|
| 9 |
llm = ChatGroq(
|
| 10 |
api_key=groq_api_key,
|
|
@@ -14,19 +14,29 @@ def build_rag_chain(vectorstore, groq_api_key):
|
|
| 14 |
|
| 15 |
prompt = ChatPromptTemplate.from_template(
|
| 16 |
"""
|
| 17 |
-
You are
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
Context:
|
| 21 |
{context}
|
| 22 |
|
| 23 |
Question:
|
| 24 |
{question}
|
|
|
|
|
|
|
| 25 |
"""
|
| 26 |
)
|
| 27 |
|
| 28 |
def format_docs(docs):
|
| 29 |
-
return "\n\n".join(
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
chain = (
|
| 32 |
{
|
|
|
|
| 4 |
from langchain_core.runnables import RunnablePassthrough
|
| 5 |
|
| 6 |
def build_rag_chain(vectorstore, groq_api_key):
|
| 7 |
+
retriever = vectorstore.as_retriever(search_kwargs={"k": 2})
|
| 8 |
|
| 9 |
llm = ChatGroq(
|
| 10 |
api_key=groq_api_key,
|
|
|
|
| 14 |
|
| 15 |
prompt = ChatPromptTemplate.from_template(
|
| 16 |
"""
|
| 17 |
+
You are a codebase assistant.
|
| 18 |
+
|
| 19 |
+
RULES:
|
| 20 |
+
- Use ONLY the context below.
|
| 21 |
+
- If information is missing, say:
|
| 22 |
+
"I cannot find this information in the provided codebase."
|
| 23 |
+
- Do NOT guess.
|
| 24 |
|
| 25 |
Context:
|
| 26 |
{context}
|
| 27 |
|
| 28 |
Question:
|
| 29 |
{question}
|
| 30 |
+
|
| 31 |
+
Answer:
|
| 32 |
"""
|
| 33 |
)
|
| 34 |
|
| 35 |
def format_docs(docs):
|
| 36 |
+
return "\n\n".join(
|
| 37 |
+
f"FILE: {d.metadata['file']}\n{d.page_content}"
|
| 38 |
+
for d in docs
|
| 39 |
+
)
|
| 40 |
|
| 41 |
chain = (
|
| 42 |
{
|