Hans Han
commited on
Commit
·
3fde873
1
Parent(s):
81917a3
added agent
Browse files
app.py
CHANGED
@@ -10,13 +10,36 @@ 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 |
-
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):
|
|
|
10 |
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
+
from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
|
14 |
+
from llama_index.core.tools import FunctionTool
|
15 |
+
from llama_index.core.agent.workflow import AgentWorkflow
|
16 |
+
from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
|
17 |
+
from llama_index.tools.wikipedia import WikipediaToolSpec
|
18 |
+
|
19 |
+
# Initialize the Hugging Face model
|
20 |
+
llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
|
21 |
+
|
22 |
+
# Initialize the DuckDuckGo search tool
|
23 |
+
tool_spec = DuckDuckGoSearchToolSpec()
|
24 |
+
search_tool = FunctionTool.from_defaults(tool_spec.duckduckgo_full_search)
|
25 |
+
# Initialize the wikipedia tool
|
26 |
+
wiki_spec = WikipediaToolSpec()
|
27 |
+
wiki_tools = wiki_spec.to_tool_list()
|
28 |
+
|
29 |
class BasicAgent:
|
30 |
def __init__(self):
|
31 |
print("BasicAgent initialized.")
|
32 |
def __call__(self, question: str) -> str:
|
33 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
34 |
+
# fixed_answer = "This is a default answer."
|
35 |
+
# print(f"Agent returning fixed answer: {fixed_answer}")
|
36 |
+
# Create agent with all the tools
|
37 |
+
agent = AgentWorkflow.from_tools_or_functions(
|
38 |
+
[search_tool] + wiki_tools,
|
39 |
+
llm=llm
|
40 |
+
)
|
41 |
+
# Example query agent might receive during the gala
|
42 |
+
fixed_answer = await agent.run(question)
|
43 |
return fixed_answer
|
44 |
|
45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|