ORromu commited on
Commit
1736efe
·
verified ·
1 Parent(s): 0936bdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -12
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- from smolagents import CodeAgent, OpenAIServerModel, DuckDuckGoSearchTool, WikipediaSearchTool, MultiStepAgent
7
  from smolagents.agents import PromptTemplates
8
 
9
  GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
@@ -14,13 +14,52 @@ model = OpenAIServerModel(
14
  api_base="https://generativelanguage.googleapis.com/v1beta/openai/"
15
  )
16
 
17
- class CustomMultiStepAgent(MultiStepAgent):
18
- def initialize_system_prompt(self):
19
- # Implement the method as required
20
- pass
21
 
22
- prompt = PromptTemplates(
23
- system_prompt="""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  You are a helpful assistant tasked with answering questions using a set of tools.
25
  {{tool_descriptions}}
26
 
@@ -36,14 +75,14 @@ YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma sepa
36
  Your answer should **only** start with `FINAL ANSWER: ` followed by the answer.
37
  """,
38
 
39
- planning="""
40
  You have received the following task:
41
  {{task_description}}
42
 
43
  Think step-by-step about what tools or steps are needed to solve it. Plan clearly before proceeding.
44
  """,
45
 
46
- managed_agent="""
47
  You are executing the following step:
48
  {{step_description}}
49
 
@@ -53,7 +92,7 @@ Remember to ultimately return the answer in the format:
53
  FINAL ANSWER: [YOUR FINAL ANSWER]
54
  """,
55
 
56
- final_answer="""
57
  You have completed all steps.
58
 
59
  Now, return your final response using the following format:
@@ -61,7 +100,8 @@ FINAL ANSWER: [YOUR FINAL ANSWER]
61
 
62
  YOUR FINAL ANSWER should be a number, a few words, or a comma-separated list, following the formatting rules provided earlier.
63
  """
64
- )
 
65
 
66
  # (Keep Constants as is)
67
  # --- Constants ---
@@ -71,7 +111,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
71
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
72
  class BasicAgent:
73
  def __init__(self):
74
- self.agent = CustomMultiStepAgent(
75
  tools = [DuckDuckGoSearchTool(), WikipediaSearchTool()],
76
  model = model,
77
  add_base_tools=True,
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, OpenAIServerModel, DuckDuckGoSearchTool, WikipediaSearchTool
7
  from smolagents.agents import PromptTemplates
8
 
9
  GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
 
14
  api_base="https://generativelanguage.googleapis.com/v1beta/openai/"
15
  )
16
 
17
+ # prompt = PromptTemplates(
18
+ # system_prompt="""
19
+ # You are a helpful assistant tasked with answering questions using a set of tools.
20
+ # {{tool_descriptions}}
21
 
22
+ # Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
23
+
24
+ # FINAL ANSWER: [YOUR FINAL ANSWER].
25
+
26
+ # YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
27
+ # - If you are asked for a number, don't use commas or units like $ or %, unless explicitly required.
28
+ # - If you are asked for a string, do not include articles or abbreviations, and write digits in full unless otherwise specified.
29
+ # - If asked for a comma-separated list, apply the above rules depending on whether the list elements are numbers or strings.
30
+
31
+ # Your answer should **only** start with `FINAL ANSWER: ` followed by the answer.
32
+ # """,
33
+
34
+ # planning="""
35
+ # You have received the following task:
36
+ # {{task_description}}
37
+
38
+ # Think step-by-step about what tools or steps are needed to solve it. Plan clearly before proceeding.
39
+ # """,
40
+
41
+ # managed_agent="""
42
+ # You are executing the following step:
43
+ # {{step_description}}
44
+
45
+ # Use available tools wisely. Think before acting, and ensure your actions follow the original instruction format.
46
+
47
+ # Remember to ultimately return the answer in the format:
48
+ # FINAL ANSWER: [YOUR FINAL ANSWER]
49
+ # """,
50
+
51
+ # final_answer="""
52
+ # You have completed all steps.
53
+
54
+ # Now, return your final response using the following format:
55
+ # FINAL ANSWER: [YOUR FINAL ANSWER]
56
+
57
+ # YOUR FINAL ANSWER should be a number, a few words, or a comma-separated list, following the formatting rules provided earlier.
58
+ # """
59
+ # )
60
+
61
+ prompt = {
62
+ 'system_prompt':"""
63
  You are a helpful assistant tasked with answering questions using a set of tools.
64
  {{tool_descriptions}}
65
 
 
75
  Your answer should **only** start with `FINAL ANSWER: ` followed by the answer.
76
  """,
77
 
78
+ 'planning':"""
79
  You have received the following task:
80
  {{task_description}}
81
 
82
  Think step-by-step about what tools or steps are needed to solve it. Plan clearly before proceeding.
83
  """,
84
 
85
+ 'managed_agent':"""
86
  You are executing the following step:
87
  {{step_description}}
88
 
 
92
  FINAL ANSWER: [YOUR FINAL ANSWER]
93
  """,
94
 
95
+ 'final_answer':"""
96
  You have completed all steps.
97
 
98
  Now, return your final response using the following format:
 
100
 
101
  YOUR FINAL ANSWER should be a number, a few words, or a comma-separated list, following the formatting rules provided earlier.
102
  """
103
+ }
104
+
105
 
106
  # (Keep Constants as is)
107
  # --- Constants ---
 
111
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
112
  class BasicAgent:
113
  def __init__(self):
114
+ self.agent = CodeAgent(
115
  tools = [DuckDuckGoSearchTool(), WikipediaSearchTool()],
116
  model = model,
117
  add_base_tools=True,