philincloud commited on
Commit
3603cca
·
verified ·
1 Parent(s): 666975c

Update langgraph_agent.py

Browse files
Files changed (1) hide show
  1. langgraph_agent.py +13 -13
langgraph_agent.py CHANGED
@@ -16,7 +16,8 @@ from langchain_core.messages import SystemMessage, HumanMessage
16
  from langchain_google_genai import ChatGoogleGenerativeAI
17
  from langchain_core.tools import tool
18
 
19
- from langchain_google_community.tools.Google Search import GoogleSearchResults
 
20
 
21
  @tool
22
  def multiply(a: int, b: int) -> int:
@@ -55,18 +56,17 @@ def wiki_search(query: str) -> dict:
55
  print(f"Error in wiki_search tool: {e}")
56
  return {"wiki_results": f"Error occurred while searching Wikipedia for '{query}'. Details: {str(e)}"}
57
 
58
- Google Search_tool = GoogleSearchResults(
59
- api_key=os.getenv("GOOGLE_API_KEY"),
60
- engine_id=os.getenv("GOOGLE_CSE_ID")
61
- )
62
  @tool
63
- def google_web_search(query: str) -> dict:
64
  try:
65
- docs = Google Search_tool.invoke(query)
66
- return {"google_web_results": docs}
67
  except Exception as e:
68
  print(f"Error in google_web_search tool: {e}")
69
- return {"google_web_results": f"Error occurred while searching the web for '{query}'. Details: {str(e)}"}
70
 
71
  @tool
72
  def arvix_search(query: str) -> dict:
@@ -191,10 +191,10 @@ def build_graph(provider: str = "gemini"):
191
  llm_with_tools = llm.bind_tools(tools)
192
 
193
  def assistant(state: MessagesState):
194
- messages_to_send = [sys_msg] + state["messages"] # This line was moved right
195
- llm_response = llm_with_tools.invoke(messages_to_send) # This line was moved right
196
- print(f"LLM Raw Response: {llm_response}") # This line was moved right
197
- return {"messages": [llm_response]} # This line was moved right
198
 
199
  builder = StateGraph(MessagesState)
200
  builder.add_node("assistant", assistant)
 
16
  from langchain_google_genai import ChatGoogleGenerativeAI
17
  from langchain_core.tools import tool
18
 
19
+ # Correct import for GoogleSearchAPIWrapper
20
+ from langchain_google_community import GoogleSearchAPIWrapper
21
 
22
  @tool
23
  def multiply(a: int, b: int) -> int:
 
56
  print(f"Error in wiki_search tool: {e}")
57
  return {"wiki_results": f"Error occurred while searching Wikipedia for '{query}'. Details: {str(e)}"}
58
 
59
+ # Instantiate GoogleSearchAPIWrapper
60
+ search = GoogleSearchAPIWrapper()
61
+
 
62
  @tool
63
+ def google_web_search(query: str) -> str:
64
  try:
65
+ # Use the run method of the GoogleSearchAPIWrapper instance
66
+ return search.run(query)
67
  except Exception as e:
68
  print(f"Error in google_web_search tool: {e}")
69
+ return f"Error occurred while searching the web for '{query}'. Details: {str(e)}"
70
 
71
  @tool
72
  def arvix_search(query: str) -> dict:
 
191
  llm_with_tools = llm.bind_tools(tools)
192
 
193
  def assistant(state: MessagesState):
194
+ messages_to_send = [sys_msg] + state["messages"]
195
+ llm_response = llm_with_tools.invoke(messages_to_send)
196
+ print(f"LLM Raw Response: {llm_response}")
197
+ return {"messages": [llm_response]}
198
 
199
  builder = StateGraph(MessagesState)
200
  builder.add_node("assistant", assistant)