Spaces:
Build error
Build error
agent 1st try
Browse filesFiles changed (3)
- app.py+5-1
- requirements.txt+119-2
- unit4agent.pyAdded+106
2 unmodified lines3456784 unmodified lines13141516171819202169 unmodified lines919293949596972 unmodified linesimport requestsimport inspectimport pandas as pd# (Keep Constants as is)# --- Constants ---4 unmodified linesclass 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_answer69 unmodified linesprint("Agent did not produce any answers to submit.")return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)# 4. Prepare Submissionsubmission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."print(status_update)2 unmodified lines34567894 unmodified lines14151617181920212223242569 unmodified lines95969798991001012 unmodified linesimport requestsimport inspectimport pandas as pdfrom unit4agent import compile_agent# (Keep Constants as is)# --- Constants ---4 unmodified linesclass BasicAgent:def __init__(self):print("BasicAgent initialized.")self.ai_unit = compile_agent()def __call__(self, question: str) -> str:print(f"Agent received question (first 50 chars): {question[:50]}...")fixed_answer = "This is a default answer."response = self.ai_unit.supervisor.invoke({"messages": [HumanMessage(question)]})fixed_answer = response['messages'][-1].contentprint(f"Agent returning fixed answer: {fixed_answer}")return fixed_answer69 unmodified linesprint("Agent did not produce any answers to submit.")return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)# 4. Prepare Submissionsubmission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."print(status_update)
12gradiorequests123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119aiofiles==24.1.0aiohappyeyeballs==2.6.1aiohttp==3.11.18aiosignal==1.3.2alabaster==0.7.16annotated-types==0.7.0anyio==4.9.0arxiv==2.2.0attrs==25.3.0babel==2.17.0beautifulsoup4==4.13.4certifi==2025.4.26charset-normalizer==3.4.2click==8.1.8dataclasses-json==0.6.7distro==1.9.0docutils==0.21.2fastapi==0.115.12feedparser==6.0.11ffmpy==0.5.0filelock==3.18.0frozenlist==1.6.0fsspec==2025.5.0gradio==5.30.0gradio_client==1.10.1groovy==0.1.2h11==0.16.0httpcore==1.0.9httpx==0.27.2httpx-sse==0.4.0huggingface-hub==0.31.4idna==3.10imagesize==1.4.1iniconfig==2.1.0Jinja2==3.1.6jiter==0.10.0jsonpatch==1.33jsonpointer==3.0.0langchain==0.3.25langchain-community==0.3.24langchain-core==0.3.60langchain-openai==0.3.17langchain-tavily==0.1.6langchain-text-splitters==0.3.8langgraph==0.4.5langgraph-checkpoint==2.0.26langgraph-prebuilt==0.1.8langgraph-sdk==0.1.70langsmith==0.3.42markdown-it-py==3.0.0MarkupSafe==3.0.2marshmallow==3.26.1mdurl==0.1.2mediawikiapi==1.3multidict==6.4.4mypy==1.15.0mypy_extensions==1.1.0numpy==2.2.6openai==1.81.0orjson==3.10.18ormsgpack==1.9.1packaging==24.2pandas==2.2.3pillow==11.2.1pluggy==1.6.0propcache==0.3.1pydantic==2.11.4pydantic-settings==2.9.1pydantic_core==2.33.2pydub==0.25.1Pygments==2.19.1pytest==8.3.5pytest-vcr==1.0.2python-dateutil==2.9.0.post0python-dotenv==1.1.0python-multipart==0.0.20pytz==2025.2PyYAML==6.0.2regex==2024.11.6requests==2.32.3requests-toolbelt==1.0.0rich==14.0.0ruff==0.11.10safehttpx==0.1.6semantic-version==2.10.0sgmllib3k==1.0.0shellingham==1.5.4six==1.17.0sniffio==1.3.1snowballstemmer==3.0.1soupsieve==2.7Sphinx==7.4.7sphinxcontrib-applehelp==2.0.0sphinxcontrib-devhelp==2.0.0sphinxcontrib-htmlhelp==2.1.0sphinxcontrib-jsmath==1.0.1sphinxcontrib-qthelp==2.0.0sphinxcontrib-serializinghtml==2.0.0SQLAlchemy==2.0.41starlette==0.46.2tenacity==9.1.2tiktoken==0.9.0tomlkit==0.13.2tqdm==4.67.1typer==0.15.4typing-inspect==0.9.0typing-inspection==0.4.1typing_extensions==4.13.2tzdata==2025.2urllib3==2.4.0uvicorn==0.34.2vcrpy==7.0.0websockets==15.0.1wikibase-rest-api-client==0.2.2wikipedia==1.4.0wrapt==1.17.2xxhash==3.5.0yarl==1.20.0zstandard==0.23.0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106from langchain_core.tools import toolfrom langchain_tavily import TavilySearchfrom langchain_community.utilities import ArxivAPIWrapperfrom langchain_community.tools import WikipediaQueryRunfrom langchain_community.utilities import WikipediaAPIWrapperfrom langchain_community.tools.wikidata.tool import WikidataAPIWrapper, WikidataQueryRunfrom typing import List, TypedDict, Annotated, Optionalfrom langchain_core.messages import AnyMessage, SystemMessage, HumanMessagefrom langchain.chat_models import init_chat_modelfrom langgraph.prebuilt import create_react_agentfrom langchain_openai import ChatOpenAI
# tools ///////////////////////////////////
# calculations@tooldef multiply(a: float, b: float) -> float: """Multiply a and """ return a * b
@tooldef divide(a: int, b: int) -> float: """Divide a and b""" return a / b
@tooldef add(a: int, b: int) -> int: """Add a and b""" return a + b
@tooldef subtract(a: int, b: int) -> int: """Subtract b from a""" return a - b
@tooldef square_root(a: int) -> float: """Square root of a""" return a ** 0.5
# web search, TavilyTAVILY_API_KEY = os.getenv("TAVILY_API_KEY")
web_search_tool = TavilySearch( max_results=5, topic="general", # include_answer=False, # include_raw_content=False, # include_images=False, # include_image_descriptions=False, # search_depth="basic", # time_range="day", # include_domains=None, # exclude_domains=None)
# wikidata searchwikidata = WikidataQueryRun(api_wrapper=WikidataAPIWrapper())
@tooldef wikidata_search(query: str) -> str: """Search the wikidata for information""" return wikidata.run(query)
# wiki searchwikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
@tooldef wikipedia_search(query: str) -> str: """Search the wikipedia for information""" return wikipedia.run(query)
# arxiv searcharxiv = ArxivAPIWrapper()
@tooldef arxiv_search(query: str) -> str: """Search the arxiv for information""" return arxiv.run(query)
def compile_agent():
tools = [multiply, divide, add, subtract, square_root, web_search_tool, arxiv_search, wikidata_search, wikipedia_search]
# HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
# read system prompt from file with open("system_prompt.txt", "r") as file: system_prompt = file.read()
# llm = HuggingFaceEndpoint( # repo_id="Qwen/Qwen2.5-Coder-32B-Instruct", # huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN # )
llm = ChatOpenAI(model="gpt-4.1")
ai_agent = create_react_agent( model=llm, tools=tools, prompt=system_prompt )
return ai_agent
app.py+5-1
requirements.txt+119-2
unit4agent.pyAdded+106