Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,68 +17,41 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
17 |
SYSTEM_PROMPT = """You are an agent solving the GAIA benchmark and you are required to provide exact answers.
|
18 |
Rules to follow:
|
19 |
1. Return only the exact requested answer: no explanation and no reasoning.
|
20 |
-
2. For yes/no questions, return exactly "Yes" or "No".
|
21 |
3. For dates, use the exact format requested.
|
22 |
4. For numbers, use the exact number, no other format.
|
23 |
5. For names, use the exact name as found in sources.
|
24 |
6. If the question has an associated file, process it accordingly.
|
25 |
Examples of good responses:
|
26 |
-
- "42"
|
27 |
-
- "Yes"
|
28 |
-
- "October 5, 2001"
|
29 |
-
- "Buenos Aires"
|
30 |
-
Never include phrases like "the answer is
|
31 |
Only return the exact answer."""
|
32 |
|
33 |
# Define agent tools
|
34 |
audio_tool = AudioTranscriptionTool()
|
35 |
image_tool = ImageAnalysisTool()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
name = "wikipedia_search"
|
39 |
-
description = "Search for facts using Wikipedia."
|
40 |
-
inputs = {
|
41 |
-
"query": {"type": "string", "description": "Search query"}
|
42 |
-
}
|
43 |
-
output_type = "string"
|
44 |
-
|
45 |
-
def forward(self, query: str) -> str:
|
46 |
-
return WikipediaSearcher().search(query)
|
47 |
-
|
48 |
-
wiki_tool = WikipediaTool()
|
49 |
-
|
50 |
-
tools = [audio_tool, image_tool, wiki_tool]
|
51 |
-
|
52 |
-
# Define the custom agent using Mixtral on Hugging Face
|
53 |
-
#class MyAgent(CodeAgent):
|
54 |
-
# def __init__(self):
|
55 |
-
# model = HfApiModel(
|
56 |
-
# api_url="https://api-inference.huggingface.com/models/mistralai/Mixtral-8x7B-Instruct-v0.1",
|
57 |
-
# api_key=os.getenv("HF_API_TOKEN")
|
58 |
-
# )
|
59 |
-
# super().__init__(model=model, tools=tools, system_prompt=SYSTEM_PROMPT)
|
60 |
-
|
61 |
-
api_key = os.getenv("HF_API_TOKEN", "").strip()
|
62 |
-
|
63 |
|
|
|
64 |
class MyAgent(CodeAgent):
|
65 |
def __init__(self):
|
66 |
model = HfApiModel(
|
67 |
-
model="
|
68 |
-
api_key=
|
69 |
)
|
70 |
super().__init__(model=model, tools=tools)
|
71 |
|
72 |
-
def __call__(self, question_dict):
|
73 |
-
question = question_dict.get("question", "")
|
74 |
-
full_prompt = SYSTEM_PROMPT + "\n\n" + question
|
75 |
-
new_input = question_dict.copy()
|
76 |
-
new_input["question"] = full_prompt
|
77 |
-
return super().__call__(new_input)
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
# Evaluation + Submission function
|
83 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
84 |
space_id = os.getenv("SPACE_ID")
|
|
|
17 |
SYSTEM_PROMPT = """You are an agent solving the GAIA benchmark and you are required to provide exact answers.
|
18 |
Rules to follow:
|
19 |
1. Return only the exact requested answer: no explanation and no reasoning.
|
20 |
+
2. For yes/no questions, return exactly \"Yes\" or \"No\".
|
21 |
3. For dates, use the exact format requested.
|
22 |
4. For numbers, use the exact number, no other format.
|
23 |
5. For names, use the exact name as found in sources.
|
24 |
6. If the question has an associated file, process it accordingly.
|
25 |
Examples of good responses:
|
26 |
+
- \"42\"
|
27 |
+
- \"Yes\"
|
28 |
+
- \"October 5, 2001\"
|
29 |
+
- \"Buenos Aires\"
|
30 |
+
Never include phrases like \"the answer is...\" or \"Based on my research\".
|
31 |
Only return the exact answer."""
|
32 |
|
33 |
# Define agent tools
|
34 |
audio_tool = AudioTranscriptionTool()
|
35 |
image_tool = ImageAnalysisTool()
|
36 |
+
wikipedia_tool = Tool.from_function(
|
37 |
+
name="wikipedia_search",
|
38 |
+
description="Search for facts using Wikipedia.",
|
39 |
+
input_schema={"query": {"type": "string", "description": "Search query"}},
|
40 |
+
output_type="string",
|
41 |
+
forward=lambda query: WikipediaSearcher().search(query)
|
42 |
+
)
|
43 |
|
44 |
+
tools = [audio_tool, image_tool, wikipedia_tool]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
# Define the custom agent using Dolphin model (free Mixtral)
|
47 |
class MyAgent(CodeAgent):
|
48 |
def __init__(self):
|
49 |
model = HfApiModel(
|
50 |
+
model="cognitivecomputations/dolphin-2.6-mixtral-8x7b",
|
51 |
+
api_key=os.getenv("HF_API_TOKEN", "").strip()
|
52 |
)
|
53 |
super().__init__(model=model, tools=tools)
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
# Evaluation + Submission function
|
56 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
57 |
space_id = os.getenv("SPACE_ID")
|