Update tools.py
Browse files
tools.py
CHANGED
@@ -146,6 +146,13 @@ def build_graph(csv_file_path: str = "embeddings.csv"):
|
|
146 |
chat_model = ChatHuggingFace(llm=llm)
|
147 |
llm_with_tools = chat_model.bind_tools(tools=tools)
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
|
151 |
|
@@ -156,14 +163,14 @@ def build_graph(csv_file_path: str = "embeddings.csv"):
|
|
156 |
query_embedding = get_query_embedding(query)
|
157 |
docs = vector_store.similarity_search(query_embedding, k=2)
|
158 |
|
159 |
-
|
160 |
f"<Document metadata={doc.metadata}>\n{doc.page_content}\n</Document>"
|
161 |
for doc in docs
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
|
168 |
# Node function for assistant
|
169 |
def call_llm(state: MessagesState) -> MessagesState:
|
|
|
146 |
chat_model = ChatHuggingFace(llm=llm)
|
147 |
llm_with_tools = chat_model.bind_tools(tools=tools)
|
148 |
|
149 |
+
from sentence_transformers import SentenceTransformer
|
150 |
+
|
151 |
+
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
|
152 |
+
|
153 |
+
def get_query_embedding(query: str) -> np.ndarray:
|
154 |
+
return embedding_model.encode(query)
|
155 |
+
|
156 |
|
157 |
|
158 |
|
|
|
163 |
query_embedding = get_query_embedding(query)
|
164 |
docs = vector_store.similarity_search(query_embedding, k=2)
|
165 |
|
166 |
+
context = "\n\n---\n\n".join(
|
167 |
f"<Document metadata={doc.metadata}>\n{doc.page_content}\n</Document>"
|
168 |
for doc in docs
|
169 |
+
)
|
170 |
+
combined_content = f"{system_prompt}\n\nHere are relevant documents:\n\n{context}"
|
171 |
+
system_message = SystemMessage(content=combined_content)
|
172 |
+
return {"messages": [system_message, last_human_msg]}
|
173 |
+
|
174 |
|
175 |
# Node function for assistant
|
176 |
def call_llm(state: MessagesState) -> MessagesState:
|