Upload 11 files
Browse files- .gitattributes +35 -0
- .github/workflows/sync-to-huggingface-space.yml +23 -0
- .gitignore +175 -0
- README.md +39 -0
- agent.py +184 -0
- agent_tools.py +242 -0
- app.py +202 -0
- exploration.ipynb +190 -0
- metadata.jsonl +0 -0
- requirements.txt +20 -0
- system_prompt.txt +8 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.github/workflows/sync-to-huggingface-space.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: sync to Huggingface space
|
| 3 |
+
|
| 4 |
+
on:
|
| 5 |
+
push:
|
| 6 |
+
branches:
|
| 7 |
+
- main
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
sync-to-hub:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v3
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
lfs: true
|
| 17 |
+
- name: Push to Space
|
| 18 |
+
run: |
|
| 19 |
+
git push -f https://maldu:${{ secrets.HF_AGENTS_PROJECT }}@huggingface.co/spaces/maldu/AGENTS_FINAL_PROJECT main
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
.gitignore
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# UV
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
#uv.lock
|
| 102 |
+
|
| 103 |
+
# poetry
|
| 104 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 105 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 106 |
+
# commonly ignored for libraries.
|
| 107 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 108 |
+
#poetry.lock
|
| 109 |
+
|
| 110 |
+
# pdm
|
| 111 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 112 |
+
#pdm.lock
|
| 113 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 114 |
+
# in version control.
|
| 115 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
| 116 |
+
.pdm.toml
|
| 117 |
+
.pdm-python
|
| 118 |
+
.pdm-build/
|
| 119 |
+
|
| 120 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 121 |
+
__pypackages__/
|
| 122 |
+
|
| 123 |
+
# Celery stuff
|
| 124 |
+
celerybeat-schedule
|
| 125 |
+
celerybeat.pid
|
| 126 |
+
|
| 127 |
+
# SageMath parsed files
|
| 128 |
+
*.sage.py
|
| 129 |
+
|
| 130 |
+
# Environments
|
| 131 |
+
.env
|
| 132 |
+
.venv
|
| 133 |
+
env/
|
| 134 |
+
venv/
|
| 135 |
+
ENV/
|
| 136 |
+
env.bak/
|
| 137 |
+
venv.bak/
|
| 138 |
+
agentsvenv/
|
| 139 |
+
|
| 140 |
+
# Spyder project settings
|
| 141 |
+
.spyderproject
|
| 142 |
+
.spyproject
|
| 143 |
+
|
| 144 |
+
# Rope project settings
|
| 145 |
+
.ropeproject
|
| 146 |
+
|
| 147 |
+
# mkdocs documentation
|
| 148 |
+
/site
|
| 149 |
+
|
| 150 |
+
# mypy
|
| 151 |
+
.mypy_cache/
|
| 152 |
+
.dmypy.json
|
| 153 |
+
dmypy.json
|
| 154 |
+
|
| 155 |
+
# Pyre type checker
|
| 156 |
+
.pyre/
|
| 157 |
+
|
| 158 |
+
# pytype static type analyzer
|
| 159 |
+
.pytype/
|
| 160 |
+
|
| 161 |
+
# Cython debug symbols
|
| 162 |
+
cython_debug/
|
| 163 |
+
|
| 164 |
+
# PyCharm
|
| 165 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 166 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 167 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 168 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 169 |
+
#.idea/
|
| 170 |
+
|
| 171 |
+
# Ruff stuff:
|
| 172 |
+
.ruff_cache/
|
| 173 |
+
|
| 174 |
+
# PyPI configuration file
|
| 175 |
+
.pypirc
|
README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Template Final Assignment
|
| 3 |
+
emoji: 🕵🏻♂️
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.25.2
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
hf_oauth: true
|
| 11 |
+
# optional, default duration is 8 hours/480 minutes. Max duration is 30 days/43200 minutes.
|
| 12 |
+
hf_oauth_expiration_minutes: 480
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
## 🛠️ Setup instructions
|
| 19 |
+
|
| 20 |
+
Follow these steps to set up your Python environment:
|
| 21 |
+
|
| 22 |
+
### 1. Create virtual environment
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
python3.10 -m venv agentsvenv
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
### 2. Activate virtual environment
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
source agentsvenv/bin/activate
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### 3. Install dependencies
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
pip install -r requirements.txt
|
| 39 |
+
```
|
agent.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from typing import List, Dict, Any, Optional
|
| 5 |
+
import tempfile
|
| 6 |
+
import re
|
| 7 |
+
import json
|
| 8 |
+
import requests
|
| 9 |
+
from urllib.parse import urlparse
|
| 10 |
+
from PIL import Image, ImageDraw, ImageFont, ImageEnhance, ImageFilter
|
| 11 |
+
import cmath
|
| 12 |
+
import pandas as pd
|
| 13 |
+
import uuid
|
| 14 |
+
import numpy as np
|
| 15 |
+
from datetime import datetime
|
| 16 |
+
import pytz
|
| 17 |
+
import pytesseract
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
"""Langraph"""
|
| 21 |
+
from langgraph.graph import START, StateGraph, MessagesState
|
| 22 |
+
|
| 23 |
+
from langgraph.prebuilt import ToolNode, tools_condition
|
| 24 |
+
|
| 25 |
+
from langchain_huggingface import (
|
| 26 |
+
ChatHuggingFace,
|
| 27 |
+
HuggingFaceEndpoint,
|
| 28 |
+
HuggingFaceEmbeddings,
|
| 29 |
+
)
|
| 30 |
+
from langchain_community.vectorstores import SupabaseVectorStore
|
| 31 |
+
from langchain_core.messages import SystemMessage, HumanMessage
|
| 32 |
+
from langchain.tools import tool
|
| 33 |
+
|
| 34 |
+
from langchain.tools.retriever import create_retriever_tool
|
| 35 |
+
from supabase.client import Client, create_client
|
| 36 |
+
|
| 37 |
+
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 38 |
+
from langchain_community.document_loaders import WikipediaLoader, ArxivLoader
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
load_dotenv()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
### =============== INFORMATION RETRIEVAL TOOLS =============== ###
|
| 45 |
+
|
| 46 |
+
@tool
|
| 47 |
+
def web_search(query: str) -> str:
|
| 48 |
+
"""Search Tavily for a query and return a maximum of 3 results.
|
| 49 |
+
Args:
|
| 50 |
+
query: The search query."""
|
| 51 |
+
search_docs = TavilySearchResults(
|
| 52 |
+
max_results=3,
|
| 53 |
+
include_raw_content=True,
|
| 54 |
+
include_images=True,
|
| 55 |
+
exclude_domains = ["wikipedia.org"]
|
| 56 |
+
).invoke(query=query)
|
| 57 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
| 58 |
+
[
|
| 59 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 60 |
+
for doc in search_docs
|
| 61 |
+
]
|
| 62 |
+
)
|
| 63 |
+
return {"web_results": formatted_search_docs}
|
| 64 |
+
|
| 65 |
+
@tool
|
| 66 |
+
def arxiv_search(query: str) -> str:
|
| 67 |
+
"""Search Arxiv for a query and return a maximum of 3 results.
|
| 68 |
+
Args:
|
| 69 |
+
query: The search query."""
|
| 70 |
+
search_docs = ArxivLoader(query=query, load_max_docs=3).load()
|
| 71 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
| 72 |
+
[
|
| 73 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
|
| 74 |
+
for doc in search_docs
|
| 75 |
+
]
|
| 76 |
+
)
|
| 77 |
+
return {"arxiv_results": formatted_search_docs}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@tool
|
| 82 |
+
def wiki_search(query: str) -> str:
|
| 83 |
+
"""Search Wikipedia for a query and return a maximum of 3 results.
|
| 84 |
+
Args:
|
| 85 |
+
query: The search query."""
|
| 86 |
+
search_docs = WikipediaLoader(query=query, load_max_docs=3, lang = "en").load()
|
| 87 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
| 88 |
+
[
|
| 89 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
| 90 |
+
for doc in search_docs
|
| 91 |
+
]
|
| 92 |
+
)
|
| 93 |
+
return {"wiki_results": formatted_search_docs}
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# load the system prompt from the file
|
| 99 |
+
with open("system_prompt.txt", "r", encoding="utf-8") as f:
|
| 100 |
+
system_prompt = f.read()
|
| 101 |
+
print(system_prompt)
|
| 102 |
+
|
| 103 |
+
# System message
|
| 104 |
+
sys_msg = SystemMessage(content=system_prompt)
|
| 105 |
+
|
| 106 |
+
# build a retriever
|
| 107 |
+
embeddings = HuggingFaceEmbeddings(
|
| 108 |
+
model_name="sentence-transformers/all-mpnet-base-v2"
|
| 109 |
+
) # dim=768
|
| 110 |
+
supabase: Client = create_client(
|
| 111 |
+
os.environ.get("SUPABASE_URL"), os.environ.get("SUPABASE_KEY")
|
| 112 |
+
)
|
| 113 |
+
vector_store = SupabaseVectorStore(
|
| 114 |
+
client=supabase,
|
| 115 |
+
embedding=embeddings,
|
| 116 |
+
table_name="documents",
|
| 117 |
+
query_name="match_documents",
|
| 118 |
+
)
|
| 119 |
+
create_retriever_tool = create_retriever_tool(
|
| 120 |
+
retriever=vector_store.as_retriever(),
|
| 121 |
+
name="Question Search",
|
| 122 |
+
description="A tool to retrieve similar questions from a vector store.",
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
tools = [
|
| 127 |
+
web_search,
|
| 128 |
+
arxiv_search,
|
| 129 |
+
wiki_search,
|
| 130 |
+
]
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
# Build graph function
|
| 134 |
+
def build_graph():
|
| 135 |
+
llm = ChatHuggingFace(
|
| 136 |
+
llm=HuggingFaceEndpoint(
|
| 137 |
+
repo_id="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
|
| 138 |
+
task="text-generation",
|
| 139 |
+
max_new_tokens=1024,
|
| 140 |
+
do_sample=False,
|
| 141 |
+
repetition_penalty=1.03,
|
| 142 |
+
temperature=0,
|
| 143 |
+
),
|
| 144 |
+
verbose=True,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
# Bind tools to LLM
|
| 148 |
+
llm_with_tools = llm.bind_tools(tools)
|
| 149 |
+
|
| 150 |
+
# Node
|
| 151 |
+
def assistant(state: MessagesState):
|
| 152 |
+
"""Assistant node"""
|
| 153 |
+
return {"messages": [llm_with_tools.invoke(state["messages"])]}
|
| 154 |
+
|
| 155 |
+
def retriever(state: MessagesState):
|
| 156 |
+
"""Retriever node"""
|
| 157 |
+
similar_question = vector_store.similarity_search(state["messages"][0].content)
|
| 158 |
+
|
| 159 |
+
if similar_question: # Check if the list is not empty
|
| 160 |
+
example_msg = HumanMessage(
|
| 161 |
+
content=f"Here I provide a similar question and answer for reference: \n\n{similar_question[0].page_content}",
|
| 162 |
+
)
|
| 163 |
+
return {"messages": [sys_msg] + state["messages"] + [example_msg]}
|
| 164 |
+
else:
|
| 165 |
+
# Handle the case when no similar questions are found
|
| 166 |
+
return {"messages": [sys_msg] + state["messages"]}
|
| 167 |
+
|
| 168 |
+
builder = StateGraph(MessagesState)
|
| 169 |
+
builder.add_node("retriever", retriever)
|
| 170 |
+
builder.add_node("assistant", assistant)
|
| 171 |
+
builder.add_node("tools", ToolNode(tools))
|
| 172 |
+
builder.add_edge(START, "retriever")
|
| 173 |
+
builder.add_edge("retriever", "assistant")
|
| 174 |
+
builder.add_conditional_edges(
|
| 175 |
+
"assistant",
|
| 176 |
+
tools_condition,
|
| 177 |
+
)
|
| 178 |
+
builder.add_edge("tools", "assistant")
|
| 179 |
+
|
| 180 |
+
# Compile graph
|
| 181 |
+
return builder.compile()
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
agent_tools.py
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import datetime
|
| 3 |
+
import pytz
|
| 4 |
+
import cmath
|
| 5 |
+
|
| 6 |
+
from typing import Optional
|
| 7 |
+
import os
|
| 8 |
+
import tempfile
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
### =============== TIMEZONE TOOLS =============== ###
|
| 13 |
+
|
| 14 |
+
@tool
|
| 15 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 16 |
+
"""Fetches the current local time in a specified timezone.
|
| 17 |
+
Args:
|
| 18 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 19 |
+
"""
|
| 20 |
+
try:
|
| 21 |
+
tz = pytz.timezone(timezone)
|
| 22 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 23 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
### =============== MATHEMATICAL TOOLS =============== ###
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
@tool
|
| 33 |
+
def multiply(a: float, b: float) -> float:
|
| 34 |
+
"""
|
| 35 |
+
Multiplies two numbers.
|
| 36 |
+
Args:
|
| 37 |
+
a (float): the first number
|
| 38 |
+
b (float): the second number
|
| 39 |
+
"""
|
| 40 |
+
return a * b
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@tool
|
| 44 |
+
def add(a: float, b: float) -> float:
|
| 45 |
+
"""
|
| 46 |
+
Adds two numbers.
|
| 47 |
+
Args:
|
| 48 |
+
a (float): the first number
|
| 49 |
+
b (float): the second number
|
| 50 |
+
"""
|
| 51 |
+
return a + b
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@tool
|
| 55 |
+
def subtract(a: float, b: float) -> int:
|
| 56 |
+
"""
|
| 57 |
+
Subtracts two numbers.
|
| 58 |
+
Args:
|
| 59 |
+
a (float): the first number
|
| 60 |
+
b (float): the second number
|
| 61 |
+
"""
|
| 62 |
+
return a - b
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
@tool
|
| 66 |
+
def divide(a: float, b: float) -> float:
|
| 67 |
+
"""
|
| 68 |
+
Divides two numbers.
|
| 69 |
+
Args:
|
| 70 |
+
a (float): the first float number
|
| 71 |
+
b (float): the second float number
|
| 72 |
+
"""
|
| 73 |
+
if b == 0:
|
| 74 |
+
raise ValueError("Cannot divided by zero.")
|
| 75 |
+
return a / b
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
@tool
|
| 79 |
+
def modulus(a: int, b: int) -> int:
|
| 80 |
+
"""
|
| 81 |
+
Get the modulus of two numbers.
|
| 82 |
+
Args:
|
| 83 |
+
a (int): the first number
|
| 84 |
+
b (int): the second number
|
| 85 |
+
"""
|
| 86 |
+
return a % b
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
@tool
|
| 90 |
+
def power(a: float, b: float) -> float:
|
| 91 |
+
"""
|
| 92 |
+
Get the power of two numbers.
|
| 93 |
+
Args:
|
| 94 |
+
a (float): the first number
|
| 95 |
+
b (float): the second number
|
| 96 |
+
"""
|
| 97 |
+
return a**b
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
@tool
|
| 101 |
+
def square_root(a: float) -> float | complex:
|
| 102 |
+
"""
|
| 103 |
+
Get the square root of a number.
|
| 104 |
+
Args:
|
| 105 |
+
a (float): the number to get the square root of
|
| 106 |
+
"""
|
| 107 |
+
if a >= 0:
|
| 108 |
+
return a**0.5
|
| 109 |
+
return cmath.sqrt(a)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
### =============== DOCUMENT PROCESSING TOOLS =============== ###
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
@tool
|
| 116 |
+
def save_and_read_file(content: str, filename: Optional[str] = None) -> str:
|
| 117 |
+
"""
|
| 118 |
+
Save content to a file and return the path.
|
| 119 |
+
Args:
|
| 120 |
+
content (str): the content to save to the file
|
| 121 |
+
filename (str, optional): the name of the file. If not provided, a random name file will be created.
|
| 122 |
+
"""
|
| 123 |
+
temp_dir = tempfile.gettempdir()
|
| 124 |
+
if filename is None:
|
| 125 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, dir=temp_dir)
|
| 126 |
+
filepath = temp_file.name
|
| 127 |
+
else:
|
| 128 |
+
filepath = os.path.join(temp_dir, filename)
|
| 129 |
+
|
| 130 |
+
with open(filepath, "w") as f:
|
| 131 |
+
f.write(content)
|
| 132 |
+
|
| 133 |
+
return f"File saved to {filepath}. You can read this file to process its contents."
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
@tool
|
| 137 |
+
def download_file_from_url(url: str, filename: Optional[str] = None) -> str:
|
| 138 |
+
"""
|
| 139 |
+
Download a file from a URL and save it to a temporary location.
|
| 140 |
+
Args:
|
| 141 |
+
url (str): the URL of the file to download.
|
| 142 |
+
filename (str, optional): the name of the file. If not provided, a random name file will be created.
|
| 143 |
+
"""
|
| 144 |
+
try:
|
| 145 |
+
# Parse URL to get filename if not provided
|
| 146 |
+
if not filename:
|
| 147 |
+
path = urlparse(url).path
|
| 148 |
+
filename = os.path.basename(path)
|
| 149 |
+
if not filename:
|
| 150 |
+
filename = f"downloaded_{uuid.uuid4().hex[:8]}"
|
| 151 |
+
|
| 152 |
+
# Create temporary file
|
| 153 |
+
temp_dir = tempfile.gettempdir()
|
| 154 |
+
filepath = os.path.join(temp_dir, filename)
|
| 155 |
+
|
| 156 |
+
# Download the file
|
| 157 |
+
response = requests.get(url, stream=True)
|
| 158 |
+
response.raise_for_status()
|
| 159 |
+
|
| 160 |
+
# Save the file
|
| 161 |
+
with open(filepath, "wb") as f:
|
| 162 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 163 |
+
f.write(chunk)
|
| 164 |
+
|
| 165 |
+
return f"File downloaded to {filepath}. You can read this file to process its contents."
|
| 166 |
+
except Exception as e:
|
| 167 |
+
return f"Error downloading file: {str(e)}"
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
@tool
|
| 171 |
+
def extract_text_from_image(image_path: str) -> str:
|
| 172 |
+
"""
|
| 173 |
+
Extract text from an image using OCR library pytesseract (if available).
|
| 174 |
+
Args:
|
| 175 |
+
image_path (str): the path to the image file.
|
| 176 |
+
"""
|
| 177 |
+
try:
|
| 178 |
+
# Open the image
|
| 179 |
+
image = Image.open(image_path)
|
| 180 |
+
|
| 181 |
+
# Extract text from the image
|
| 182 |
+
text = pytesseract.image_to_string(image)
|
| 183 |
+
|
| 184 |
+
return f"Extracted text from image:\n\n{text}"
|
| 185 |
+
except Exception as e:
|
| 186 |
+
return f"Error extracting text from image: {str(e)}"
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
@tool
|
| 190 |
+
def analyze_csv_file(file_path: str, query: str) -> str:
|
| 191 |
+
"""
|
| 192 |
+
Analyze a CSV file using pandas and answer a question about it.
|
| 193 |
+
Args:
|
| 194 |
+
file_path (str): the path to the CSV file.
|
| 195 |
+
query (str): Question about the data
|
| 196 |
+
"""
|
| 197 |
+
try:
|
| 198 |
+
# Read the CSV file
|
| 199 |
+
df = pd.read_csv(file_path)
|
| 200 |
+
|
| 201 |
+
# Run various analyses based on the query
|
| 202 |
+
result = f"CSV file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
|
| 203 |
+
result += f"Columns: {', '.join(df.columns)}\n\n"
|
| 204 |
+
|
| 205 |
+
# Add summary statistics
|
| 206 |
+
result += "Summary statistics:\n"
|
| 207 |
+
result += str(df.describe())
|
| 208 |
+
|
| 209 |
+
return result
|
| 210 |
+
|
| 211 |
+
except Exception as e:
|
| 212 |
+
return f"Error analyzing CSV file: {str(e)}"
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
@tool
|
| 216 |
+
def analyze_excel_file(file_path: str, query: str) -> str:
|
| 217 |
+
"""
|
| 218 |
+
Analyze an Excel file using pandas and answer a question about it.
|
| 219 |
+
Args:
|
| 220 |
+
file_path (str): the path to the Excel file.
|
| 221 |
+
query (str): Question about the data
|
| 222 |
+
"""
|
| 223 |
+
try:
|
| 224 |
+
# Read the Excel file
|
| 225 |
+
df = pd.read_excel(file_path)
|
| 226 |
+
|
| 227 |
+
# Run various analyses based on the query
|
| 228 |
+
result = (
|
| 229 |
+
f"Excel file loaded with {len(df)} rows and {len(df.columns)} columns.\n"
|
| 230 |
+
)
|
| 231 |
+
result += f"Columns: {', '.join(df.columns)}\n\n"
|
| 232 |
+
|
| 233 |
+
# Add summary statistics
|
| 234 |
+
result += "Summary statistics:\n"
|
| 235 |
+
result += str(df.describe())
|
| 236 |
+
|
| 237 |
+
return result
|
| 238 |
+
|
| 239 |
+
except Exception as e:
|
| 240 |
+
return f"Error analyzing Excel file: {str(e)}"
|
| 241 |
+
|
| 242 |
+
|
app.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
import inspect
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import time
|
| 7 |
+
from langchain_core.messages import HumanMessage
|
| 8 |
+
from agent import build_graph
|
| 9 |
+
|
| 10 |
+
# (Keep Constants as is)
|
| 11 |
+
# --- Constants ---
|
| 12 |
+
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
+
|
| 14 |
+
# --- Basic Agent Definition ---
|
| 15 |
+
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
+
class BasicAgent:
|
| 17 |
+
def __init__(self):
|
| 18 |
+
print("BasicAgent initialized.")
|
| 19 |
+
self.graph = build_graph()
|
| 20 |
+
|
| 21 |
+
def __call__(self, question: str) -> str:
|
| 22 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 23 |
+
messages = [HumanMessage(content=question)]
|
| 24 |
+
messages = self.graph.invoke({"messages": messages})
|
| 25 |
+
answer = messages['messages'][-1].content
|
| 26 |
+
return answer
|
| 27 |
+
|
| 28 |
+
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 29 |
+
"""
|
| 30 |
+
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 31 |
+
and displays the results.
|
| 32 |
+
"""
|
| 33 |
+
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 34 |
+
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 35 |
+
|
| 36 |
+
if profile:
|
| 37 |
+
username= f"{profile.username}"
|
| 38 |
+
print(f"User logged in: {username}")
|
| 39 |
+
else:
|
| 40 |
+
print("User not logged in.")
|
| 41 |
+
return "Please Login to Hugging Face with the button.", None
|
| 42 |
+
|
| 43 |
+
api_url = DEFAULT_API_URL
|
| 44 |
+
questions_url = f"{api_url}/questions"
|
| 45 |
+
submit_url = f"{api_url}/submit"
|
| 46 |
+
|
| 47 |
+
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 48 |
+
try:
|
| 49 |
+
agent = BasicAgent()
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print(f"Error instantiating agent: {e}")
|
| 52 |
+
return f"Error initializing agent: {e}", None
|
| 53 |
+
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 54 |
+
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 55 |
+
print(agent_code)
|
| 56 |
+
|
| 57 |
+
# 2. Fetch Questions
|
| 58 |
+
print(f"Fetching questions from: {questions_url}")
|
| 59 |
+
try:
|
| 60 |
+
response = requests.get(questions_url, timeout=15)
|
| 61 |
+
response.raise_for_status()
|
| 62 |
+
questions_data = response.json()
|
| 63 |
+
if not questions_data:
|
| 64 |
+
print("Fetched questions list is empty.")
|
| 65 |
+
return "Fetched questions list is empty or invalid format.", None
|
| 66 |
+
print(f"Fetched {len(questions_data)} questions.")
|
| 67 |
+
except requests.exceptions.RequestException as e:
|
| 68 |
+
print(f"Error fetching questions: {e}")
|
| 69 |
+
return f"Error fetching questions: {e}", None
|
| 70 |
+
except requests.exceptions.JSONDecodeError as e:
|
| 71 |
+
print(f"Error decoding JSON response from questions endpoint: {e}")
|
| 72 |
+
print(f"Response text: {response.text[:500]}")
|
| 73 |
+
return f"Error decoding server response for questions: {e}", None
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f"An unexpected error occurred fetching questions: {e}")
|
| 76 |
+
return f"An unexpected error occurred fetching questions: {e}", None
|
| 77 |
+
|
| 78 |
+
# 3. Run your Agent
|
| 79 |
+
results_log = []
|
| 80 |
+
answers_payload = []
|
| 81 |
+
print(f"Running agent on {len(questions_data)} questions...")
|
| 82 |
+
for item in questions_data:
|
| 83 |
+
task_id = item.get("task_id")
|
| 84 |
+
question_text = item.get("question")
|
| 85 |
+
if not task_id or question_text is None:
|
| 86 |
+
print(f"Skipping item with missing task_id or question: {item}")
|
| 87 |
+
continue
|
| 88 |
+
try:
|
| 89 |
+
submitted_answer = agent(question_text)
|
| 90 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 91 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 92 |
+
except Exception as e:
|
| 93 |
+
print(f"Error running agent on task {task_id}: {e}")
|
| 94 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 95 |
+
|
| 96 |
+
if not answers_payload:
|
| 97 |
+
print("Agent did not produce any answers to submit.")
|
| 98 |
+
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 99 |
+
|
| 100 |
+
# 4. Prepare Submission
|
| 101 |
+
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 102 |
+
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 103 |
+
print(status_update)
|
| 104 |
+
|
| 105 |
+
# 5. Submit
|
| 106 |
+
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
| 107 |
+
try:
|
| 108 |
+
response = requests.post(submit_url, json=submission_data, timeout=60)
|
| 109 |
+
response.raise_for_status()
|
| 110 |
+
result_data = response.json()
|
| 111 |
+
final_status = (
|
| 112 |
+
f"Submission Successful!\n"
|
| 113 |
+
f"User: {result_data.get('username')}\n"
|
| 114 |
+
f"Overall Score: {result_data.get('score', 'N/A')}% "
|
| 115 |
+
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
| 116 |
+
f"Message: {result_data.get('message', 'No message received.')}"
|
| 117 |
+
)
|
| 118 |
+
print("Submission successful.")
|
| 119 |
+
results_df = pd.DataFrame(results_log)
|
| 120 |
+
return final_status, results_df
|
| 121 |
+
except requests.exceptions.HTTPError as e:
|
| 122 |
+
error_detail = f"Server responded with status {e.response.status_code}."
|
| 123 |
+
try:
|
| 124 |
+
error_json = e.response.json()
|
| 125 |
+
error_detail += f" Detail: {error_json.get('detail', e.response.text)}"
|
| 126 |
+
except requests.exceptions.JSONDecodeError:
|
| 127 |
+
error_detail += f" Response: {e.response.text[:500]}"
|
| 128 |
+
status_message = f"Submission Failed: {error_detail}"
|
| 129 |
+
print(status_message)
|
| 130 |
+
results_df = pd.DataFrame(results_log)
|
| 131 |
+
return status_message, results_df
|
| 132 |
+
except requests.exceptions.Timeout:
|
| 133 |
+
status_message = "Submission Failed: The request timed out."
|
| 134 |
+
print(status_message)
|
| 135 |
+
results_df = pd.DataFrame(results_log)
|
| 136 |
+
return status_message, results_df
|
| 137 |
+
except requests.exceptions.RequestException as e:
|
| 138 |
+
status_message = f"Submission Failed: Network error - {e}"
|
| 139 |
+
print(status_message)
|
| 140 |
+
results_df = pd.DataFrame(results_log)
|
| 141 |
+
return status_message, results_df
|
| 142 |
+
except Exception as e:
|
| 143 |
+
status_message = f"An unexpected error occurred during submission: {e}"
|
| 144 |
+
print(status_message)
|
| 145 |
+
results_df = pd.DataFrame(results_log)
|
| 146 |
+
return status_message, results_df
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# --- Build Gradio Interface using Blocks ---
|
| 150 |
+
with gr.Blocks() as demo:
|
| 151 |
+
gr.Markdown("# Basic Agent Evaluation Runner")
|
| 152 |
+
gr.Markdown(
|
| 153 |
+
"""
|
| 154 |
+
**Instructions:**
|
| 155 |
+
|
| 156 |
+
1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
|
| 157 |
+
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
| 158 |
+
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
| 159 |
+
|
| 160 |
+
---
|
| 161 |
+
**Disclaimers:**
|
| 162 |
+
Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
|
| 163 |
+
This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
|
| 164 |
+
"""
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
gr.LoginButton()
|
| 168 |
+
|
| 169 |
+
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 170 |
+
|
| 171 |
+
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
| 172 |
+
# Removed max_rows=10 from DataFrame constructor
|
| 173 |
+
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 174 |
+
|
| 175 |
+
run_button.click(
|
| 176 |
+
fn=run_and_submit_all,
|
| 177 |
+
outputs=[status_output, results_table]
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
if __name__ == "__main__":
|
| 181 |
+
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
| 182 |
+
# Check for SPACE_HOST and SPACE_ID at startup for information
|
| 183 |
+
space_host_startup = os.getenv("SPACE_HOST")
|
| 184 |
+
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
| 185 |
+
|
| 186 |
+
if space_host_startup:
|
| 187 |
+
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 188 |
+
print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
|
| 189 |
+
else:
|
| 190 |
+
print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
| 191 |
+
|
| 192 |
+
if space_id_startup: # Print repo URLs if SPACE_ID is found
|
| 193 |
+
print(f"✅ SPACE_ID found: {space_id_startup}")
|
| 194 |
+
print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
|
| 195 |
+
print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")
|
| 196 |
+
else:
|
| 197 |
+
print("ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined.")
|
| 198 |
+
|
| 199 |
+
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 200 |
+
|
| 201 |
+
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 202 |
+
demo.launch(debug=True, share=True)
|
exploration.ipynb
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "94bd79f6",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"# Overview of the GAIA dataset"
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"cell_type": "code",
|
| 13 |
+
"execution_count": 1,
|
| 14 |
+
"id": "773d3352",
|
| 15 |
+
"metadata": {},
|
| 16 |
+
"outputs": [
|
| 17 |
+
{
|
| 18 |
+
"data": {
|
| 19 |
+
"text/plain": [
|
| 20 |
+
"{'task_id': 'c61d22de-5f6c-4958-a7f6-5e9707bd3466',\n",
|
| 21 |
+
" 'Question': 'A paper about AI regulation that was originally submitted to arXiv.org in June 2022 shows a figure with three axes, where each axis has a label word at both ends. Which of these words is used to describe a type of society in a Physics and Society article submitted to arXiv.org on August 11, 2016?',\n",
|
| 22 |
+
" 'Level': 2,\n",
|
| 23 |
+
" 'Final answer': 'egalitarian',\n",
|
| 24 |
+
" 'file_name': '',\n",
|
| 25 |
+
" 'Annotator Metadata': {'Steps': '1. Go to arxiv.org and navigate to the Advanced Search page.\\n2. Enter \"AI regulation\" in the search box and select \"All fields\" from the dropdown.\\n3. Enter 2022-06-01 and 2022-07-01 into the date inputs, select \"Submission date (original)\", and submit the search.\\n4. Go through the search results to find the article that has a figure with three axes and labels on each end of the axes, titled \"Fairness in Agreement With European Values: An Interdisciplinary Perspective on AI Regulation\".\\n5. Note the six words used as labels: deontological, egalitarian, localized, standardized, utilitarian, and consequential.\\n6. Go back to arxiv.org\\n7. Find \"Physics and Society\" and go to the page for the \"Physics and Society\" category.\\n8. Note that the tag for this category is \"physics.soc-ph\".\\n9. Go to the Advanced Search page.\\n10. Enter \"physics.soc-ph\" in the search box and select \"All fields\" from the dropdown.\\n11. Enter 2016-08-11 and 2016-08-12 into the date inputs, select \"Submission date (original)\", and submit the search.\\n12. Search for instances of the six words in the results to find the paper titled \"Phase transition from egalitarian to hierarchical societies driven by competition between cognitive and social constraints\", indicating that \"egalitarian\" is the correct answer.',\n",
|
| 26 |
+
" 'Number of steps': '12',\n",
|
| 27 |
+
" 'How long did this take?': '8 minutes',\n",
|
| 28 |
+
" 'Tools': '1. Web browser\\n2. Image recognition tools (to identify and parse a figure with three axes)',\n",
|
| 29 |
+
" 'Number of tools': '2'}}"
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
"execution_count": 1,
|
| 33 |
+
"metadata": {},
|
| 34 |
+
"output_type": "execute_result"
|
| 35 |
+
}
|
| 36 |
+
],
|
| 37 |
+
"source": [
|
| 38 |
+
"\n",
|
| 39 |
+
"import json\n",
|
| 40 |
+
"# Load the metadata.jsonl file\n",
|
| 41 |
+
"with open('metadata.jsonl', 'r') as jsonl_file:\n",
|
| 42 |
+
" json_list = list(jsonl_file)\n",
|
| 43 |
+
"\n",
|
| 44 |
+
"json_QA = []\n",
|
| 45 |
+
"for json_str in json_list:\n",
|
| 46 |
+
" json_data = json.loads(json_str)\n",
|
| 47 |
+
" json_QA.append(json_data)\n",
|
| 48 |
+
" \n",
|
| 49 |
+
"\n",
|
| 50 |
+
"json_QA[0]\n",
|
| 51 |
+
" "
|
| 52 |
+
]
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"cell_type": "code",
|
| 56 |
+
"execution_count": 2,
|
| 57 |
+
"id": "be320045",
|
| 58 |
+
"metadata": {},
|
| 59 |
+
"outputs": [
|
| 60 |
+
{
|
| 61 |
+
"name": "stdout",
|
| 62 |
+
"output_type": "stream",
|
| 63 |
+
"text": [
|
| 64 |
+
"==================================================\n",
|
| 65 |
+
"Task ID: 0ff53813-3367-4f43-bcbd-3fd725c1bf4b\n",
|
| 66 |
+
"Question: What two-word type of model did Manash Pratim Kashyap's and PS Fader's studies in customer retention studies published during 2018-2019 have in common (no punctuation)?\n",
|
| 67 |
+
"Level: 2\n",
|
| 68 |
+
"Final Answer: beta geometric\n",
|
| 69 |
+
"Annotator Metadata: \n",
|
| 70 |
+
" ├── Steps: \n",
|
| 71 |
+
" │ ├── 1. Searched \"Manash Pratim Kashyap customer retention\" on Google.\n",
|
| 72 |
+
" │ ├── 2. Opened https://www.journalijar.com/article/26843/a-simple-model-for-analyzing-the-customer-retention-comparing-rural-and-urban-store/.\n",
|
| 73 |
+
" │ ├── 3. Noted \"discrete time beta geometric model\" in the abstract.\n",
|
| 74 |
+
" │ ├── 4. Searched \"PS Fader customer retention\" on Google.\n",
|
| 75 |
+
" │ ├── 5. Opened https://www.sciencedirect.com/science/article/abs/pii/S1094996807700233.\n",
|
| 76 |
+
" │ ├── 6. Noted \"basic model (known as a “shifted-beta-geometric”)\" in the abstract.\n",
|
| 77 |
+
" │ ├── 7. Extracted the two words in common.\n",
|
| 78 |
+
" ├── Number of steps: 6\n",
|
| 79 |
+
" ├── How long did this take?: 10 minutes\n",
|
| 80 |
+
" ├── Tools:\n",
|
| 81 |
+
" │ ├── 1. Web browser\n",
|
| 82 |
+
" │ ├── 2. Search engine\n",
|
| 83 |
+
" └── Number of tools: 2\n",
|
| 84 |
+
"==================================================\n"
|
| 85 |
+
]
|
| 86 |
+
}
|
| 87 |
+
],
|
| 88 |
+
"source": [
|
| 89 |
+
"\n",
|
| 90 |
+
"import random\n",
|
| 91 |
+
"# random.seed(42)\n",
|
| 92 |
+
"random_samples = random.sample(json_QA, 1)\n",
|
| 93 |
+
"for sample in random_samples:\n",
|
| 94 |
+
" print(\"=\" * 50)\n",
|
| 95 |
+
" print(f\"Task ID: {sample['task_id']}\")\n",
|
| 96 |
+
" print(f\"Question: {sample['Question']}\")\n",
|
| 97 |
+
" print(f\"Level: {sample['Level']}\")\n",
|
| 98 |
+
" print(f\"Final Answer: {sample['Final answer']}\")\n",
|
| 99 |
+
" print(f\"Annotator Metadata: \")\n",
|
| 100 |
+
" print(f\" ├── Steps: \")\n",
|
| 101 |
+
" for step in sample['Annotator Metadata']['Steps'].split('\\n'):\n",
|
| 102 |
+
" print(f\" │ ├── {step}\")\n",
|
| 103 |
+
" print(f\" ├── Number of steps: {sample['Annotator Metadata']['Number of steps']}\")\n",
|
| 104 |
+
" print(f\" ├── How long did this take?: {sample['Annotator Metadata']['How long did this take?']}\")\n",
|
| 105 |
+
" print(f\" ├── Tools:\")\n",
|
| 106 |
+
" for tool in sample['Annotator Metadata']['Tools'].split('\\n'):\n",
|
| 107 |
+
" print(f\" │ ├── {tool}\")\n",
|
| 108 |
+
" print(f\" └── Number of tools: {sample['Annotator Metadata']['Number of tools']}\")\n",
|
| 109 |
+
"print(\"=\" * 50)"
|
| 110 |
+
]
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"cell_type": "code",
|
| 114 |
+
"execution_count": 3,
|
| 115 |
+
"id": "64c5ca54",
|
| 116 |
+
"metadata": {},
|
| 117 |
+
"outputs": [
|
| 118 |
+
{
|
| 119 |
+
"data": {
|
| 120 |
+
"text/plain": [
|
| 121 |
+
"[{'task_id': 'c61d22de-5f6c-4958-a7f6-5e9707bd3466',\n",
|
| 122 |
+
" 'Question': 'A paper about AI regulation that was originally submitted to arXiv.org in June 2022 shows a figure with three axes, where each axis has a label word at both ends. Which of these words is used to describe a type of society in a Physics and Society article submitted to arXiv.org on August 11, 2016?',\n",
|
| 123 |
+
" 'Level': 2,\n",
|
| 124 |
+
" 'Final answer': 'egalitarian',\n",
|
| 125 |
+
" 'file_name': '',\n",
|
| 126 |
+
" 'Annotator Metadata': {'Steps': '1. Go to arxiv.org and navigate to the Advanced Search page.\\n2. Enter \"AI regulation\" in the search box and select \"All fields\" from the dropdown.\\n3. Enter 2022-06-01 and 2022-07-01 into the date inputs, select \"Submission date (original)\", and submit the search.\\n4. Go through the search results to find the article that has a figure with three axes and labels on each end of the axes, titled \"Fairness in Agreement With European Values: An Interdisciplinary Perspective on AI Regulation\".\\n5. Note the six words used as labels: deontological, egalitarian, localized, standardized, utilitarian, and consequential.\\n6. Go back to arxiv.org\\n7. Find \"Physics and Society\" and go to the page for the \"Physics and Society\" category.\\n8. Note that the tag for this category is \"physics.soc-ph\".\\n9. Go to the Advanced Search page.\\n10. Enter \"physics.soc-ph\" in the search box and select \"All fields\" from the dropdown.\\n11. Enter 2016-08-11 and 2016-08-12 into the date inputs, select \"Submission date (original)\", and submit the search.\\n12. Search for instances of the six words in the results to find the paper titled \"Phase transition from egalitarian to hierarchical societies driven by competition between cognitive and social constraints\", indicating that \"egalitarian\" is the correct answer.',\n",
|
| 127 |
+
" 'Number of steps': '12',\n",
|
| 128 |
+
" 'How long did this take?': '8 minutes',\n",
|
| 129 |
+
" 'Tools': '1. Web browser\\n2. Image recognition tools (to identify and parse a figure with three axes)',\n",
|
| 130 |
+
" 'Number of tools': '2'}},\n",
|
| 131 |
+
" {'task_id': '17b5a6a3-bc87-42e8-b0fb-6ab0781ef2cc',\n",
|
| 132 |
+
" 'Question': 'I’m researching species that became invasive after people who kept them as pets released them. There’s a certain species of fish that was popularized as a pet by being the main character of the movie Finding Nemo. According to the USGS, where was this fish found as a nonnative species, before the year 2020? I need the answer formatted as the five-digit zip codes of the places the species was found, separated by commas if there is more than one place.',\n",
|
| 133 |
+
" 'Level': 2,\n",
|
| 134 |
+
" 'Final answer': '34689',\n",
|
| 135 |
+
" 'file_name': '',\n",
|
| 136 |
+
" 'Annotator Metadata': {'Steps': '1. Search the web for “finding nemo main character”.\\n2. Note the results, which state that the main character is a clownfish.\\n3. Search the web for “usgs nonnative species database”.\\n4. Click result for the Nonindigenous Aquatic Species site.\\n5. Click “Marine Fishes”.\\n6. Click “Species List of Nonindigenous Marine Fish”.\\n7. Scroll through the list until I find the clown anenomefish, and click “Collection info”.\\n8. Note the place that a clown anenomefish was found, in Fred Howard Park at the Gulf of Mexico.\\n9. Search the web for “fred howard park florida zip code”.\\n10. Note the zip code, 34689. Since only one clownfish was found before the year 2020, this is the answer.',\n",
|
| 137 |
+
" 'Number of steps': '10',\n",
|
| 138 |
+
" 'How long did this take?': '5 minutes',\n",
|
| 139 |
+
" 'Tools': '1. Search engine\\n2. Web browser',\n",
|
| 140 |
+
" 'Number of tools': '2'}},\n",
|
| 141 |
+
" {'task_id': '04a04a9b-226c-43fd-b319-d5e89743676f',\n",
|
| 142 |
+
" 'Question': 'If we assume all articles published by Nature in 2020 (articles, only, not book reviews/columns, etc) relied on statistical significance to justify their findings and they on average came to a p-value of 0.04, how many papers would be incorrect as to their claims of statistical significance? Round the value up to the next integer.',\n",
|
| 143 |
+
" 'Level': 2,\n",
|
| 144 |
+
" 'Final answer': '41',\n",
|
| 145 |
+
" 'file_name': '',\n",
|
| 146 |
+
" 'Annotator Metadata': {'Steps': '1. Find how many articles were published in Nature in 2020 by Googling \"articles submitted to nature 2020\"\\n2. Click through to Nature\\'s archive for 2020 and filter the results to only provide articles, not other types of publications: 1002\\n3. Find 4% of 1002 and round up: 40.08 > 41',\n",
|
| 147 |
+
" 'Number of steps': '3',\n",
|
| 148 |
+
" 'How long did this take?': '5 minutes',\n",
|
| 149 |
+
" 'Tools': '1. search engine\\n2. calculator',\n",
|
| 150 |
+
" 'Number of tools': '2'}}]"
|
| 151 |
+
]
|
| 152 |
+
},
|
| 153 |
+
"execution_count": 3,
|
| 154 |
+
"metadata": {},
|
| 155 |
+
"output_type": "execute_result"
|
| 156 |
+
}
|
| 157 |
+
],
|
| 158 |
+
"source": [
|
| 159 |
+
"json_QA[0:3]"
|
| 160 |
+
]
|
| 161 |
+
},
|
| 162 |
+
{
|
| 163 |
+
"cell_type": "markdown",
|
| 164 |
+
"id": "d4ddf21d",
|
| 165 |
+
"metadata": {},
|
| 166 |
+
"source": []
|
| 167 |
+
}
|
| 168 |
+
],
|
| 169 |
+
"metadata": {
|
| 170 |
+
"kernelspec": {
|
| 171 |
+
"display_name": "Python 3",
|
| 172 |
+
"language": "python",
|
| 173 |
+
"name": "python3"
|
| 174 |
+
},
|
| 175 |
+
"language_info": {
|
| 176 |
+
"codemirror_mode": {
|
| 177 |
+
"name": "ipython",
|
| 178 |
+
"version": 3
|
| 179 |
+
},
|
| 180 |
+
"file_extension": ".py",
|
| 181 |
+
"mimetype": "text/x-python",
|
| 182 |
+
"name": "python",
|
| 183 |
+
"nbconvert_exporter": "python",
|
| 184 |
+
"pygments_lexer": "ipython3",
|
| 185 |
+
"version": "3.10.12"
|
| 186 |
+
}
|
| 187 |
+
},
|
| 188 |
+
"nbformat": 4,
|
| 189 |
+
"nbformat_minor": 5
|
| 190 |
+
}
|
metadata.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|
| 3 |
+
langchain-community
|
| 4 |
+
langchain-core
|
| 5 |
+
langchain-google-genai
|
| 6 |
+
langchain-huggingface
|
| 7 |
+
langchain-groq
|
| 8 |
+
langchain-tavily
|
| 9 |
+
langchain-chroma
|
| 10 |
+
langgraph
|
| 11 |
+
huggingface_hub
|
| 12 |
+
supabase
|
| 13 |
+
arxiv
|
| 14 |
+
pymupdf
|
| 15 |
+
wikipedia
|
| 16 |
+
pgvector
|
| 17 |
+
python-dotenv
|
| 18 |
+
matplotlib
|
| 19 |
+
pytesseract
|
| 20 |
+
flake8
|
system_prompt.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a general AI assistant.
|
| 2 |
+
I will ask you a question.
|
| 3 |
+
Report your thoughts, and finish your answer with the following template:
|
| 4 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 5 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 6 |
+
If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
|
| 7 |
+
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|
| 8 |
+
If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|