Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,9 +30,9 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
30 |
from smolagents import Tool, CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel
|
31 |
|
32 |
|
33 |
-
class
|
34 |
-
name = "
|
35 |
-
description = "Solves reasoning/code questions using
|
36 |
|
37 |
inputs = {
|
38 |
"question": {
|
@@ -43,7 +43,7 @@ class QwenChatTool(Tool):
|
|
43 |
output_type = "string"
|
44 |
|
45 |
def __init__(self):
|
46 |
-
self.model_id = "
|
47 |
token = os.getenv("HF_TOKEN")
|
48 |
|
49 |
self.tokenizer = AutoTokenizer.from_pretrained(self.model_id, token=token)
|
@@ -113,6 +113,14 @@ Answer:"""
|
|
113 |
return f"Error executing code:\n{traceback.format_exc()}"
|
114 |
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
#from smolagents import Tool
|
117 |
#from langchain_community.document_loaders import WikipediaLoader
|
118 |
|
@@ -270,12 +278,13 @@ class VideoTranscriptionTool(Tool):
|
|
270 |
class BasicAgent:
|
271 |
def __init__(self):
|
272 |
token = os.environ.get("HF_API_TOKEN")
|
|
|
273 |
model = HfApiModel(
|
274 |
temperature=0.1,
|
275 |
token=token
|
276 |
)
|
277 |
|
278 |
-
#
|
279 |
search_tool = DuckDuckGoSearchTool()
|
280 |
wiki_search_tool = WikiSearchTool()
|
281 |
str_reverse_tool = StringReverseTool()
|
@@ -284,20 +293,21 @@ class BasicAgent:
|
|
284 |
visit_webpage_tool = VisitWebpageTool()
|
285 |
final_answer_tool = FinalAnswerTool()
|
286 |
video_transcription_tool = VideoTranscriptionTool()
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
"""
|
300 |
|
|
|
301 |
self.agent = CodeAgent(
|
302 |
model=model,
|
303 |
tools=[
|
@@ -305,7 +315,10 @@ If the answer is a comma-separated list, apply the above rules for each element
|
|
305 |
keywords_extract_tool, speech_to_text_tool,
|
306 |
visit_webpage_tool, final_answer_tool,
|
307 |
parse_excel_to_json, video_transcription_tool,
|
308 |
-
|
|
|
|
|
|
|
309 |
],
|
310 |
add_base_tools=True
|
311 |
)
|
|
|
30 |
from smolagents import Tool, CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel
|
31 |
|
32 |
|
33 |
+
class CodeLlamaTool(Tool):
|
34 |
+
name = "code_llama_tool"
|
35 |
+
description = "Solves reasoning/code questions using Meta Code Llama 7B Instruct"
|
36 |
|
37 |
inputs = {
|
38 |
"question": {
|
|
|
43 |
output_type = "string"
|
44 |
|
45 |
def __init__(self):
|
46 |
+
self.model_id = "codellama/CodeLlama-7b-Instruct-hf"
|
47 |
token = os.getenv("HF_TOKEN")
|
48 |
|
49 |
self.tokenizer = AutoTokenizer.from_pretrained(self.model_id, token=token)
|
|
|
113 |
return f"Error executing code:\n{traceback.format_exc()}"
|
114 |
|
115 |
|
116 |
+
from transformers.tools import (
|
117 |
+
DocumentQuestionAnsweringTool,
|
118 |
+
ImageQuestionAnsweringTool,
|
119 |
+
TranslationTool,
|
120 |
+
PythonInterpreterTool
|
121 |
+
)
|
122 |
+
|
123 |
+
|
124 |
#from smolagents import Tool
|
125 |
#from langchain_community.document_loaders import WikipediaLoader
|
126 |
|
|
|
278 |
class BasicAgent:
|
279 |
def __init__(self):
|
280 |
token = os.environ.get("HF_API_TOKEN")
|
281 |
+
|
282 |
model = HfApiModel(
|
283 |
temperature=0.1,
|
284 |
token=token
|
285 |
)
|
286 |
|
287 |
+
# Your other tools
|
288 |
search_tool = DuckDuckGoSearchTool()
|
289 |
wiki_search_tool = WikiSearchTool()
|
290 |
str_reverse_tool = StringReverseTool()
|
|
|
293 |
visit_webpage_tool = VisitWebpageTool()
|
294 |
final_answer_tool = FinalAnswerTool()
|
295 |
video_transcription_tool = VideoTranscriptionTool()
|
296 |
+
code_llama_tool = CodeLlamaTool()
|
297 |
+
arxiv_search_tool = ArxivSearchTool()
|
298 |
+
|
299 |
+
# ✅ Add Hugging Face default tools
|
300 |
+
doc_qa_tool = DocumentQuestionAnsweringTool()
|
301 |
+
image_qa_tool = ImageQuestionAnsweringTool()
|
302 |
+
translation_tool = TranslationTool()
|
303 |
+
python_tool = PythonInterpreterTool()
|
304 |
+
|
305 |
+
system_prompt = """You are my general AI assistant...
|
306 |
+
Always return your final result in the format:
|
307 |
+
"FINAL ANSWER: [your short answer here]"
|
308 |
"""
|
309 |
|
310 |
+
|
311 |
self.agent = CodeAgent(
|
312 |
model=model,
|
313 |
tools=[
|
|
|
315 |
keywords_extract_tool, speech_to_text_tool,
|
316 |
visit_webpage_tool, final_answer_tool,
|
317 |
parse_excel_to_json, video_transcription_tool,
|
318 |
+
arxiv_search_tool,
|
319 |
+
doc_qa_tool, image_qa_tool,
|
320 |
+
translation_tool, python_tool
|
321 |
+
code_llama_tool # 🔧 Add here
|
322 |
],
|
323 |
add_base_tools=True
|
324 |
)
|