Saptadip Sarkar
commited on
Commit
·
5164dc5
1
Parent(s):
2309b3d
fix: added tools
Browse files- agent_course_tools.py +16 -0
- app.py +13 -0
- requirements.txt +5 -1
agent_course_tools.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from llama_index.tools.wikipedia import WikipediaToolSpec
|
2 |
+
from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
|
3 |
+
from llama_index.core.tools.tool_spec.load_and_search import (
|
4 |
+
LoadAndSearchToolSpec,
|
5 |
+
)
|
6 |
+
|
7 |
+
wiki_spec = WikipediaToolSpec()
|
8 |
+
wiki_tool = LoadAndSearchToolSpec.from_defaults(wiki_spec.to_tool_list()[1]).to_tool_list()
|
9 |
+
|
10 |
+
ddgo_spec = DuckDuckGoSearchToolSpec()
|
11 |
+
ddgo_tool = LoadAndSearchToolSpec.from_defaults(ddgo_spec.to_tool_list()[1]).to_tool_list()
|
12 |
+
|
13 |
+
# Create the Agent with load/search tools
|
14 |
+
#agent = OpenAIAgent.from_tools(
|
15 |
+
# LoadAndSearchToolSpec.from_defaults(wiki_tool).to_tool_list(), verbose=True
|
16 |
+
#)
|
app.py
CHANGED
@@ -3,6 +3,10 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
@@ -13,6 +17,15 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
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."
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from llama_index.core.agent.workflow import AgentWorkflow
|
7 |
+
from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
|
8 |
+
#from llama_index.core.tools.tool_spec.load_and_search import LoadAndSearchToolSpec
|
9 |
+
import agent_course_tools as tools
|
10 |
|
11 |
# (Keep Constants as is)
|
12 |
# --- Constants ---
|
|
|
17 |
class BasicAgent:
|
18 |
def __init__(self):
|
19 |
print("BasicAgent initialized.")
|
20 |
+
llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
|
21 |
+
agent = AgentWorkflow.from_tools_or_functions([
|
22 |
+
tools.wiki_tool,
|
23 |
+
tools.ddgo_tool
|
24 |
+
],
|
25 |
+
llm=llm,
|
26 |
+
system_prompt="You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. 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. 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.",
|
27 |
+
)
|
28 |
+
|
29 |
def __call__(self, question: str) -> str:
|
30 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
31 |
fixed_answer = "This is a default answer."
|
requirements.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1 |
gradio
|
2 |
requests
|
3 |
-
llama-index
|
|
|
|
|
|
|
|
|
|
1 |
gradio
|
2 |
requests
|
3 |
+
llama-index
|
4 |
+
llama-index-tools-wikipedia
|
5 |
+
llama-index-llms-litellm
|
6 |
+
llama-index-readers-file
|
7 |
+
llama-index-tools-duckduckgo
|