Julia Ostheimer
commited on
Commit
·
a959e84
1
Parent(s):
f72320c
Rebuild Langgraph to new flow with always retrieving information from vector store
Browse files
app.py
CHANGED
|
@@ -5,10 +5,12 @@ from langchain.chat_models import init_chat_model
|
|
| 5 |
from langchain_core.tools import tool
|
| 6 |
from langchain_aws import BedrockEmbeddings
|
| 7 |
from langchain_qdrant import QdrantVectorStore
|
|
|
|
|
|
|
|
|
|
| 8 |
from langgraph.checkpoint.memory import MemorySaver
|
| 9 |
from langgraph.graph import MessagesState, StateGraph, END
|
| 10 |
from langgraph.prebuilt import ToolNode, tools_condition
|
| 11 |
-
from langgraph.prebuilt import ToolNode
|
| 12 |
|
| 13 |
import structlog
|
| 14 |
|
|
@@ -107,14 +109,17 @@ def trigger_ai_message_with_tool_call(state: MessagesState) -> AIMessage:
|
|
| 107 |
|
| 108 |
|
| 109 |
graph_builder = StateGraph(MessagesState)
|
| 110 |
-
tools = ToolNode([retrieve])
|
| 111 |
memory = MemorySaver()
|
| 112 |
|
| 113 |
-
|
| 114 |
-
graph_builder.add_node(generate)
|
| 115 |
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
graph_builder.
|
|
|
|
|
|
|
| 118 |
graph_builder.add_edge("generate", END)
|
| 119 |
|
| 120 |
graph = graph_builder.compile(checkpointer=memory)
|
|
|
|
| 5 |
from langchain_core.tools import tool
|
| 6 |
from langchain_aws import BedrockEmbeddings
|
| 7 |
from langchain_qdrant import QdrantVectorStore
|
| 8 |
+
from langchain.schema import AIMessage, HumanMessage
|
| 9 |
+
from langchain_core.messages.tool import ToolCall
|
| 10 |
+
|
| 11 |
from langgraph.checkpoint.memory import MemorySaver
|
| 12 |
from langgraph.graph import MessagesState, StateGraph, END
|
| 13 |
from langgraph.prebuilt import ToolNode, tools_condition
|
|
|
|
| 14 |
|
| 15 |
import structlog
|
| 16 |
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
graph_builder = StateGraph(MessagesState)
|
|
|
|
| 112 |
memory = MemorySaver()
|
| 113 |
|
| 114 |
+
tool_node = ToolNode([retrieve])
|
|
|
|
| 115 |
|
| 116 |
+
graph_builder.add_node(trigger_ai_message_with_tool_call)
|
| 117 |
+
graph_builder.add_node("tool_node", tool_node)
|
| 118 |
+
graph_builder.add_node(generate)
|
| 119 |
|
| 120 |
+
graph_builder.set_entry_point("trigger_ai_message_with_tool_call")
|
| 121 |
+
graph_builder.add_edge("trigger_ai_message_with_tool_call", "tool_node")
|
| 122 |
+
graph_builder.add_edge("tool_node", "generate")
|
| 123 |
graph_builder.add_edge("generate", END)
|
| 124 |
|
| 125 |
graph = graph_builder.compile(checkpointer=memory)
|