add system prompt and tools, still cannot analyze videos somehow
Browse files- .gitignore +2 -0
- agent.py +6 -0
- app.py +36 -5
- requirements.txt +8 -3
.gitignore
CHANGED
@@ -1,3 +1,5 @@
|
|
1 |
.idea/
|
2 |
.venv/
|
|
|
|
|
3 |
|
|
|
1 |
.idea/
|
2 |
.venv/
|
3 |
+
.env
|
4 |
+
|
5 |
|
agent.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
2 |
+
|
3 |
+
|
4 |
+
if __name__ == '__main__':
|
5 |
+
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
|
6 |
+
agent.run("Search for the best music recommendations for a party at the Wayne's mansion.")
|
app.py
CHANGED
@@ -1,23 +1,54 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
-
import inspect
|
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 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
def __init__(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
print("BasicAgent initialized.")
|
16 |
def __call__(self, question: str) -> str:
|
17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import requests
|
|
|
4 |
import pandas as pd
|
5 |
+
from smolagents import DuckDuckGoSearchTool, CodeAgent, VisitWebpageTool, FinalAnswerTool, OpenAIServerModel, \
|
6 |
+
WikipediaSearchTool
|
7 |
+
from dotenv import load_dotenv
|
8 |
# (Keep Constants as is)
|
9 |
# --- Constants ---
|
10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
11 |
|
12 |
+
load_dotenv()
|
13 |
+
|
14 |
# --- Basic Agent Definition ---
|
15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
16 |
class BasicAgent:
|
17 |
def __init__(self):
|
18 |
+
search_tool = DuckDuckGoSearchTool()
|
19 |
+
model = OpenAIServerModel(model_id="gpt-4o", api_key=os.environ["OPENAI_API_KEY"])
|
20 |
+
wiki= WikipediaSearchTool()
|
21 |
+
# model = HfApiModel()
|
22 |
+
visit_webpage = VisitWebpageTool()
|
23 |
+
final_answer = FinalAnswerTool()
|
24 |
+
self.agent = CodeAgent(
|
25 |
+
model=model,
|
26 |
+
tools=[search_tool, visit_webpage, wiki, final_answer],
|
27 |
+
managed_agents=[],
|
28 |
+
max_steps=10,
|
29 |
+
verbosity_level=2,
|
30 |
+
name="My_basic_agent",
|
31 |
+
description="for hf agent course",
|
32 |
+
)
|
33 |
+
SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and
|
34 |
+
finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
35 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated
|
36 |
+
list of numbers and/or strings.
|
37 |
+
If you are asked for a number, don't use comma to write your number neither use units such as $ or
|
38 |
+
percent sign unless specified otherwise.
|
39 |
+
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the
|
40 |
+
digits in plain text unless specified otherwise.
|
41 |
+
If you are asked for a comma separated list, apply the above rules depending of whether the element
|
42 |
+
to be put in the list is a number or a string.
|
43 |
+
"""
|
44 |
+
self.agent.prompt_templates["system_prompt"] = self.agent.prompt_templates["system_prompt"] + SYSTEM_PROMPT
|
45 |
print("BasicAgent initialized.")
|
46 |
def __call__(self, question: str) -> str:
|
47 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
48 |
+
# answer = "This is a default answer."
|
49 |
+
answer = self.agent.run(question)
|
50 |
+
print(f"Agent returning answer: {answer}")
|
51 |
+
return answer
|
52 |
|
53 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
54 |
"""
|
requirements.txt
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
-
gradio
|
2 |
gradio[oauth]
|
3 |
-
requests
|
4 |
-
smolagents
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio~=5.27.0
|
2 |
gradio[oauth]
|
3 |
+
requests~=2.32.3
|
4 |
+
smolagents~=1.14.0
|
5 |
+
smolagents[openai]
|
6 |
+
huggingface_hub
|
7 |
+
wikipedia-api
|
8 |
+
pandas~=2.2.3
|
9 |
+
python-dotenv~=1.1.0
|