Spaces:
Runtime error
Runtime error
DirtyFock
commited on
Commit
·
28a72c5
1
Parent(s):
81917a3
First iteration of ToolAgent with custom OllamaModel
Browse files- .gitignore +177 -0
- .vscode/settings.json +3 -0
- TODO.md +38 -0
- app.py +77 -41
- https:/agents-course-unit4-scoring.hf.space/questions +122 -0
- notebooks/data.ipynb +267 -0
- pyproject.toml +33 -0
- src/models.py +221 -0
- src/tools_registry.py +47 -0
- src/utils.py +65 -0
- uv.lock +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 139 |
+
# Spyder project settings
|
| 140 |
+
.spyderproject
|
| 141 |
+
.spyproject
|
| 142 |
+
|
| 143 |
+
# Rope project settings
|
| 144 |
+
.ropeproject
|
| 145 |
+
|
| 146 |
+
# mkdocs documentation
|
| 147 |
+
/site
|
| 148 |
+
|
| 149 |
+
# mypy
|
| 150 |
+
.mypy_cache/
|
| 151 |
+
.dmypy.json
|
| 152 |
+
dmypy.json
|
| 153 |
+
|
| 154 |
+
# Pyre type checker
|
| 155 |
+
.pyre/
|
| 156 |
+
|
| 157 |
+
# pytype static type analyzer
|
| 158 |
+
.pytype/
|
| 159 |
+
|
| 160 |
+
# Cython debug symbols
|
| 161 |
+
cython_debug/
|
| 162 |
+
|
| 163 |
+
# PyCharm
|
| 164 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 165 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 166 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 167 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 168 |
+
#.idea/
|
| 169 |
+
|
| 170 |
+
# Ruff stuff:
|
| 171 |
+
.ruff_cache/
|
| 172 |
+
|
| 173 |
+
# PyPI configuration file
|
| 174 |
+
.pypirc
|
| 175 |
+
|
| 176 |
+
# Custom ignored files
|
| 177 |
+
.data
|
.vscode/settings.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"continue.telemetryEnabled": false,
|
| 3 |
+
}
|
TODO.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Tasks in GAIA subdataset
|
| 2 |
+
|
| 3 |
+
- [ ] Extract from Wikipedia (2022)
|
| 4 |
+
- [ ] Video from Youtube
|
| 5 |
+
- [ ] Inverted text
|
| 6 |
+
- [ ] Chess move from image
|
| 7 |
+
- [ ] Extract from Wikipedia (2016)
|
| 8 |
+
- [ ] Algebra
|
| 9 |
+
- [ ] Video from Youtube
|
| 10 |
+
- [ ] Retrieval from LibreText pdf
|
| 11 |
+
- [ ] Structured output
|
| 12 |
+
- [ ] ASR
|
| 13 |
+
- [ ] Extract from Wikipedia with polish wording
|
| 14 |
+
- [ ] Python code output
|
| 15 |
+
- [ ] Wikipedia baseball info
|
| 16 |
+
- [ ] ASR
|
| 17 |
+
- [ ] Web browsing
|
| 18 |
+
- [ ] Web browsing
|
| 19 |
+
- [ ] Web browsing, wikipedia sport info
|
| 20 |
+
- [ ] Wikipedia baseball info from table
|
| 21 |
+
- [ ] Excel file
|
| 22 |
+
- [ ] Web browsing, wikipedia
|
| 23 |
+
|
| 24 |
+
# Priorities
|
| 25 |
+
|
| 26 |
+
1. Web browsing
|
| 27 |
+
2. Wikipedia API
|
| 28 |
+
3. Video processing
|
| 29 |
+
4. PDF Extraction
|
| 30 |
+
5. ASR
|
| 31 |
+
|
| 32 |
+
# Extensions
|
| 33 |
+
|
| 34 |
+
- Sympy/Mathematica : Algebra
|
| 35 |
+
- OpenCV : CV
|
| 36 |
+
- Stockfish : Chess moves
|
| 37 |
+
- NLTK/spaCy : NLP
|
| 38 |
+
- docling : PDF extraction
|
app.py
CHANGED
|
@@ -1,34 +1,39 @@
|
|
| 1 |
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
import requests
|
| 4 |
-
|
|
|
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
fixed_answer = "This is a default answer."
|
| 19 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 20 |
-
return fixed_answer
|
| 21 |
-
|
| 22 |
-
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
| 24 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 25 |
and displays the results.
|
| 26 |
"""
|
| 27 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 28 |
-
space_id = os.getenv("SPACE_ID")
|
| 29 |
|
| 30 |
if profile:
|
| 31 |
-
username= f"{profile.username}"
|
| 32 |
print(f"User logged in: {username}")
|
| 33 |
else:
|
| 34 |
print("User not logged in.")
|
|
@@ -40,7 +45,17 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 40 |
|
| 41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 42 |
try:
|
| 43 |
-
agent =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
print(f"Error instantiating agent: {e}")
|
| 46 |
return f"Error initializing agent: {e}", None
|
|
@@ -55,16 +70,16 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 55 |
response.raise_for_status()
|
| 56 |
questions_data = response.json()
|
| 57 |
if not questions_data:
|
| 58 |
-
|
| 59 |
-
|
| 60 |
print(f"Fetched {len(questions_data)} questions.")
|
| 61 |
except requests.exceptions.RequestException as e:
|
| 62 |
print(f"Error fetching questions: {e}")
|
| 63 |
return f"Error fetching questions: {e}", None
|
| 64 |
except requests.exceptions.JSONDecodeError as e:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
except Exception as e:
|
| 69 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 70 |
return f"An unexpected error occurred fetching questions: {e}", None
|
|
@@ -80,19 +95,37 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 80 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 81 |
continue
|
| 82 |
try:
|
| 83 |
-
submitted_answer = agent(question_text)
|
| 84 |
-
answers_payload.append(
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
except Exception as e:
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
if not answers_payload:
|
| 91 |
print("Agent did not produce any answers to submit.")
|
| 92 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 93 |
|
| 94 |
-
# 4. Prepare Submission
|
| 95 |
-
submission_data = {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 97 |
print(status_update)
|
| 98 |
|
|
@@ -162,20 +195,19 @@ with gr.Blocks() as demo:
|
|
| 162 |
|
| 163 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 164 |
|
| 165 |
-
status_output = gr.Textbox(
|
|
|
|
|
|
|
| 166 |
# Removed max_rows=10 from DataFrame constructor
|
| 167 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 168 |
|
| 169 |
-
run_button.click(
|
| 170 |
-
fn=run_and_submit_all,
|
| 171 |
-
outputs=[status_output, results_table]
|
| 172 |
-
)
|
| 173 |
|
| 174 |
if __name__ == "__main__":
|
| 175 |
-
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
| 176 |
# Check for SPACE_HOST and SPACE_ID at startup for information
|
| 177 |
space_host_startup = os.getenv("SPACE_HOST")
|
| 178 |
-
space_id_startup = os.getenv("SPACE_ID")
|
| 179 |
|
| 180 |
if space_host_startup:
|
| 181 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
|
@@ -183,14 +215,18 @@ if __name__ == "__main__":
|
|
| 183 |
else:
|
| 184 |
print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
| 185 |
|
| 186 |
-
if space_id_startup:
|
| 187 |
print(f"✅ SPACE_ID found: {space_id_startup}")
|
| 188 |
print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
|
| 189 |
-
print(
|
|
|
|
|
|
|
| 190 |
else:
|
| 191 |
-
print(
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 194 |
|
| 195 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 196 |
-
demo.launch(debug=True, share=False)
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import requests
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import (
|
| 7 |
+
DuckDuckGoSearchTool,
|
| 8 |
+
WikipediaSearchTool,
|
| 9 |
+
VisitWebpageTool,
|
| 10 |
+
ToolCallingAgent,
|
| 11 |
+
)
|
| 12 |
+
import openlit
|
| 13 |
+
|
| 14 |
+
from src.models import OllamaModel
|
| 15 |
+
from src.tools_registry import ToolsRegistry
|
| 16 |
|
| 17 |
# (Keep Constants as is)
|
| 18 |
# --- Constants ---
|
| 19 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 20 |
|
| 21 |
+
|
| 22 |
+
openlit.init(
|
| 23 |
+
otlp_endpoint="http://127.0.0.1:4318", application_name="Final Assignment GAIA"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
"""
|
| 29 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 30 |
and displays the results.
|
| 31 |
"""
|
| 32 |
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 33 |
+
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 34 |
|
| 35 |
if profile:
|
| 36 |
+
username = f"{profile.username}"
|
| 37 |
print(f"User logged in: {username}")
|
| 38 |
else:
|
| 39 |
print("User not logged in.")
|
|
|
|
| 45 |
|
| 46 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 47 |
try:
|
| 48 |
+
agent = ToolCallingAgent(
|
| 49 |
+
tools=[
|
| 50 |
+
DuckDuckGoSearchTool(),
|
| 51 |
+
VisitWebpageTool(),
|
| 52 |
+
WikipediaSearchTool(content_type="text"),
|
| 53 |
+
],
|
| 54 |
+
max_steps=20,
|
| 55 |
+
model=OllamaModel(model_id="qwen3:14b", tools_registry=ToolsRegistry),
|
| 56 |
+
planning_interval=5,
|
| 57 |
+
add_base_tools=True,
|
| 58 |
+
)
|
| 59 |
except Exception as e:
|
| 60 |
print(f"Error instantiating agent: {e}")
|
| 61 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 70 |
response.raise_for_status()
|
| 71 |
questions_data = response.json()
|
| 72 |
if not questions_data:
|
| 73 |
+
print("Fetched questions list is empty.")
|
| 74 |
+
return "Fetched questions list is empty or invalid format.", None
|
| 75 |
print(f"Fetched {len(questions_data)} questions.")
|
| 76 |
except requests.exceptions.RequestException as e:
|
| 77 |
print(f"Error fetching questions: {e}")
|
| 78 |
return f"Error fetching questions: {e}", None
|
| 79 |
except requests.exceptions.JSONDecodeError as e:
|
| 80 |
+
print(f"Error decoding JSON response from questions endpoint: {e}")
|
| 81 |
+
print(f"Response text: {response.text[:500]}")
|
| 82 |
+
return f"Error decoding server response for questions: {e}", None
|
| 83 |
except Exception as e:
|
| 84 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 85 |
return f"An unexpected error occurred fetching questions: {e}", None
|
|
|
|
| 95 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 96 |
continue
|
| 97 |
try:
|
| 98 |
+
submitted_answer = agent.run(question_text)
|
| 99 |
+
answers_payload.append(
|
| 100 |
+
{"task_id": task_id, "submitted_answer": submitted_answer}
|
| 101 |
+
)
|
| 102 |
+
results_log.append(
|
| 103 |
+
{
|
| 104 |
+
"Task ID": task_id,
|
| 105 |
+
"Question": question_text,
|
| 106 |
+
"Submitted Answer": submitted_answer,
|
| 107 |
+
}
|
| 108 |
+
)
|
| 109 |
except Exception as e:
|
| 110 |
+
print(f"Error running agent on task {task_id}: {e}")
|
| 111 |
+
results_log.append(
|
| 112 |
+
{
|
| 113 |
+
"Task ID": task_id,
|
| 114 |
+
"Question": question_text,
|
| 115 |
+
"Submitted Answer": f"AGENT ERROR: {e}",
|
| 116 |
+
}
|
| 117 |
+
)
|
| 118 |
|
| 119 |
if not answers_payload:
|
| 120 |
print("Agent did not produce any answers to submit.")
|
| 121 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 122 |
|
| 123 |
+
# 4. Prepare Submission
|
| 124 |
+
submission_data = {
|
| 125 |
+
"username": username.strip(),
|
| 126 |
+
"agent_code": agent_code,
|
| 127 |
+
"answers": answers_payload,
|
| 128 |
+
}
|
| 129 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 130 |
print(status_update)
|
| 131 |
|
|
|
|
| 195 |
|
| 196 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 197 |
|
| 198 |
+
status_output = gr.Textbox(
|
| 199 |
+
label="Run Status / Submission Result", lines=5, interactive=False
|
| 200 |
+
)
|
| 201 |
# Removed max_rows=10 from DataFrame constructor
|
| 202 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 203 |
|
| 204 |
+
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
if __name__ == "__main__":
|
| 207 |
+
print("\n" + "-" * 30 + " App Starting " + "-" * 30)
|
| 208 |
# Check for SPACE_HOST and SPACE_ID at startup for information
|
| 209 |
space_host_startup = os.getenv("SPACE_HOST")
|
| 210 |
+
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
| 211 |
|
| 212 |
if space_host_startup:
|
| 213 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
|
|
|
| 215 |
else:
|
| 216 |
print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
| 217 |
|
| 218 |
+
if space_id_startup: # Print repo URLs if SPACE_ID is found
|
| 219 |
print(f"✅ SPACE_ID found: {space_id_startup}")
|
| 220 |
print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
|
| 221 |
+
print(
|
| 222 |
+
f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main"
|
| 223 |
+
)
|
| 224 |
else:
|
| 225 |
+
print(
|
| 226 |
+
"ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined."
|
| 227 |
+
)
|
| 228 |
|
| 229 |
+
print("-" * (60 + len(" App Starting ")) + "\n")
|
| 230 |
|
| 231 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 232 |
+
demo.launch(debug=True, share=False)
|
https:/agents-course-unit4-scoring.hf.space/questions
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"task_id": "8e867cd7-cff9-4e6c-867a-ff5ddc2550be",
|
| 4 |
+
"question": "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.",
|
| 5 |
+
"Level": "1",
|
| 6 |
+
"file_name": ""
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"task_id": "a1e91b78-d3d8-4675-bb8d-62741b4b68a6",
|
| 10 |
+
"question": "In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?",
|
| 11 |
+
"Level": "1",
|
| 12 |
+
"file_name": ""
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"task_id": "2d83110e-a098-4ebb-9987-066c06fa42d0",
|
| 16 |
+
"question": ".rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI",
|
| 17 |
+
"Level": "1",
|
| 18 |
+
"file_name": ""
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"task_id": "cca530fc-4052-43b2-b130-b30968d8aa44",
|
| 22 |
+
"question": "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
|
| 23 |
+
"Level": "1",
|
| 24 |
+
"file_name": "cca530fc-4052-43b2-b130-b30968d8aa44.png"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"task_id": "4fc2f1ae-8625-45b5-ab34-ad4433bc21f8",
|
| 28 |
+
"question": "Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?",
|
| 29 |
+
"Level": "1",
|
| 30 |
+
"file_name": ""
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"task_id": "6f37996b-2ac7-44b0-8e68-6d28256631b4",
|
| 34 |
+
"question": "Given this table defining * on the set S = {a, b, c, d, e}\n\n|*|a|b|c|d|e|\n|---|---|---|---|---|---|\n|a|a|b|c|b|d|\n|b|b|c|a|e|c|\n|c|c|a|b|b|a|\n|d|b|e|b|e|d|\n|e|d|b|a|d|c|\n\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.",
|
| 35 |
+
"Level": "1",
|
| 36 |
+
"file_name": ""
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"task_id": "9d191bce-651d-4746-be2d-7ef8ecadb9c2",
|
| 40 |
+
"question": "Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec.\n\nWhat does Teal'c say in response to the question \"Isn't that hot?\"",
|
| 41 |
+
"Level": "1",
|
| 42 |
+
"file_name": ""
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"task_id": "cabe07ed-9eca-40ea-8ead-410ef5e83f91",
|
| 46 |
+
"question": "What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?",
|
| 47 |
+
"Level": "1",
|
| 48 |
+
"file_name": ""
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"task_id": "3cef3a44-215e-4aed-8e3b-b1e3f08063b7",
|
| 52 |
+
"question": "I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\n\nmilk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\n\nI need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.",
|
| 53 |
+
"Level": "1",
|
| 54 |
+
"file_name": ""
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"task_id": "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3",
|
| 58 |
+
"question": "Hi, I'm making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I'm not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can't quite make out what she's saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I've attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.",
|
| 59 |
+
"Level": "1",
|
| 60 |
+
"file_name": "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"task_id": "305ac316-eef6-4446-960a-92d80d542f82",
|
| 64 |
+
"question": "Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.",
|
| 65 |
+
"Level": "1",
|
| 66 |
+
"file_name": ""
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"task_id": "f918266a-b3e0-4914-865d-4faa564f1aef",
|
| 70 |
+
"question": "What is the final numeric output from the attached Python code?",
|
| 71 |
+
"Level": "1",
|
| 72 |
+
"file_name": "f918266a-b3e0-4914-865d-4faa564f1aef.py"
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"task_id": "3f57289b-8c60-48be-bd80-01f8099ca449",
|
| 76 |
+
"question": "How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?",
|
| 77 |
+
"Level": "1",
|
| 78 |
+
"file_name": ""
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"task_id": "1f975693-876d-457b-a649-393859e79bf3",
|
| 82 |
+
"question": "Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.",
|
| 83 |
+
"Level": "1",
|
| 84 |
+
"file_name": "1f975693-876d-457b-a649-393859e79bf3.mp3"
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"task_id": "840bfca7-4f7b-481a-8794-c560c340185d",
|
| 88 |
+
"question": "On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?",
|
| 89 |
+
"Level": "1",
|
| 90 |
+
"file_name": ""
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"task_id": "bda648d7-d618-4883-88f4-3466eabd860e",
|
| 94 |
+
"question": "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.",
|
| 95 |
+
"Level": "1",
|
| 96 |
+
"file_name": ""
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"task_id": "cf106601-ab4f-4af9-b045-5295fe67b37d",
|
| 100 |
+
"question": "What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.",
|
| 101 |
+
"Level": "1",
|
| 102 |
+
"file_name": ""
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"task_id": "a0c07678-e491-4bbc-8f0b-07405144218f",
|
| 106 |
+
"question": "Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters.",
|
| 107 |
+
"Level": "1",
|
| 108 |
+
"file_name": ""
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"task_id": "7bd855d8-463d-4ed5-93ca-5fe35145f733",
|
| 112 |
+
"question": "The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.",
|
| 113 |
+
"Level": "1",
|
| 114 |
+
"file_name": "7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"task_id": "5a0c1adf-205e-4841-a666-7c3ef95def9d",
|
| 118 |
+
"question": "What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?",
|
| 119 |
+
"Level": "1",
|
| 120 |
+
"file_name": ""
|
| 121 |
+
}
|
| 122 |
+
]
|
notebooks/data.ipynb
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "9d48d80a",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"data": {
|
| 11 |
+
"text/plain": [
|
| 12 |
+
"True"
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
"execution_count": 1,
|
| 16 |
+
"metadata": {},
|
| 17 |
+
"output_type": "execute_result"
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"source": [
|
| 21 |
+
"from dotenv import load_dotenv\n",
|
| 22 |
+
"load_dotenv()"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"cell_type": "code",
|
| 27 |
+
"execution_count": 2,
|
| 28 |
+
"id": "202697c1",
|
| 29 |
+
"metadata": {},
|
| 30 |
+
"outputs": [],
|
| 31 |
+
"source": [
|
| 32 |
+
"import os\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"api_url = os.getenv(\"DEFAULT_API_URL\")\n",
|
| 35 |
+
"questions_url = f\"{api_url}/questions\""
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"cell_type": "code",
|
| 40 |
+
"execution_count": null,
|
| 41 |
+
"id": "ac69d5c0",
|
| 42 |
+
"metadata": {},
|
| 43 |
+
"outputs": [
|
| 44 |
+
{
|
| 45 |
+
"name": "stdout",
|
| 46 |
+
"output_type": "stream",
|
| 47 |
+
"text": [
|
| 48 |
+
"Fetching questions from: https://agents-course-unit4-scoring.hf.space/questions\n",
|
| 49 |
+
"Fetched 20 questions.\n"
|
| 50 |
+
]
|
| 51 |
+
}
|
| 52 |
+
],
|
| 53 |
+
"source": [
|
| 54 |
+
"from utils import fetch_questions\n",
|
| 55 |
+
"\n",
|
| 56 |
+
"questions = fetch_questions(output_file_path=\"./.data/questions.json\")"
|
| 57 |
+
]
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"cell_type": "code",
|
| 61 |
+
"execution_count": 4,
|
| 62 |
+
"id": "080538b7",
|
| 63 |
+
"metadata": {},
|
| 64 |
+
"outputs": [
|
| 65 |
+
{
|
| 66 |
+
"data": {
|
| 67 |
+
"text/plain": [
|
| 68 |
+
"[{'task_id': '8e867cd7-cff9-4e6c-867a-ff5ddc2550be',\n",
|
| 69 |
+
" 'question': 'How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.',\n",
|
| 70 |
+
" 'Level': '1',\n",
|
| 71 |
+
" 'file_name': ''},\n",
|
| 72 |
+
" {'task_id': 'a1e91b78-d3d8-4675-bb8d-62741b4b68a6',\n",
|
| 73 |
+
" 'question': 'In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?',\n",
|
| 74 |
+
" 'Level': '1',\n",
|
| 75 |
+
" 'file_name': ''},\n",
|
| 76 |
+
" {'task_id': '2d83110e-a098-4ebb-9987-066c06fa42d0',\n",
|
| 77 |
+
" 'question': '.rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI',\n",
|
| 78 |
+
" 'Level': '1',\n",
|
| 79 |
+
" 'file_name': ''},\n",
|
| 80 |
+
" {'task_id': 'cca530fc-4052-43b2-b130-b30968d8aa44',\n",
|
| 81 |
+
" 'question': \"Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.\",\n",
|
| 82 |
+
" 'Level': '1',\n",
|
| 83 |
+
" 'file_name': 'cca530fc-4052-43b2-b130-b30968d8aa44.png'},\n",
|
| 84 |
+
" {'task_id': '4fc2f1ae-8625-45b5-ab34-ad4433bc21f8',\n",
|
| 85 |
+
" 'question': 'Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?',\n",
|
| 86 |
+
" 'Level': '1',\n",
|
| 87 |
+
" 'file_name': ''},\n",
|
| 88 |
+
" {'task_id': '6f37996b-2ac7-44b0-8e68-6d28256631b4',\n",
|
| 89 |
+
" 'question': 'Given this table defining * on the set S = {a, b, c, d, e}\\n\\n|*|a|b|c|d|e|\\n|---|---|---|---|---|---|\\n|a|a|b|c|b|d|\\n|b|b|c|a|e|c|\\n|c|c|a|b|b|a|\\n|d|b|e|b|e|d|\\n|e|d|b|a|d|c|\\n\\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.',\n",
|
| 90 |
+
" 'Level': '1',\n",
|
| 91 |
+
" 'file_name': ''},\n",
|
| 92 |
+
" {'task_id': '9d191bce-651d-4746-be2d-7ef8ecadb9c2',\n",
|
| 93 |
+
" 'question': 'Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec.\\n\\nWhat does Teal\\'c say in response to the question \"Isn\\'t that hot?\"',\n",
|
| 94 |
+
" 'Level': '1',\n",
|
| 95 |
+
" 'file_name': ''},\n",
|
| 96 |
+
" {'task_id': 'cabe07ed-9eca-40ea-8ead-410ef5e83f91',\n",
|
| 97 |
+
" 'question': \"What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?\",\n",
|
| 98 |
+
" 'Level': '1',\n",
|
| 99 |
+
" 'file_name': ''},\n",
|
| 100 |
+
" {'task_id': '3cef3a44-215e-4aed-8e3b-b1e3f08063b7',\n",
|
| 101 |
+
" 'question': \"I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\\n\\nmilk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\\n\\nI need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.\",\n",
|
| 102 |
+
" 'Level': '1',\n",
|
| 103 |
+
" 'file_name': ''},\n",
|
| 104 |
+
" {'task_id': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3',\n",
|
| 105 |
+
" 'question': 'Hi, I\\'m making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I\\'m not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can\\'t quite make out what she\\'s saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I\\'ve attached the recipe as Strawberry pie.mp3.\\n\\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\\n\\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.',\n",
|
| 106 |
+
" 'Level': '1',\n",
|
| 107 |
+
" 'file_name': '99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3'},\n",
|
| 108 |
+
" {'task_id': '305ac316-eef6-4446-960a-92d80d542f82',\n",
|
| 109 |
+
" 'question': 'Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.',\n",
|
| 110 |
+
" 'Level': '1',\n",
|
| 111 |
+
" 'file_name': ''},\n",
|
| 112 |
+
" {'task_id': 'f918266a-b3e0-4914-865d-4faa564f1aef',\n",
|
| 113 |
+
" 'question': 'What is the final numeric output from the attached Python code?',\n",
|
| 114 |
+
" 'Level': '1',\n",
|
| 115 |
+
" 'file_name': 'f918266a-b3e0-4914-865d-4faa564f1aef.py'},\n",
|
| 116 |
+
" {'task_id': '3f57289b-8c60-48be-bd80-01f8099ca449',\n",
|
| 117 |
+
" 'question': 'How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?',\n",
|
| 118 |
+
" 'Level': '1',\n",
|
| 119 |
+
" 'file_name': ''},\n",
|
| 120 |
+
" {'task_id': '1f975693-876d-457b-a649-393859e79bf3',\n",
|
| 121 |
+
" 'question': \"Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\\n\\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.\",\n",
|
| 122 |
+
" 'Level': '1',\n",
|
| 123 |
+
" 'file_name': '1f975693-876d-457b-a649-393859e79bf3.mp3'},\n",
|
| 124 |
+
" {'task_id': '840bfca7-4f7b-481a-8794-c560c340185d',\n",
|
| 125 |
+
" 'question': 'On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?',\n",
|
| 126 |
+
" 'Level': '1',\n",
|
| 127 |
+
" 'file_name': ''},\n",
|
| 128 |
+
" {'task_id': 'bda648d7-d618-4883-88f4-3466eabd860e',\n",
|
| 129 |
+
" 'question': \"Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.\",\n",
|
| 130 |
+
" 'Level': '1',\n",
|
| 131 |
+
" 'file_name': ''},\n",
|
| 132 |
+
" {'task_id': 'cf106601-ab4f-4af9-b045-5295fe67b37d',\n",
|
| 133 |
+
" 'question': \"What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.\",\n",
|
| 134 |
+
" 'Level': '1',\n",
|
| 135 |
+
" 'file_name': ''},\n",
|
| 136 |
+
" {'task_id': 'a0c07678-e491-4bbc-8f0b-07405144218f',\n",
|
| 137 |
+
" 'question': \"Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters.\",\n",
|
| 138 |
+
" 'Level': '1',\n",
|
| 139 |
+
" 'file_name': ''},\n",
|
| 140 |
+
" {'task_id': '7bd855d8-463d-4ed5-93ca-5fe35145f733',\n",
|
| 141 |
+
" 'question': 'The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.',\n",
|
| 142 |
+
" 'Level': '1',\n",
|
| 143 |
+
" 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'},\n",
|
| 144 |
+
" {'task_id': '5a0c1adf-205e-4841-a666-7c3ef95def9d',\n",
|
| 145 |
+
" 'question': 'What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?',\n",
|
| 146 |
+
" 'Level': '1',\n",
|
| 147 |
+
" 'file_name': ''}]"
|
| 148 |
+
]
|
| 149 |
+
},
|
| 150 |
+
"execution_count": 4,
|
| 151 |
+
"metadata": {},
|
| 152 |
+
"output_type": "execute_result"
|
| 153 |
+
}
|
| 154 |
+
],
|
| 155 |
+
"source": [
|
| 156 |
+
"questions"
|
| 157 |
+
]
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"cell_type": "code",
|
| 161 |
+
"execution_count": 5,
|
| 162 |
+
"id": "1f2812fd",
|
| 163 |
+
"metadata": {},
|
| 164 |
+
"outputs": [
|
| 165 |
+
{
|
| 166 |
+
"name": "stdout",
|
| 167 |
+
"output_type": "stream",
|
| 168 |
+
"text": [
|
| 169 |
+
"Downloading file associated with task_id cca530fc-4052-43b2-b130-b30968d8aa44...\n",
|
| 170 |
+
"File downloaded successfully for task_id: cca530fc-4052-43b2-b130-b30968d8aa44\n",
|
| 171 |
+
"Downloading file associated with task_id 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3...\n",
|
| 172 |
+
"File downloaded successfully for task_id: 99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3\n",
|
| 173 |
+
"Downloading file associated with task_id f918266a-b3e0-4914-865d-4faa564f1aef...\n",
|
| 174 |
+
"File downloaded successfully for task_id: f918266a-b3e0-4914-865d-4faa564f1aef\n",
|
| 175 |
+
"Downloading file associated with task_id 1f975693-876d-457b-a649-393859e79bf3...\n",
|
| 176 |
+
"File downloaded successfully for task_id: 1f975693-876d-457b-a649-393859e79bf3\n",
|
| 177 |
+
"Downloading file associated with task_id 7bd855d8-463d-4ed5-93ca-5fe35145f733...\n",
|
| 178 |
+
"File downloaded successfully for task_id: 7bd855d8-463d-4ed5-93ca-5fe35145f733\n"
|
| 179 |
+
]
|
| 180 |
+
}
|
| 181 |
+
],
|
| 182 |
+
"source": [
|
| 183 |
+
"from utils import download_questions_files\n",
|
| 184 |
+
"\n",
|
| 185 |
+
"download_questions_files(questions)"
|
| 186 |
+
]
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
"cell_type": "code",
|
| 190 |
+
"execution_count": 6,
|
| 191 |
+
"id": "5873eb0c",
|
| 192 |
+
"metadata": {},
|
| 193 |
+
"outputs": [],
|
| 194 |
+
"source": [
|
| 195 |
+
"import pandas as pd\n",
|
| 196 |
+
"\n",
|
| 197 |
+
"dataframe = pd.DataFrame.from_dict(questions)"
|
| 198 |
+
]
|
| 199 |
+
},
|
| 200 |
+
{
|
| 201 |
+
"cell_type": "code",
|
| 202 |
+
"execution_count": 7,
|
| 203 |
+
"id": "7223a976",
|
| 204 |
+
"metadata": {},
|
| 205 |
+
"outputs": [],
|
| 206 |
+
"source": [
|
| 207 |
+
"from pathlib import Path\n",
|
| 208 |
+
"\n",
|
| 209 |
+
"assets_type_dataframe = dataframe[\"file_name\"].apply(lambda x: Path(x).suffix).value_counts()"
|
| 210 |
+
]
|
| 211 |
+
},
|
| 212 |
+
{
|
| 213 |
+
"cell_type": "code",
|
| 214 |
+
"execution_count": 8,
|
| 215 |
+
"id": "18c629df",
|
| 216 |
+
"metadata": {},
|
| 217 |
+
"outputs": [
|
| 218 |
+
{
|
| 219 |
+
"data": {
|
| 220 |
+
"text/plain": [
|
| 221 |
+
"<Axes: xlabel='file_name', ylabel='count'>"
|
| 222 |
+
]
|
| 223 |
+
},
|
| 224 |
+
"execution_count": 8,
|
| 225 |
+
"metadata": {},
|
| 226 |
+
"output_type": "execute_result"
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"data": {
|
| 230 |
+
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjIAAAGxCAYAAAB4AFyyAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjEsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvc2/+5QAAAAlwSFlzAAAPYQAAD2EBqD+naQAAJP1JREFUeJzt3Xt0lPWdx/HP5MIQyAWIISQSE6QIlqtyK2IpaCpGZYWeolgKiKgsohCjiNlTgpRLim4xtlIUXEG7IFR3QcUtalkIKAVJAKsudwPkiAhWkiFBBiS//cPDnE5JQhgmeZ5feL/OmXN8rvNNnlrf53kmiccYYwQAAGChCKcHAAAACBUhAwAArEXIAAAAaxEyAADAWoQMAACwFiEDAACsRcgAAABrETIAAMBaUU4PUN+qqqp0+PBhxcXFyePxOD0OAACoA2OMTpw4odTUVEVE1HzfpdGHzOHDh5WWlub0GAAAIASlpaVq27ZtjdsbfcjExcVJ+v4bER8f7/A0AACgLnw+n9LS0gL/Ha9Jow+Zc4+T4uPjCRkAACxzoY+F8GFfAABgLUIGAABYi5ABAADWImQAAIC1CBkAAGAtQgYAAFiLkAEAANYiZAAAgLUIGQAAYC1CBgAAWIuQAQAA1iJkAACAtQgZAABgLUIGAABYi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AejJ+/Hi1b99eMTExSkpK0p133lnjn9YAAISGkAHqSc+ePbV48WLt3LlT7777rowxuuWWW3T27FmnRwOARoOQwWVtyZIlatGihVavXq2OHTuqWbNm+vnPf66TJ0/qlVdeUUZGhlq2bKlJkyYFBUhGRoZmzpype+65R82bN9eVV16p+fPnB537wQcf1IABA5SRkaHrr79es2bNUmlpqQ4cONDAX6V9zl2XVatWqUOHDmratKkGDx6s0tLSwD5PPfWUevTooT/+8Y/KyMhQQkKCRowYoRMnTgT2OXHihEaOHKnmzZsrJSVFzz77rAYOHKjs7GwHvqrG40LX58CBA4qIiFBRUVHQcQUFBUpPT1dVVZUTY1vvvvvuU7du3QJ/GPn06dO67rrrNHr06Gr3P378uEaOHKmkpCTFxMSoQ4cOWrx4sSTp1VdfVWxsrPbu3RvY/6GHHlKnTp108uTJ+v9iwiksf90RsNTixYtNdHS0+elPf2q2bdtmCgsLTWJiornlllvMXXfdZT777DPz9ttvmyZNmpjly5cHjktPTzdxcXEmPz/f7N692/zud78zkZGR5r333qv2fSoqKkx2drZp166d8fv9DfXlWevcdenVq5fZtGmTKSoqMn369DE33HBDYJ/p06eb2NhY87Of/cx88sknZsOGDaZNmzbm3/7t3wL73H///SY9Pd385S9/MZ988okZNmyYiYuLM5MnT3bgq2o86nJ9fvrTn5qHHnoo6Lhu3bqZvLy8hh630Thx4oS5+uqrTXZ2tjHGmMcff9xkZGSY8vJyY4wxJSUlRpLZvn27McaYiRMnmh49epitW7eakpIS8/7775u33norcL7hw4eb3r17mzNnzpjVq1eb6OhoU1RU1OBf16UiZHBZW7x4sZFk9u3bF1g3fvx406xZM3PixInAusGDB5vx48cHltPT082tt94adK67777bZGVlBa2bP3++ad68uZFkOnbsGPQ+qNm567J58+bAup07dxpJZsuWLcaY70OmWbNmxufzBfaZMmWK6du3rzHGGJ/PZ6Kjo83rr78e2F5WVmaaNWtGyFyiulyfFStWmJYtW5pTp04ZY4wpLi42Ho/HlJSUODFyo7Fp0yYTHR1tpk2bZqK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yiuv1PG7BaDeGAAI0bPPPmvS09MDyz/5yU/M5MmTA8vp6enm2WefNcYYs3HjRhMfH29OnToVdI727dubF1988YLvNX36dNOsWTPj8/kC66ZMmWL69u1b4zHHjh0zkswnn3xijDGmpKTESDIvvfRSYJ/XXnvNSDJr164NrMvPzzcdO3YMmnHZsmVB5545c6bp16/fBecGUL/4jAyABvHxxx+roqJCiYmJQeu//fbboMc/tcnIyFBcXFxgOSUlRUePHg0s7927V3l5edqyZYu+/vrrwJ2YQ4cOqUuXLoH9unXrFvjn5ORkSVLXrl2D1p07b2Vlpfbv369x48bpgQceCOzz3XffKSEhoU5zA6g/hAyABlFRUaGUlBStX7/+vG0tWrSo0zmio6ODlj0eT9BjoyFDhig9PV2LFi1Samqqqqqq1KVLF50+fbrG83g8nmrXnTtvRUWFJGnRokXq27dv0HkiIyPrNDeA+kPIAGgQ119/vY4cOaKoqChlZGSE/fx///vftXv3bi1atEg//vGPJUkffPDBJZ83OTlZqamp+vzzzzVy5MhLPh+A8CJkADSIzMxM9evXT0OHDtXTTz+ta665RocPH9Y777yjYcOGqVevXpd0/pYtWyoxMVELFy5USkqKDh06pCeffDIss8+YMUOTJk1SQkKCbr31Vvn9fhUVFen48ePKyckJy3sACA0/tQSgQXg8Hv3P//yPBgwYoLFjx+qaa67RiBEjdPDgwcDnVC5FRESEli9fruLiYnXp0kWPPvqonnnmmTBMLt1///166aWXtHjxYnXt2lU/+clPtGTJErVr1y4s5wcQOo8xxjg9BAAAQCi4IwMAAKxFyABwhc6dOys2Nrba19KlS50eD4BL8WgJgCscPHhQZ86cqXZbcnJy0O+PAYBzCBkAAGAtHi0BAABrETIAAMBahAwAALAWIQMAAKxFyAAAAGsRMgAAwFqEDAAAsBYhAwAArPX/uG2lj5Wfkn4AAAAASUVORK5CYII=",
|
| 231 |
+
"text/plain": [
|
| 232 |
+
"<Figure size 640x480 with 1 Axes>"
|
| 233 |
+
]
|
| 234 |
+
},
|
| 235 |
+
"metadata": {},
|
| 236 |
+
"output_type": "display_data"
|
| 237 |
+
}
|
| 238 |
+
],
|
| 239 |
+
"source": [
|
| 240 |
+
"import seaborn as sns\n",
|
| 241 |
+
"\n",
|
| 242 |
+
"sns.barplot(assets_type_dataframe)"
|
| 243 |
+
]
|
| 244 |
+
}
|
| 245 |
+
],
|
| 246 |
+
"metadata": {
|
| 247 |
+
"kernelspec": {
|
| 248 |
+
"display_name": ".venv",
|
| 249 |
+
"language": "python",
|
| 250 |
+
"name": "python3"
|
| 251 |
+
},
|
| 252 |
+
"language_info": {
|
| 253 |
+
"codemirror_mode": {
|
| 254 |
+
"name": "ipython",
|
| 255 |
+
"version": 3
|
| 256 |
+
},
|
| 257 |
+
"file_extension": ".py",
|
| 258 |
+
"mimetype": "text/x-python",
|
| 259 |
+
"name": "python",
|
| 260 |
+
"nbconvert_exporter": "python",
|
| 261 |
+
"pygments_lexer": "ipython3",
|
| 262 |
+
"version": "3.13.1"
|
| 263 |
+
}
|
| 264 |
+
},
|
| 265 |
+
"nbformat": 4,
|
| 266 |
+
"nbformat_minor": 5
|
| 267 |
+
}
|
pyproject.toml
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "final-assignment-gaia"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "My submission to the Huggingface Agents Course final hans-on"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.13"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"autohooks>=25.4.1",
|
| 9 |
+
"autohooks-plugin-black>=23.10.0",
|
| 10 |
+
"autohooks-plugin-ruff>=25.3.1",
|
| 11 |
+
"dotenv>=0.9.9",
|
| 12 |
+
"duckduckgo-search>=8.0.1",
|
| 13 |
+
"gradio[oauth]>=5.29.0",
|
| 14 |
+
"ipykernel>=6.29.5",
|
| 15 |
+
"ipython>=9.0.1",
|
| 16 |
+
"jupyter>=1.1.1",
|
| 17 |
+
"litellm>=1.68.0",
|
| 18 |
+
"markdownify>=1.1.0",
|
| 19 |
+
"ollama>=0.4.8",
|
| 20 |
+
"openlit>=1.33.20",
|
| 21 |
+
"openpyxl>=3.1.5",
|
| 22 |
+
"pyarrow>=20.0.0",
|
| 23 |
+
"requests>=2.32.3",
|
| 24 |
+
"seaborn>=0.13.2",
|
| 25 |
+
"smolagents>=1.14.0",
|
| 26 |
+
"torch>=2.7.0",
|
| 27 |
+
"transformers>=4.51.3",
|
| 28 |
+
"wikipedia-api>=0.8.1",
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
[tool.autohooks]
|
| 32 |
+
mode = "pythonpath"
|
| 33 |
+
pre-commit = ["autohooks.plugins.black", "autohooks.plugins.ruff"]
|
src/models.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
from copy import deepcopy
|
| 3 |
+
|
| 4 |
+
from smolagents import ChatMessage, Tool, tool_role_conversions, MessageRole, ApiModel
|
| 5 |
+
from smolagents.models import supports_stop_parameter
|
| 6 |
+
from smolagents.utils import make_image_url, encode_image_base64
|
| 7 |
+
from ollama import Client
|
| 8 |
+
from ollama import Message as OllamaMessage
|
| 9 |
+
|
| 10 |
+
from tools_registry import ToolsRegistry
|
| 11 |
+
|
| 12 |
+
DEFAULT_NUM_CTX = 8192
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class OllamaModel(ApiModel):
|
| 16 |
+
def __init__(
|
| 17 |
+
self,
|
| 18 |
+
host: str = "http://localhost:11434",
|
| 19 |
+
model_id: str = "gemma3:12b",
|
| 20 |
+
timeout: int = 120,
|
| 21 |
+
client_kwargs: dict[str, Any] | None = None,
|
| 22 |
+
custom_role_conversions: dict[str, str] | None = None,
|
| 23 |
+
flatten_messages_as_text: bool = True,
|
| 24 |
+
tools_registry=ToolsRegistry,
|
| 25 |
+
**kwargs,
|
| 26 |
+
):
|
| 27 |
+
self.client_kwargs = {**(client_kwargs or {}), "host": host, "timeout": timeout}
|
| 28 |
+
self.client = Client(**self.client_kwargs)
|
| 29 |
+
self.tools_registry = tools_registry
|
| 30 |
+
super().__init__(
|
| 31 |
+
model_id=model_id,
|
| 32 |
+
custom_role_conversions=custom_role_conversions,
|
| 33 |
+
client=self.client,
|
| 34 |
+
flatten_messages_as_text=flatten_messages_as_text,
|
| 35 |
+
**kwargs,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
def _get_clean_message_list(
|
| 39 |
+
self,
|
| 40 |
+
message_list: list[dict[str, str | list[dict]]],
|
| 41 |
+
role_conversions: dict[MessageRole, MessageRole] | dict[str, str] = {},
|
| 42 |
+
convert_images_to_image_urls: bool = False,
|
| 43 |
+
flatten_messages_as_text: bool = False,
|
| 44 |
+
) -> list[OllamaMessage]:
|
| 45 |
+
"""
|
| 46 |
+
Subsequent messages with the same role will be concatenated to a single message.
|
| 47 |
+
output_message_list is a list of messages that will be used to generate the final message that is chat template compatible with transformers LLM chat template.
|
| 48 |
+
|
| 49 |
+
Args:
|
| 50 |
+
message_list (`list[dict[str, str]]`): List of chat messages.
|
| 51 |
+
role_conversions (`dict[MessageRole, MessageRole]`, *optional* ): Mapping to convert roles.
|
| 52 |
+
convert_images_to_image_urls (`bool`, default `False`): Whether to convert images to image URLs.
|
| 53 |
+
flatten_messages_as_text (`bool`, default `False`): Whether to flatten messages as text.
|
| 54 |
+
"""
|
| 55 |
+
output_message_list: list[dict[str, str | list[dict]]] = []
|
| 56 |
+
message_list = deepcopy(message_list) # Avoid modifying the original list
|
| 57 |
+
for message in message_list:
|
| 58 |
+
role = message["role"]
|
| 59 |
+
if role not in MessageRole.roles():
|
| 60 |
+
raise ValueError(
|
| 61 |
+
f"Incorrect role {role}, only {MessageRole.roles()} are supported for now."
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
if role in role_conversions:
|
| 65 |
+
message["role"] = role_conversions[role] # type: ignore
|
| 66 |
+
# encode images if needed
|
| 67 |
+
if isinstance(message["content"], list):
|
| 68 |
+
for element in message["content"]:
|
| 69 |
+
assert isinstance(
|
| 70 |
+
element, dict
|
| 71 |
+
), "Error: this element should be a dict:" + str(element)
|
| 72 |
+
if element["type"] == "image":
|
| 73 |
+
assert (
|
| 74 |
+
not flatten_messages_as_text
|
| 75 |
+
), f"Cannot use images with {flatten_messages_as_text=}"
|
| 76 |
+
if convert_images_to_image_urls:
|
| 77 |
+
element.update(
|
| 78 |
+
{
|
| 79 |
+
"type": "image_url",
|
| 80 |
+
"image_url": {
|
| 81 |
+
"url": make_image_url(
|
| 82 |
+
encode_image_base64(element.pop("image"))
|
| 83 |
+
)
|
| 84 |
+
},
|
| 85 |
+
}
|
| 86 |
+
)
|
| 87 |
+
else:
|
| 88 |
+
element["image"] = encode_image_base64(element["image"])
|
| 89 |
+
|
| 90 |
+
if (
|
| 91 |
+
len(output_message_list) > 0
|
| 92 |
+
and message["role"] == output_message_list[-1]["role"]
|
| 93 |
+
):
|
| 94 |
+
assert isinstance(
|
| 95 |
+
message["content"], list
|
| 96 |
+
), "Error: wrong content:" + str(message["content"])
|
| 97 |
+
if flatten_messages_as_text:
|
| 98 |
+
output_message_list[-1]["content"] += (
|
| 99 |
+
"\n" + message["content"][0]["text"]
|
| 100 |
+
)
|
| 101 |
+
else:
|
| 102 |
+
for el in message["content"]:
|
| 103 |
+
if (
|
| 104 |
+
el["type"] == "text"
|
| 105 |
+
and output_message_list[-1]["content"][-1]["type"] == "text"
|
| 106 |
+
):
|
| 107 |
+
# Merge consecutive text messages rather than creating new ones
|
| 108 |
+
output_message_list[-1]["content"][-1]["text"] += (
|
| 109 |
+
"\n" + el["text"]
|
| 110 |
+
)
|
| 111 |
+
else:
|
| 112 |
+
output_message_list[-1]["content"].append(el)
|
| 113 |
+
else:
|
| 114 |
+
if flatten_messages_as_text:
|
| 115 |
+
content = message["content"][0]["text"]
|
| 116 |
+
else:
|
| 117 |
+
content = message["content"]
|
| 118 |
+
output_message_list.append(
|
| 119 |
+
OllamaMessage(role=message["role"], content=content)
|
| 120 |
+
)
|
| 121 |
+
return output_message_list
|
| 122 |
+
|
| 123 |
+
def _prepare_completion_kwargs(
|
| 124 |
+
self,
|
| 125 |
+
messages: list[dict[str, str | list[dict]]],
|
| 126 |
+
stop_sequences: list[str] | None = None,
|
| 127 |
+
grammar: str | None = None,
|
| 128 |
+
tools_to_call_from: list[Tool] | None = None,
|
| 129 |
+
custom_role_conversions: dict[str, str] | None = None,
|
| 130 |
+
convert_images_to_image_urls: bool = False,
|
| 131 |
+
stream: bool = True,
|
| 132 |
+
keep_alive: float | str | None = None,
|
| 133 |
+
**kwargs,
|
| 134 |
+
) -> dict[str, Any]:
|
| 135 |
+
"""
|
| 136 |
+
Prepare parameters required for model invocation, handling parameter priorities.
|
| 137 |
+
|
| 138 |
+
Parameter priority from high to low:
|
| 139 |
+
1. Explicitly passed kwargs
|
| 140 |
+
2. Specific parameters (stop_sequences, grammar, etc.)
|
| 141 |
+
3. Default values in self.kwargs
|
| 142 |
+
"""
|
| 143 |
+
# Clean and standardize the message list
|
| 144 |
+
flatten_messages_as_text = kwargs.pop(
|
| 145 |
+
"flatten_messages_as_text", self.flatten_messages_as_text
|
| 146 |
+
)
|
| 147 |
+
messages = self._get_clean_message_list(
|
| 148 |
+
messages,
|
| 149 |
+
role_conversions=custom_role_conversions or tool_role_conversions,
|
| 150 |
+
convert_images_to_image_urls=convert_images_to_image_urls,
|
| 151 |
+
flatten_messages_as_text=flatten_messages_as_text,
|
| 152 |
+
)
|
| 153 |
+
generation_options = {"num_ctx": DEFAULT_NUM_CTX}
|
| 154 |
+
# Use self.kwargs as the base configuration
|
| 155 |
+
completion_kwargs = {
|
| 156 |
+
**self.kwargs,
|
| 157 |
+
"messages": messages,
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
# Handle specific parameters
|
| 161 |
+
if stop_sequences is not None:
|
| 162 |
+
# Some models do not support stop parameter
|
| 163 |
+
if supports_stop_parameter(self.model_id or ""):
|
| 164 |
+
generation_options["stop"] = stop_sequences
|
| 165 |
+
|
| 166 |
+
# Define Ollama's parameters
|
| 167 |
+
completion_kwargs["model"] = self.model_id
|
| 168 |
+
if tools_to_call_from:
|
| 169 |
+
completion_kwargs["tools"] = [
|
| 170 |
+
self.tools_registry.get_all_tools()[tool.name]
|
| 171 |
+
for tool in tools_to_call_from
|
| 172 |
+
]
|
| 173 |
+
else:
|
| 174 |
+
completion_kwargs["tools"] = None
|
| 175 |
+
completion_kwargs["stream"] = stream
|
| 176 |
+
if grammar is not None:
|
| 177 |
+
completion_kwargs["format"] = grammar
|
| 178 |
+
else:
|
| 179 |
+
completion_kwargs["format"] = None
|
| 180 |
+
|
| 181 |
+
completion_kwargs["options"] = generation_options
|
| 182 |
+
completion_kwargs["keep_alive"] = keep_alive
|
| 183 |
+
|
| 184 |
+
# Finally, use the passed-in kwargs to override all settings
|
| 185 |
+
completion_kwargs.update(kwargs)
|
| 186 |
+
|
| 187 |
+
return completion_kwargs
|
| 188 |
+
|
| 189 |
+
def generate(
|
| 190 |
+
self,
|
| 191 |
+
messages: list[dict[str, str | list[dict]]],
|
| 192 |
+
stop_sequences: list[str] | None = None,
|
| 193 |
+
grammar: str | None = None,
|
| 194 |
+
tools_to_call_from: list[Tool] | None = None,
|
| 195 |
+
**kwargs,
|
| 196 |
+
) -> ChatMessage:
|
| 197 |
+
completion_kwargs = self._prepare_completion_kwargs(
|
| 198 |
+
messages=messages,
|
| 199 |
+
stop_sequences=stop_sequences,
|
| 200 |
+
grammar=grammar,
|
| 201 |
+
tools_to_call_from=tools_to_call_from,
|
| 202 |
+
convert_images_to_image_urls=True,
|
| 203 |
+
custom_role_conversions=self.custom_role_conversions,
|
| 204 |
+
stream=False,
|
| 205 |
+
**kwargs,
|
| 206 |
+
)
|
| 207 |
+
response = self.client.chat(**completion_kwargs)
|
| 208 |
+
|
| 209 |
+
self.last_input_token_count = response.prompt_eval_count
|
| 210 |
+
self.last_output_token_count = response.eval_count
|
| 211 |
+
|
| 212 |
+
response_json_dumped = response.message.model_dump()
|
| 213 |
+
|
| 214 |
+
if response_json_dumped["tool_calls"]:
|
| 215 |
+
for tool_call_id, tool_call in enumerate(
|
| 216 |
+
response_json_dumped["tool_calls"]
|
| 217 |
+
):
|
| 218 |
+
tool_call["type"] = "function"
|
| 219 |
+
tool_call["id"] = tool_call_id
|
| 220 |
+
|
| 221 |
+
return ChatMessage.from_dict(response_json_dumped, raw=None)
|
src/tools_registry.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Callable
|
| 2 |
+
from functools import wraps
|
| 3 |
+
import inspect
|
| 4 |
+
|
| 5 |
+
import smolagents.default_tools
|
| 6 |
+
from smolagents._function_type_hints_utils import get_json_schema
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
SMOLAGENT_DEFAULT_TOOLS_OLLAMA_MAPPING = {
|
| 10 |
+
smolagent_tool.name: {
|
| 11 |
+
"type": "function",
|
| 12 |
+
"function": {
|
| 13 |
+
"name": smolagent_tool.name,
|
| 14 |
+
"description": smolagent_tool.description,
|
| 15 |
+
"parameters": {"type": "object", "properties": smolagent_tool.inputs},
|
| 16 |
+
"required": list(smolagent_tool.inputs.keys()),
|
| 17 |
+
},
|
| 18 |
+
}
|
| 19 |
+
for smolagent_tool in [
|
| 20 |
+
class_element
|
| 21 |
+
for _, class_element in inspect.getmembers(
|
| 22 |
+
smolagents.default_tools, inspect.isclass
|
| 23 |
+
)
|
| 24 |
+
if ("Tool" in str(class_element)) and (getattr(class_element, "name", None))
|
| 25 |
+
]
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class ToolsRegistry:
|
| 30 |
+
_tools: dict[str, Any] = SMOLAGENT_DEFAULT_TOOLS_OLLAMA_MAPPING
|
| 31 |
+
|
| 32 |
+
@classmethod
|
| 33 |
+
def register(cls):
|
| 34 |
+
def decorator(func: Callable):
|
| 35 |
+
cls._tools.update({func.__name__: get_json_schema(func)})
|
| 36 |
+
|
| 37 |
+
@wraps(func)
|
| 38 |
+
def wrapper(*args, **kwargs):
|
| 39 |
+
return func(*args, **kwargs)
|
| 40 |
+
|
| 41 |
+
return wrapper
|
| 42 |
+
|
| 43 |
+
return decorator
|
| 44 |
+
|
| 45 |
+
@classmethod
|
| 46 |
+
def get_all_tools(cls) -> list[dict[str, Any]]:
|
| 47 |
+
return cls._tools
|
src/utils.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
API_URL = os.getenv("DEFAULT_API_URL")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def fetch_questions(output_file_path: str | None = None):
|
| 9 |
+
QUESTIONS_URL = f"{API_URL}/questions"
|
| 10 |
+
|
| 11 |
+
print(f"Fetching questions from: {QUESTIONS_URL}")
|
| 12 |
+
try:
|
| 13 |
+
response = requests.get(QUESTIONS_URL, timeout=15)
|
| 14 |
+
response.raise_for_status()
|
| 15 |
+
questions_data = response.json()
|
| 16 |
+
if not questions_data:
|
| 17 |
+
print("Fetched questions list is empty.")
|
| 18 |
+
return "Fetched questions list is empty or invalid format.", None
|
| 19 |
+
print(f"Fetched {len(questions_data)} questions.")
|
| 20 |
+
except Exception as e:
|
| 21 |
+
raise e
|
| 22 |
+
|
| 23 |
+
if output_file_path:
|
| 24 |
+
output_dir_path = os.path.dirname(output_file_path)
|
| 25 |
+
|
| 26 |
+
if not os.path.exists(output_dir_path):
|
| 27 |
+
os.makedirs(output_dir_path, exist_ok=True)
|
| 28 |
+
|
| 29 |
+
with open(output_file_path, "w") as output_file:
|
| 30 |
+
json.dump(
|
| 31 |
+
questions_data,
|
| 32 |
+
output_file,
|
| 33 |
+
indent=4,
|
| 34 |
+
ensure_ascii=False,
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
return questions_data
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def download_questions_files(
|
| 41 |
+
questions: list[dict[str, str]], output_folder: str = "./data/assets"
|
| 42 |
+
):
|
| 43 |
+
"""Download files associated with each question and save them locally."""
|
| 44 |
+
# Implement your logic to check if the question files exist here.
|
| 45 |
+
FILES_URL = f"{API_URL}/files"
|
| 46 |
+
|
| 47 |
+
if not os.path.exists(output_folder):
|
| 48 |
+
os.makedirs(output_folder, exist_ok=True)
|
| 49 |
+
|
| 50 |
+
for question in questions:
|
| 51 |
+
if file_name := question.get("file_name"):
|
| 52 |
+
task_id = question.get("task_id")
|
| 53 |
+
file_url = f"{FILES_URL}/{task_id}"
|
| 54 |
+
print(f"Downloading file associated with task_id {task_id}...")
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
response = requests.get(file_url, timeout=15)
|
| 58 |
+
response.raise_for_status()
|
| 59 |
+
|
| 60 |
+
with open(f"{output_folder}/{file_name}", "wb") as file:
|
| 61 |
+
file.write(response.content)
|
| 62 |
+
|
| 63 |
+
print(f"File downloaded successfully for task_id: {task_id}")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
raise e
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|