SHAMIL SHAHBAZ AWAN commited on
Commit
e0b02e9
·
verified ·
1 Parent(s): a1b3907

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -17,7 +17,6 @@ from langchain_text_splitters import RecursiveCharacterTextSplitter
17
  from langchain.tools.retriever import create_retriever_tool
18
  from langchain_google_genai import ChatGoogleGenerativeAI, GoogleGenerativeAIEmbeddings
19
  from langgraph.graph import StateGraph, START, END
20
- from langgraph.graph.state import MessagesState
21
  from langgraph.prebuilt import ToolNode, tools_condition
22
  from langgraph.checkpoint.memory import MemorySaver
23
  from langgraph.graph import CompiledStateGraph
@@ -53,7 +52,6 @@ def space_events_agent():
53
  category = (event.get('categories', [{}])[0]).get('title', 'Unknown Category')
54
  geometries = event.get('geometries', [])
55
  coordinates = geometries[0].get('coordinates', 'Unknown Location') if geometries else 'Unknown Location'
56
- # Include additional detailed formatting for each event
57
  event_details.append(
58
  f"• **Event:** {event.get('title', 'N/A')}\n"
59
  f" **Type:** {category}\n"
@@ -238,12 +236,12 @@ sys_msg = SystemMessage(content='''This system is designed to provide real-time
238
  When responding to user queries, the assistant should provide comprehensive, detailed, and accurate explanations. Visual responses should include image URLs that the interface can use to display pictures. All responses should strive for clarity and depth in explanation.
239
  ''')
240
 
241
- # Define the assistant node function
242
- def assistant(state: MessagesState) -> MessagesState:
243
  return {"messages": [llm_with_tools.invoke([sys_msg] + state["messages"][-10:])]}
244
 
245
- # Build the LangGraph state graph
246
- builder: StateGraph = StateGraph(MessagesState)
247
  builder.add_node("assistant", assistant)
248
  builder.add_node("tools", ToolNode(tools))
249
  builder.add_edge(START, "assistant")
@@ -282,7 +280,7 @@ if user_input := st.chat_input("Ask about space news, ISS location, astronomy im
282
  # Check for image URL markers in a case-insensitive way
283
  image_url = None
284
  if "image url:" in assistant_response.lower():
285
- # Use regex to extract the first URL after "image url:"
286
  match = re.search(r"[Ii]mage [Uu][Rr][Ll]:\s*(\S+)", assistant_response)
287
  if match:
288
  image_url = match.group(1).strip()
 
17
  from langchain.tools.retriever import create_retriever_tool
18
  from langchain_google_genai import ChatGoogleGenerativeAI, GoogleGenerativeAIEmbeddings
19
  from langgraph.graph import StateGraph, START, END
 
20
  from langgraph.prebuilt import ToolNode, tools_condition
21
  from langgraph.checkpoint.memory import MemorySaver
22
  from langgraph.graph import CompiledStateGraph
 
52
  category = (event.get('categories', [{}])[0]).get('title', 'Unknown Category')
53
  geometries = event.get('geometries', [])
54
  coordinates = geometries[0].get('coordinates', 'Unknown Location') if geometries else 'Unknown Location'
 
55
  event_details.append(
56
  f"• **Event:** {event.get('title', 'N/A')}\n"
57
  f" **Type:** {category}\n"
 
236
  When responding to user queries, the assistant should provide comprehensive, detailed, and accurate explanations. Visual responses should include image URLs that the interface can use to display pictures. All responses should strive for clarity and depth in explanation.
237
  ''')
238
 
239
+ # Define the assistant node function; we use a plain dictionary as the state type
240
+ def assistant(state: dict) -> dict:
241
  return {"messages": [llm_with_tools.invoke([sys_msg] + state["messages"][-10:])]}
242
 
243
+ # Build the LangGraph state graph using dict as the state type
244
+ builder: StateGraph = StateGraph(dict)
245
  builder.add_node("assistant", assistant)
246
  builder.add_node("tools", ToolNode(tools))
247
  builder.add_edge(START, "assistant")
 
280
  # Check for image URL markers in a case-insensitive way
281
  image_url = None
282
  if "image url:" in assistant_response.lower():
283
+ # Use regex to extract the first URL after "Image URL:"
284
  match = re.search(r"[Ii]mage [Uu][Rr][Ll]:\s*(\S+)", assistant_response)
285
  if match:
286
  image_url = match.group(1).strip()