Spaces:
Sleeping
Sleeping
Update app.py
Browse filesfirst pass with websearch
2 unmodified lines3456781 unmodified line10111213141516171819202122232 unmodified linesimport requestsimport inspectimport pandas as pd# (Keep Constants as is)# --- Constants ---1 unmodified line# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent:def __init__(self):print("BasicAgent initialized.")def __call__(self, question: str) -> str:print(f"Agent received question (first 50 chars): {question[:50]}...")fixed_answer = "This is a default answer."print(f"Agent returning fixed answer: {fixed_answer}")return fixed_answerdef run_and_submit_all( profile: gr.OAuthProfile | None):"""2 unmodified lines345678910111213141516171 unmodified line1920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465662 unmodified linesimport requestsimport inspectimport pandas as pdfrom langchain_core.tools import toolfrom langchain_core.messages import add_messagefrom langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFacefrom langchain_community.tools import DuckDuckGoSearchRunfrom typing import TypedDict, Annotatedfrom langgraph.graph.message import add_messagefrom langgraph.graph import START, StateGraphfrom langgraph.prebuilt import tools_condition# (Keep Constants as is)# --- Constants ---1 unmodified line# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------llm = HuggingFaceEndpoint(repo_id = "Qwen/Qwen2.5-Coder-32B-Instruct",huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,)chat = ChatHuggingFace(llm=llm, verbose=True)search_tool = DuckDuckGoSearchRun()tools = [search_tool]chat_with_tools = chat.bind_tools(tools)class AgentState(TypedDict):messages:Annotated[list[AnyMessage], add_message]def assistant(state:AgentState):return {"messages": [chat_with_tools.invoke(state["messages"])]}# Graphbuilder = StateGraph(AgentState)# Graph Nodesbuilder.add_node("assistant", assistant)builder.add_node("tools", ToolNode(toools))#Graph Edgesbuilder.add_edge(START, "assistant")builder.add_conditional_edges("assistant",tools_condition)builder.add_edge("tools", "assistant")my_agent = builder.complie()class BasicAgent:def __init__(self):print("BasicAgent initialized.")def __call__(self, question: str) -> str:print(f"Agent received question (first 50 chars): {question[:50]}...")response = my_agent.invoke({"messages": messages})return responsedef run_and_submit_all( profile: gr.OAuthProfile | None):"""
app.py+46-3