Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
@@ -19,6 +21,16 @@ class BasicAgent:
|
|
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,
|
@@ -40,7 +52,31 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
40 |
|
41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
42 |
try:
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
except Exception as e:
|
45 |
print(f"Error instantiating agent: {e}")
|
46 |
return f"Error initializing agent: {e}", None
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
7 |
+
from tools.final_answer import FinalAnswerTool
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
|
|
21 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
22 |
return fixed_answer
|
23 |
|
24 |
+
@tool
|
25 |
+
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
26 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
27 |
+
"""A tool that does nothing yet
|
28 |
+
Args:
|
29 |
+
arg1: the first argument
|
30 |
+
arg2: the second argument
|
31 |
+
"""
|
32 |
+
return "What magic will you build ?"
|
33 |
+
|
34 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
35 |
"""
|
36 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
52 |
|
53 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
54 |
try:
|
55 |
+
model = HfApiModel(
|
56 |
+
max_tokens=2096,
|
57 |
+
temperature=0.5,
|
58 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
59 |
+
custom_role_conversions=None,
|
60 |
+
)
|
61 |
+
|
62 |
+
final_answer = FinalAnswerTool()
|
63 |
+
search_tool = DuckDuckGoSearchTool()
|
64 |
+
|
65 |
+
agent = CodeAgent(
|
66 |
+
model=model,
|
67 |
+
tools=[
|
68 |
+
final_answer,
|
69 |
+
search_tool,
|
70 |
+
my_custom_tool,
|
71 |
+
],
|
72 |
+
max_steps=6,
|
73 |
+
verbosity_level=1,
|
74 |
+
grammar=None,
|
75 |
+
planning_interval=None,
|
76 |
+
name=None,
|
77 |
+
description=None,
|
78 |
+
prompt_templates=prompt_templates
|
79 |
+
)
|
80 |
except Exception as e:
|
81 |
print(f"Error instantiating agent: {e}")
|
82 |
return f"Error initializing agent: {e}", None
|