rsant commited on
Commit
9041b2d
·
verified ·
1 Parent(s): 5a7efb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -6
app.py CHANGED
@@ -1,7 +1,9 @@
1
  import os
2
  import re
 
3
  import openai
4
  import pathlib
 
5
  import requests
6
  import tempfile
7
  import gradio as gr
@@ -11,10 +13,17 @@ from pathlib import Path
11
  from tabulate import tabulate
12
  from typing import Union, Optional
13
  from smolagents.tools import PipelineTool, Tool
14
- from smolagents import OpenAIServerModel, DuckDuckGoSearchTool, CodeAgent, WikipediaSearchTool, PythonInterpreterTool
15
 
16
 
17
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
 
 
 
 
 
 
18
 
19
  #-------------------------------------------------
20
  # TOOLS
@@ -132,17 +141,45 @@ class ExcelToTextTool(Tool):
132
  #-------------------------------------------------
133
  class BasicAgent:
134
  def __init__(self):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  self.agent = CodeAgent(
136
- model=OpenAIServerModel(model_id="gpt-4o"),
137
  tools=[
138
- DuckDuckGoSearchTool(),
 
 
 
 
 
 
 
 
139
  WikipediaSearchTool(),
140
- PythonInterpreterTool(),
141
  #SpeechToTextTool(),
142
  #ExcelToTextTool()
143
  ],
144
- add_base_tools=True,
145
- additional_authorized_imports=['pandas','numpy','csv','subprocess']
 
 
 
 
 
 
 
146
  )
147
  print("BasicAgent initialized.")
148
  def __call__(self, question: str) -> str:
 
1
  import os
2
  import re
3
+ import yaml
4
  import openai
5
  import pathlib
6
+ import inspect
7
  import requests
8
  import tempfile
9
  import gradio as gr
 
13
  from tabulate import tabulate
14
  from typing import Union, Optional
15
  from smolagents.tools import PipelineTool, Tool
16
+ from smolagents import OpenAIServerModel, DuckDuckGoSearchTool, CodeAgent, WikipediaSearchTool, PythonInterpreterTool, VisitWebpageTool
17
 
18
 
19
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
20
+ SYSTEM_PROMPT = """
21
+ You are a helpful assistant tasked with answering questions using a set of tools.
22
+ Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
23
+ FINAL ANSWER: [YOUR FINAL ANSWER].
24
+ YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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.
25
+ Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
26
+ """
27
 
28
  #-------------------------------------------------
29
  # TOOLS
 
141
  #-------------------------------------------------
142
  class BasicAgent:
143
  def __init__(self):
144
+
145
+ #Define model
146
+ self.model = OpenAIServerModel(
147
+ model_id="gpt-4o-mini",
148
+ api_base="https://api.openai.com/v1",
149
+ api_key=os.getenv("OPENAI_API_KEY")
150
+ ),
151
+
152
+ #Define prompts
153
+ self.prompt_templates = {}
154
+ with open("prompt_templates.yaml", 'r') as stream:
155
+ self.prompt_templates = yaml.safe_load(stream)
156
+
157
+ #Define agent
158
  self.agent = CodeAgent(
159
+ model = self.model,
160
  tools=[
161
+ DuckDuckGoSearchTool(),
162
+ VisitWebpageTool(),
163
+ PythonInterpreterTool(
164
+ authorized_imports=[
165
+ 'pandas',
166
+ 'numpy',
167
+ 're'
168
+ ]
169
+ ),
170
  WikipediaSearchTool(),
 
171
  #SpeechToTextTool(),
172
  #ExcelToTextTool()
173
  ],
174
+ max_steps = 6,
175
+ verbosity_level = 1,
176
+ grammar = None,
177
+ planning_interval = None,
178
+ name = None,
179
+ description = None,
180
+ #add_base_tools = True,
181
+ #prompt_templates=self.prompt_templates,
182
+ additional_authorized_imports=['pandas','numpy','csv','subprocess', 're']
183
  )
184
  print("BasicAgent initialized.")
185
  def __call__(self, question: str) -> str: