Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,14 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# ------------------------------
|
4 |
# Imports & Dependencies
|
@@ -8,7 +18,7 @@ from langchain_community.vectorstores import Chroma
|
|
8 |
from langchain_core.messages import HumanMessage, AIMessage, ToolMessage
|
9 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
10 |
from langgraph.graph import END, StateGraph
|
11 |
-
from langgraph.prebuilt import ToolNode
|
12 |
from langgraph.graph.message import add_messages
|
13 |
from typing_extensions import TypedDict, Annotated
|
14 |
from typing import Sequence
|
@@ -18,9 +28,6 @@ import streamlit as st
|
|
18 |
import requests
|
19 |
from langchain.tools.retriever import create_retriever_tool
|
20 |
|
21 |
-
# Define our own START constant
|
22 |
-
START = "START"
|
23 |
-
|
24 |
# ------------------------------
|
25 |
# Dummy Data: Research & Development Texts
|
26 |
# ------------------------------
|
@@ -259,18 +266,21 @@ def custom_tools_condition(state: AgentState):
|
|
259 |
return END
|
260 |
|
261 |
# ------------------------------
|
262 |
-
# Workflow Configuration using LangGraph
|
263 |
# ------------------------------
|
264 |
workflow = StateGraph(AgentState)
|
265 |
|
|
|
266 |
workflow.add_node("agent", agent)
|
267 |
retrieve_node = ToolNode(tools)
|
268 |
workflow.add_node("retrieve", retrieve_node)
|
269 |
workflow.add_node("rewrite", rewrite)
|
270 |
workflow.add_node("generate", generate)
|
271 |
|
272 |
-
|
|
|
273 |
|
|
|
274 |
workflow.add_conditional_edges(
|
275 |
"agent",
|
276 |
custom_tools_condition,
|
@@ -280,12 +290,24 @@ workflow.add_conditional_edges(
|
|
280 |
}
|
281 |
)
|
282 |
|
283 |
-
workflow.add_conditional_edges(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
workflow.add_edge("generate", END)
|
285 |
workflow.add_edge("rewrite", "agent")
|
286 |
|
|
|
287 |
app = workflow.compile()
|
288 |
|
|
|
|
|
|
|
289 |
def process_question(user_question, app, config):
|
290 |
"""Process user question through the workflow"""
|
291 |
events = []
|
|
|
1 |
+
# requirements.txt contents:
|
2 |
+
"""
|
3 |
+
langgraph>=0.0.25
|
4 |
+
langchain_openai>=0.0.4
|
5 |
+
langchain_community>=0.0.11
|
6 |
+
chromadb>=0.4.15
|
7 |
+
openai>=1.9.0
|
8 |
+
streamlit>=1.29.0
|
9 |
+
requests>=2.31.0
|
10 |
+
typing-extensions>=4.9.0
|
11 |
+
"""
|
12 |
|
13 |
# ------------------------------
|
14 |
# Imports & Dependencies
|
|
|
18 |
from langchain_core.messages import HumanMessage, AIMessage, ToolMessage
|
19 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
20 |
from langgraph.graph import END, StateGraph
|
21 |
+
from langgraph.prebuilt import ToolNode
|
22 |
from langgraph.graph.message import add_messages
|
23 |
from typing_extensions import TypedDict, Annotated
|
24 |
from typing import Sequence
|
|
|
28 |
import requests
|
29 |
from langchain.tools.retriever import create_retriever_tool
|
30 |
|
|
|
|
|
|
|
31 |
# ------------------------------
|
32 |
# Dummy Data: Research & Development Texts
|
33 |
# ------------------------------
|
|
|
266 |
return END
|
267 |
|
268 |
# ------------------------------
|
269 |
+
# Workflow Configuration using LangGraph (Corrected)
|
270 |
# ------------------------------
|
271 |
workflow = StateGraph(AgentState)
|
272 |
|
273 |
+
# Add nodes
|
274 |
workflow.add_node("agent", agent)
|
275 |
retrieve_node = ToolNode(tools)
|
276 |
workflow.add_node("retrieve", retrieve_node)
|
277 |
workflow.add_node("rewrite", rewrite)
|
278 |
workflow.add_node("generate", generate)
|
279 |
|
280 |
+
# Set entry point
|
281 |
+
workflow.set_entry_point("agent")
|
282 |
|
283 |
+
# Define transitions
|
284 |
workflow.add_conditional_edges(
|
285 |
"agent",
|
286 |
custom_tools_condition,
|
|
|
290 |
}
|
291 |
)
|
292 |
|
293 |
+
workflow.add_conditional_edges(
|
294 |
+
"retrieve",
|
295 |
+
simple_grade_documents,
|
296 |
+
{
|
297 |
+
"generate": "generate",
|
298 |
+
"rewrite": "rewrite"
|
299 |
+
}
|
300 |
+
)
|
301 |
+
|
302 |
workflow.add_edge("generate", END)
|
303 |
workflow.add_edge("rewrite", "agent")
|
304 |
|
305 |
+
# Compile the workflow
|
306 |
app = workflow.compile()
|
307 |
|
308 |
+
# ------------------------------
|
309 |
+
# Processing Function
|
310 |
+
# ------------------------------
|
311 |
def process_question(user_question, app, config):
|
312 |
"""Process user question through the workflow"""
|
313 |
events = []
|