Commit
·
3cf6d01
1
Parent(s):
6006bfe
abcd
Browse files
main.py
CHANGED
|
@@ -14,7 +14,6 @@ from pydantic.main import BaseModel
|
|
| 14 |
from typing_extensions import List, TypedDict
|
| 15 |
|
| 16 |
from langchain_cohere import CohereEmbeddings
|
| 17 |
-
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 18 |
|
| 19 |
import re
|
| 20 |
# from dotenv import load_dotenv
|
|
@@ -71,14 +70,7 @@ docs = [Document(page_content=text.page_content, metadata=text.metadata) for tex
|
|
| 71 |
_ = vector_store.add_documents(documents=docs)
|
| 72 |
|
| 73 |
|
| 74 |
-
prompt =
|
| 75 |
-
SystemMessage(content="""You are a helpful FAQ chatbot assistant for the Coherence 2025 Hackathon.
|
| 76 |
-
Use the provided context to answer questions accurately and concisely.
|
| 77 |
-
If the answer cannot be found in the context, say so clearly.
|
| 78 |
-
Keep your responses friendly and professional."""),
|
| 79 |
-
MessagesPlaceholder(variable_name="context"),
|
| 80 |
-
HumanMessage(content="{question}")
|
| 81 |
-
])
|
| 82 |
|
| 83 |
class State(TypedDict):
|
| 84 |
question: str
|
|
@@ -91,10 +83,8 @@ def retrieve(state: State):
|
|
| 91 |
|
| 92 |
def generate(state: State):
|
| 93 |
docs_content = "\n\n".join(doc.page_content for doc in state["context"])
|
| 94 |
-
messages = prompt.
|
| 95 |
-
|
| 96 |
-
question=state["question"]
|
| 97 |
-
)
|
| 98 |
response = llm.invoke(messages)
|
| 99 |
return {"answer": response.content}
|
| 100 |
|
|
|
|
| 14 |
from typing_extensions import List, TypedDict
|
| 15 |
|
| 16 |
from langchain_cohere import CohereEmbeddings
|
|
|
|
| 17 |
|
| 18 |
import re
|
| 19 |
# from dotenv import load_dotenv
|
|
|
|
| 70 |
_ = vector_store.add_documents(documents=docs)
|
| 71 |
|
| 72 |
|
| 73 |
+
prompt = hub.pull("rlm/rag-prompt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
class State(TypedDict):
|
| 76 |
question: str
|
|
|
|
| 83 |
|
| 84 |
def generate(state: State):
|
| 85 |
docs_content = "\n\n".join(doc.page_content for doc in state["context"])
|
| 86 |
+
messages = prompt.invoke({"question": state["question"], "context": docs_content})
|
| 87 |
+
print(messages)
|
|
|
|
|
|
|
| 88 |
response = llm.invoke(messages)
|
| 89 |
return {"answer": response.content}
|
| 90 |
|