Romain Fayoux
commited on
Commit
·
b6aed9a
1
Parent(s):
b284752
Skipped video analysis, gave same tools to llm only agent that multi
Browse filesagents had, changed model and model provider as together was too
expensive
- app.py +7 -2
- llm_only_agent.py +35 -13
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
import json
|
|
|
|
| 6 |
from phoenix.otel import register
|
| 7 |
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
| 8 |
from llm_only_agent import LLMOnlyAgent
|
|
@@ -90,10 +91,11 @@ def run_and_submit_all(profile: gr.OAuthProfile | None, limit: int | None):
|
|
| 90 |
results_log = []
|
| 91 |
answers_payload = []
|
| 92 |
# Limit for test purposes
|
| 93 |
-
limit =
|
| 94 |
if limit is not None:
|
| 95 |
questions_data = questions_data[:limit]
|
| 96 |
-
|
|
|
|
| 97 |
for item in questions_data:
|
| 98 |
task_id = item.get("task_id")
|
| 99 |
file_name = item.get("file_name")
|
|
@@ -109,6 +111,9 @@ def run_and_submit_all(profile: gr.OAuthProfile | None, limit: int | None):
|
|
| 109 |
if not task_id or question_text is None:
|
| 110 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 111 |
continue
|
|
|
|
|
|
|
|
|
|
| 112 |
try:
|
| 113 |
submitted_answer = agent(question_text)
|
| 114 |
answers_payload.append(
|
|
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
import json
|
| 6 |
+
import re
|
| 7 |
from phoenix.otel import register
|
| 8 |
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
| 9 |
from llm_only_agent import LLMOnlyAgent
|
|
|
|
| 91 |
results_log = []
|
| 92 |
answers_payload = []
|
| 93 |
# Limit for test purposes
|
| 94 |
+
limit = None
|
| 95 |
if limit is not None:
|
| 96 |
questions_data = questions_data[:limit]
|
| 97 |
+
# Run agents on questions fetched
|
| 98 |
+
print(f"Running agents on {len(questions_data)} questions...")
|
| 99 |
for item in questions_data:
|
| 100 |
task_id = item.get("task_id")
|
| 101 |
file_name = item.get("file_name")
|
|
|
|
| 111 |
if not task_id or question_text is None:
|
| 112 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 113 |
continue
|
| 114 |
+
if re.search("youtube", question_text, re.IGNORECASE):
|
| 115 |
+
print(f"Skipping item with youtube link: {item}")
|
| 116 |
+
continue
|
| 117 |
try:
|
| 118 |
submitted_answer = agent(question_text)
|
| 119 |
answers_payload.append(
|
llm_only_agent.py
CHANGED
|
@@ -1,12 +1,18 @@
|
|
| 1 |
import re
|
| 2 |
-
from smolagents import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from collections.abc import Callable
|
| 4 |
|
| 5 |
from smolagents.default_tools import VisitWebpageTool, WikipediaSearchTool
|
| 6 |
|
|
|
|
| 7 |
class LLMOnlyAgent:
|
| 8 |
def __init__(self):
|
| 9 |
-
|
| 10 |
# Instructions prompt
|
| 11 |
self.instructions = """finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 12 |
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
|
@@ -14,23 +20,34 @@ class LLMOnlyAgent:
|
|
| 14 |
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.
|
| 15 |
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."""
|
| 16 |
|
| 17 |
-
|
| 18 |
# Basic inference model
|
| 19 |
model = InferenceClientModel(
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
# Code Agent
|
| 26 |
self.agent = CodeAgent(
|
| 27 |
model=model,
|
| 28 |
instructions=self.instructions,
|
| 29 |
-
tools=[
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
max_steps=5,
|
| 32 |
-
planning_interval=3
|
| 33 |
-
#final_answer_checks=self.final_answer_checks()
|
| 34 |
)
|
| 35 |
|
| 36 |
print("LLM-only Agent initialized.")
|
|
@@ -41,10 +58,15 @@ class LLMOnlyAgent:
|
|
| 41 |
print(f"Agent returning answer: {answer}")
|
| 42 |
return answer
|
| 43 |
|
| 44 |
-
def final_answer_checks(self) -> list[Callable]
|
| 45 |
-
return [
|
| 46 |
|
| 47 |
def check_func(self, answer: str, memory: AgentMemory) -> bool:
|
| 48 |
-
check = bool(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
print(f"FINAL ANSWER CHECK is {check}")
|
| 50 |
return check
|
|
|
|
| 1 |
import re
|
| 2 |
+
from smolagents import (
|
| 3 |
+
AgentMemory,
|
| 4 |
+
CodeAgent,
|
| 5 |
+
InferenceClientModel,
|
| 6 |
+
FinalAnswerTool,
|
| 7 |
+
WebSearchTool,
|
| 8 |
+
)
|
| 9 |
from collections.abc import Callable
|
| 10 |
|
| 11 |
from smolagents.default_tools import VisitWebpageTool, WikipediaSearchTool
|
| 12 |
|
| 13 |
+
|
| 14 |
class LLMOnlyAgent:
|
| 15 |
def __init__(self):
|
|
|
|
| 16 |
# Instructions prompt
|
| 17 |
self.instructions = """finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 18 |
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
|
|
|
| 20 |
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.
|
| 21 |
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."""
|
| 22 |
|
|
|
|
| 23 |
# Basic inference model
|
| 24 |
model = InferenceClientModel(
|
| 25 |
+
max_tokens=8096,
|
| 26 |
+
model_id="Qwen/Qwen3-Coder-30B-A3B-Instruct",
|
| 27 |
+
custom_role_conversions=None,
|
| 28 |
+
provider="nebius",
|
| 29 |
)
|
| 30 |
|
| 31 |
# Code Agent
|
| 32 |
self.agent = CodeAgent(
|
| 33 |
model=model,
|
| 34 |
instructions=self.instructions,
|
| 35 |
+
tools=[
|
| 36 |
+
FinalAnswerTool(),
|
| 37 |
+
WikipediaSearchTool(),
|
| 38 |
+
WebSearchTool(),
|
| 39 |
+
VisitWebpageTool(),
|
| 40 |
+
],
|
| 41 |
+
additional_authorized_imports=[
|
| 42 |
+
"markdownify",
|
| 43 |
+
"requests",
|
| 44 |
+
"pandas",
|
| 45 |
+
"numpy",
|
| 46 |
+
"chess",
|
| 47 |
+
],
|
| 48 |
max_steps=5,
|
| 49 |
+
planning_interval=3,
|
| 50 |
+
# final_answer_checks=self.final_answer_checks()
|
| 51 |
)
|
| 52 |
|
| 53 |
print("LLM-only Agent initialized.")
|
|
|
|
| 58 |
print(f"Agent returning answer: {answer}")
|
| 59 |
return answer
|
| 60 |
|
| 61 |
+
def final_answer_checks(self) -> list[Callable]:
|
| 62 |
+
return [self.check_func]
|
| 63 |
|
| 64 |
def check_func(self, answer: str, memory: AgentMemory) -> bool:
|
| 65 |
+
check = bool(
|
| 66 |
+
re.match(
|
| 67 |
+
r'^(\d+(\.\d+)?|\w+(\s+\w+){0,4}|(\d+(\.\d+)?|"[^"]*"|\w+)(\s*,\s*(\d+(\.\d+)?|"[^"]*"|\w+))+)$',
|
| 68 |
+
answer,
|
| 69 |
+
)
|
| 70 |
+
)
|
| 71 |
print(f"FINAL ANSWER CHECK is {check}")
|
| 72 |
return check
|