kschuette commited on
Commit
4aaf401
·
verified ·
1 Parent(s): e607a92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -34
app.py CHANGED
@@ -3,8 +3,8 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
7
- from tools.final_answer import FinalAnswerTool
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
@@ -21,15 +21,24 @@ class BasicAgent:
21
  print(f"Agent returning fixed answer: {fixed_answer}")
22
  return fixed_answer
23
 
24
- @tool
25
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
26
- #Keep this format for the description / args / args description but feel free to modify the tool
27
- """A tool that does nothing yet
28
- Args:
29
- arg1: the first argument
30
- arg2: the second argument
31
- """
32
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
33
 
34
  def run_and_submit_all( profile: gr.OAuthProfile | None):
35
  """
@@ -52,30 +61,16 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
52
 
53
  # 1. Instantiate Agent ( modify this part to create your agent)
54
  try:
55
- model = HfApiModel(
56
- max_tokens=2096,
57
- temperature=0.5,
58
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
59
- custom_role_conversions=None,
60
- )
61
-
62
- final_answer = FinalAnswerTool()
63
- search_tool = DuckDuckGoSearchTool()
64
 
65
- agent = CodeAgent(
66
- model=model,
67
- tools=[
68
- final_answer,
69
- search_tool,
70
- my_custom_tool,
71
- ],
72
- max_steps=6,
73
- verbosity_level=1,
74
- grammar=None,
75
- planning_interval=None,
76
- name=None,
77
- description=None,
78
- prompt_templates=prompt_templates
79
  )
80
  except Exception as e:
81
  print(f"Error instantiating agent: {e}")
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
7
+ from llama_index.core.agent.workflow import AgentWorkflow, ToolCallResult, AgentStream
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
 
21
  print(f"Agent returning fixed answer: {fixed_answer}")
22
  return fixed_answer
23
 
24
+ def add(a: int, b: int) -> int:
25
+ """Add two numbers"""
26
+ return a + b
27
+
28
+
29
+ def subtract(a: int, b: int) -> int:
30
+ """Subtract two numbers"""
31
+ return a - b
32
+
33
+
34
+ def multiply(a: int, b: int) -> int:
35
+ """Multiply two numbers"""
36
+ return a * b
37
+
38
+
39
+ def divide(a: int, b: int) -> int:
40
+ """Divide two numbers"""
41
+ return a / b
42
 
43
  def run_and_submit_all( profile: gr.OAuthProfile | None):
44
  """
 
61
 
62
  # 1. Instantiate Agent ( modify this part to create your agent)
63
  try:
64
+ llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
 
 
 
 
 
 
 
 
65
 
66
+ agent = AgentWorkflow.from_tools_or_functions(
67
+ tools_or_functions=[subtract, multiply, divide, add],
68
+ llm=llm,
69
+ 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: \
70
+ 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. \
71
+ 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. \
72
+ 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. \
73
+ 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.",
 
 
 
 
 
 
74
  )
75
  except Exception as e:
76
  print(f"Error instantiating agent: {e}")