Spaces:
Build error
Build error
Update langgraph_agent.py
Browse files15 unmodified lines1617181920212232 unmodified lines555657585960616263646566676869707172118 unmodified lines19119219319419519619719819920015 unmodified linesfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_core.tools import toolfrom langchain_google_community.tools.Google Search import GoogleSearchResults@tooldef multiply(a: int, b: int) -> int:32 unmodified linesprint(f"Error in wiki_search tool: {e}")return {"wiki_results": f"Error occurred while searching Wikipedia for '{query}'. Details: {str(e)}"}Google Search_tool = GoogleSearchResults(api_key=os.getenv("GOOGLE_API_KEY"),engine_id=os.getenv("GOOGLE_CSE_ID"))@tooldef google_web_search(query: str) -> dict:try:docs = Google Search_tool.invoke(query)return {"google_web_results": docs}except Exception as e:print(f"Error in google_web_search tool: {e}")return {"google_web_results": f"Error occurred while searching the web for '{query}'. Details: {str(e)}"}@tooldef arvix_search(query: str) -> dict:118 unmodified linesllm_with_tools = llm.bind_tools(tools)def assistant(state: MessagesState):messages_to_send = [sys_msg] + state["messages"] # This line was moved rightllm_response = llm_with_tools.invoke(messages_to_send) # This line was moved rightprint(f"LLM Raw Response: {llm_response}") # This line was moved rightreturn {"messages": [llm_response]} # This line was moved rightbuilder = StateGraph(MessagesState)builder.add_node("assistant", assistant)15 unmodified lines161718192021222332 unmodified lines5657585960616263646566676869707172118 unmodified lines19119219319419519619719819920015 unmodified linesfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_core.tools import tool# Correct import for GoogleSearchAPIWrapperfrom langchain_google_community import GoogleSearchAPIWrapper@tooldef multiply(a: int, b: int) -> int:32 unmodified linesprint(f"Error in wiki_search tool: {e}")return {"wiki_results": f"Error occurred while searching Wikipedia for '{query}'. Details: {str(e)}"}# Instantiate GoogleSearchAPIWrappersearch = GoogleSearchAPIWrapper()@tooldef google_web_search(query: str) -> str:try:# Use the run method of the GoogleSearchAPIWrapper instancereturn search.run(query)except Exception as e:print(f"Error in google_web_search tool: {e}")return f"Error occurred while searching the web for '{query}'. Details: {str(e)}"@tooldef arvix_search(query: str) -> dict:118 unmodified linesllm_with_tools = llm.bind_tools(tools)def assistant(state: MessagesState):messages_to_send = [sys_msg] + state["messages"]llm_response = llm_with_tools.invoke(messages_to_send)print(f"LLM Raw Response: {llm_response}")return {"messages": [llm_response]}builder = StateGraph(MessagesState)builder.add_node("assistant", assistant)
langgraph_agent.py+13-13