wt002 commited on
Commit
c762e0c
·
verified ·
1 Parent(s): 976daf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -18
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 QwenChatTool(Tool):
34
- name = "qwen_chat_tool"
35
- description = "Solves reasoning/code questions using Qwen1.5-7B-Chat"
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 = "Qwen/Qwen1.5-7B-Chat"
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
- # Existing tools
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
- # New Llama Tool
289
- qwen_chat_tool = QwenChatTool()
290
-
291
- system_prompt = f"""
292
- You are my general AI assistant. Your task is to answer the question I asked.
293
- First, provide an explanation of your reasoning, step by step, to arrive at the answer.
294
- Then, return your final answer in a single line, formatted as follows: "FINAL ANSWER: [YOUR FINAL ANSWER]".
295
- [YOUR FINAL ANSWER] should be a number, a string, or a comma-separated list of numbers and/or strings, depending on the question.
296
- If the answer is a number, do not use commas or units (e.g., $, %) unless specified.
297
- If the answer is a string, do not use articles or abbreviations (e.g., for cities), and write digits in plain text unless specified.
298
- If the answer is a comma-separated list, apply the above rules for each element based on whether it is a number or a string.
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
- qwen_chat_tool # 🔧 Add here
 
 
 
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
  )