Update agent.py
Browse files
agent.py
CHANGED
@@ -226,6 +226,24 @@ execute_code_multilang_tool = Tool(
|
|
226 |
### ======================================== DOCUMENT PROCESSING TOOLS ======================================== ###
|
227 |
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
# load the system prompt from the file
|
231 |
with open("system_prompt.txt", "r", encoding="utf-8") as f:
|
@@ -293,14 +311,6 @@ def build_graph(provider: str = "huggingface"):
|
|
293 |
def assistant(state: MessagesState):
|
294 |
"""Assistant node"""
|
295 |
return {"messages": [chat_with_tools.invoke(state["messages"])]}
|
296 |
-
|
297 |
-
# def retriever(state: MessagesState):
|
298 |
-
# """Retriever node"""
|
299 |
-
# similar_question = vector_store.similarity_search(state["messages"][0].content)
|
300 |
-
#example_msg = HumanMessage(
|
301 |
-
# content=f"Here I provide a similar question and answer for reference: \n\n{similar_question[0].page_content}",
|
302 |
-
# )
|
303 |
-
# return {"messages": [sys_msg] + state["messages"] + [example_msg]}
|
304 |
|
305 |
from langchain_core.messages import AIMessage
|
306 |
|
@@ -316,30 +326,34 @@ def build_graph(provider: str = "huggingface"):
|
|
316 |
|
317 |
return {"messages": [AIMessage(content=answer)]}
|
318 |
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
|
|
|
|
|
|
329 |
#builder.add_edge("tools", "assistant")
|
|
|
330 |
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
# Retriever ist Start und Endpunkt
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
# Compile graph
|
339 |
-
|
340 |
-
|
341 |
|
342 |
|
|
|
|
|
|
|
343 |
builder = StateGraph(MessagesState)
|
344 |
# Define nodes: these do the work
|
345 |
builder.add_node("assistant", assistant)
|
@@ -353,6 +367,6 @@ def build_graph(provider: str = "huggingface"):
|
|
353 |
tools_condition,
|
354 |
)
|
355 |
builder.add_edge("tools", "assistant")
|
356 |
-
|
357 |
# Compile graph
|
358 |
-
return builder.compile()
|
|
|
|
226 |
### ======================================== DOCUMENT PROCESSING TOOLS ======================================== ###
|
227 |
|
228 |
|
229 |
+
### ======================================== RETRIEVER TOOLS ======================================== ###
|
230 |
+
|
231 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2") # dim=768
|
232 |
+
supabase: Client = create_client(
|
233 |
+
os.environ.get("SUPABASE_URL"),
|
234 |
+
os.environ.get("SUPABASE_SERVICE_KEY"))
|
235 |
+
vector_store = SupabaseVectorStore(
|
236 |
+
client=supabase,
|
237 |
+
embedding= embeddings,
|
238 |
+
table_name="documents",
|
239 |
+
query_name="match_documents_langchain",
|
240 |
+
)
|
241 |
+
create_retriever_tool = create_retriever_tool(
|
242 |
+
retriever=vector_store.as_retriever(),
|
243 |
+
name="Question Search",
|
244 |
+
description="A tool to retrieve similar questions from a vector store.",
|
245 |
+
)
|
246 |
+
|
247 |
|
248 |
# load the system prompt from the file
|
249 |
with open("system_prompt.txt", "r", encoding="utf-8") as f:
|
|
|
311 |
def assistant(state: MessagesState):
|
312 |
"""Assistant node"""
|
313 |
return {"messages": [chat_with_tools.invoke(state["messages"])]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
from langchain_core.messages import AIMessage
|
316 |
|
|
|
326 |
|
327 |
return {"messages": [AIMessage(content=answer)]}
|
328 |
|
329 |
+
"""
|
330 |
+
Graph with retriever and tools
|
331 |
+
|
332 |
+
builder = StateGraph(MessagesState)
|
333 |
+
builder.add_node("retriever", retriever)
|
334 |
+
builder.add_node("assistant", assistant)
|
335 |
+
builder.add_node("tools", ToolNode(tools))
|
336 |
+
builder.add_edge(START, "retriever")
|
337 |
+
builder.add_edge("retriever", "assistant")
|
338 |
+
builder.add_conditional_edges(
|
339 |
+
"assistant",
|
340 |
+
tools_condition,
|
341 |
+
)
|
342 |
#builder.add_edge("tools", "assistant")
|
343 |
+
"""
|
344 |
|
345 |
+
builder = StateGraph(MessagesState)
|
346 |
+
builder.add_node("retriever", retriever)
|
|
|
347 |
# Retriever ist Start und Endpunkt
|
348 |
+
builder.set_entry_point("retriever")
|
349 |
+
builder.set_finish_point("retriever")
|
|
|
350 |
# Compile graph
|
351 |
+
return builder.compile()
|
|
|
352 |
|
353 |
|
354 |
+
"""
|
355 |
+
Graph with tools conditions
|
356 |
+
|
357 |
builder = StateGraph(MessagesState)
|
358 |
# Define nodes: these do the work
|
359 |
builder.add_node("assistant", assistant)
|
|
|
367 |
tools_condition,
|
368 |
)
|
369 |
builder.add_edge("tools", "assistant")
|
|
|
370 |
# Compile graph
|
371 |
+
return builder.compile()
|
372 |
+
"""
|