Abraham E. Tavarez commited on
Commit ·
edcd6eb
1
Parent(s): 0c83fed
hf tool calling agnt updated with langchain wikipedia tool
Browse files- app.py +4 -3
- agent.py → code_agent.py +0 -16
- hf_tool_calling_agent.py +59 -0
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -3,7 +3,8 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from agent import codeAgent
|
|
|
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
@@ -15,8 +16,8 @@ class BasicAgent:
|
|
| 15 |
def __init__(self):
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
-
return codeAgent.run(question)
|
| 19 |
-
|
| 20 |
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 21 |
# fixed_answer = "This is a default answer."
|
| 22 |
# print(f"Agent returning fixed answer: {fixed_answer}")
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
# from agent import codeAgent
|
| 7 |
+
from hf_tool_calling_agent import toolCallingAgent
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 16 |
def __init__(self):
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
+
# return codeAgent.run(question)
|
| 20 |
+
return toolCallingAgent.run(question)
|
| 21 |
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 22 |
# fixed_answer = "This is a default answer."
|
| 23 |
# print(f"Agent returning fixed answer: {fixed_answer}")
|
agent.py → code_agent.py
RENAMED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import os
|
| 2 |
from smolagents import (
|
| 3 |
HfApiModel,
|
| 4 |
CodeAgent,
|
|
@@ -61,18 +60,3 @@ codeAgent.logger.console.width = 66
|
|
| 61 |
# )
|
| 62 |
# answer = codeAgent.run("search wikipedia for: what the name of the main character of the fast and furious movie")
|
| 63 |
# print(answer)
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
# Tool Calling Agent
|
| 67 |
-
llm = HfApiModel("Qwen/Qwen2.5-72B-Instruct", temperature=0.6)
|
| 68 |
-
|
| 69 |
-
toolCallingAgent = ToolCallingAgent(
|
| 70 |
-
model=model,
|
| 71 |
-
tools=tools,
|
| 72 |
-
max_steps=20,
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
toolCallingAgent.logger.console.width = 66
|
| 76 |
-
|
| 77 |
-
# answer = toolCallingAgent.run(question)
|
| 78 |
-
# print(answer)
|
|
|
|
|
|
|
| 1 |
from smolagents import (
|
| 2 |
HfApiModel,
|
| 3 |
CodeAgent,
|
|
|
|
| 60 |
# )
|
| 61 |
# answer = codeAgent.run("search wikipedia for: what the name of the main character of the fast and furious movie")
|
| 62 |
# print(answer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hf_tool_calling_agent.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import (
|
| 2 |
+
HfApiModel,
|
| 3 |
+
CodeAgent,
|
| 4 |
+
load_tool,
|
| 5 |
+
Tool,
|
| 6 |
+
InferenceClientModel,
|
| 7 |
+
ToolCallingAgent,
|
| 8 |
+
FinalAnswerTool,
|
| 9 |
+
DuckDuckGoSearchTool,
|
| 10 |
+
VisitWebpageTool,
|
| 11 |
+
GoogleSearchTool,
|
| 12 |
+
PythonInterpreterTool,
|
| 13 |
+
)
|
| 14 |
+
import os
|
| 15 |
+
from huggingface_hub import login
|
| 16 |
+
from dotenv import load_dotenv
|
| 17 |
+
from langchain.agents import load_tools
|
| 18 |
+
|
| 19 |
+
load_dotenv()
|
| 20 |
+
login(os.environ["HF_API_KEY"])
|
| 21 |
+
from sample_questions import QUESTIONS
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Tools
|
| 25 |
+
|
| 26 |
+
wikipedia = Tool.from_langchain(load_tools(["wikipedia"])[0])
|
| 27 |
+
|
| 28 |
+
tools = [
|
| 29 |
+
DuckDuckGoSearchTool(),
|
| 30 |
+
VisitWebpageTool(),
|
| 31 |
+
PythonInterpreterTool(),
|
| 32 |
+
FinalAnswerTool(),
|
| 33 |
+
wikipedia,
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
# Model
|
| 37 |
+
# LLM Model
|
| 38 |
+
model = HfApiModel(
|
| 39 |
+
"Qwen/Qwen2.5-72B-Instruct",
|
| 40 |
+
provider="together",
|
| 41 |
+
# max_tokens=40096,
|
| 42 |
+
temperature=0.1,
|
| 43 |
+
# token=get_huggingface_token(),
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Tool Calling Agent
|
| 47 |
+
llm = HfApiModel("Qwen/Qwen2.5-72B-Instruct", temperature=0.6)
|
| 48 |
+
|
| 49 |
+
toolCallingAgent = ToolCallingAgent(
|
| 50 |
+
model=model,
|
| 51 |
+
tools=tools,
|
| 52 |
+
max_steps=20,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
toolCallingAgent.logger.console.width = 66
|
| 56 |
+
|
| 57 |
+
question = QUESTIONS[0]
|
| 58 |
+
answer = toolCallingAgent.run(question)
|
| 59 |
+
print(answer)
|
requirements.txt
CHANGED
|
@@ -6,4 +6,5 @@ duckduckgo-search
|
|
| 6 |
markdownify
|
| 7 |
pandas
|
| 8 |
numpy
|
| 9 |
-
langchain
|
|
|
|
|
|
| 6 |
markdownify
|
| 7 |
pandas
|
| 8 |
numpy
|
| 9 |
+
langchain
|
| 10 |
+
wikipedia
|