jarguello76 commited on
Commit
dcbda4c
·
verified ·
1 Parent(s): 04f9b43

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +13 -6
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
- content_blocks = [
160
  f"<Document metadata={doc.metadata}>\n{doc.page_content}\n</Document>"
161
  for doc in docs
162
- ]
163
- combined_doc_text = "\n\n---\n\n".join(content_blocks)
164
-
165
- system_prefix = SystemMessage(content=combined_doc_text)
166
- return {"messages": [system_prefix] + state["messages"]}
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: