Mahdiyar commited on
Commit
d6b7477
·
1 Parent(s): 445de55

Prompt Engineering + Fixing Coding Agent Bugs

Browse files
Files changed (3) hide show
  1. app.py +13 -1
  2. helper.py +14 -1
  3. requirements.txt +1 -1
app.py CHANGED
@@ -37,6 +37,18 @@ def _run_python(code: str,globals_dict:Dict[str,Any]={},locals_dict:Dict[str,Any
37
  updated_globals = globals_dict.copy()
38
  updated_locals = locals_dict.copy()
39
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  tree = ast.parse(code, mode="exec")
41
  compiled = compile(tree, filename="<ast>", mode="exec")
42
  stdout_buf = io.StringIO()
@@ -92,7 +104,7 @@ class PythonCodeInterpreter:
92
  self.default_python_codes = default_python_codes
93
 
94
  self.modal_secrets = modal.Secret.from_dict(modal_secrets)
95
- self.pip_packages = list(set(["cloudpickle","requests","tinyagent-py[all]==0.0.7",
96
  "gradio",
97
  "arize-phoenix-otel",]+pip_packages))
98
  self.lazy_init = lazy_init
 
37
  updated_globals = globals_dict.copy()
38
  updated_locals = locals_dict.copy()
39
 
40
+ # Pre-import essential modules into the global namespace
41
+ # This ensures they're available for imports inside functions
42
+ essential_modules = ['requests', 'json', 'os', 'sys', 'time', 'datetime', 're', 'random', 'math']
43
+
44
+ for module_name in essential_modules:
45
+ try:
46
+ module = __import__(module_name)
47
+ updated_globals[module_name] = module
48
+ print(f"✓ {module_name} module loaded successfully")
49
+ except ImportError:
50
+ print(f"⚠️ Warning: {module_name} module not available")
51
+
52
  tree = ast.parse(code, mode="exec")
53
  compiled = compile(tree, filename="<ast>", mode="exec")
54
  stdout_buf = io.StringIO()
 
104
  self.default_python_codes = default_python_codes
105
 
106
  self.modal_secrets = modal.Secret.from_dict(modal_secrets)
107
+ self.pip_packages = list(set(["cloudpickle","requests","tinyagent-py[all]==0.0.8",
108
  "gradio",
109
  "arize-phoenix-otel",]+pip_packages))
110
  self.lazy_init = lazy_init
helper.py CHANGED
@@ -19,12 +19,25 @@ run_python("task='How the following repo has implemented Logging, and how can I
19
 
20
  prompt_qwen_helper = dedent("""
21
 
22
- **Your learning from past mistakes**
 
 
 
23
  - User can't directly see the response of run_python tool, so you need to use final_answer or ask_question whenever you want to show a response to the user.
24
  Other tools calls and their responses are not visible to the user.
25
  - run_python is a capable tool, if you need to call a function with different arguments, you can do it in one take, just like you would do in a python code you developed to be executed in one cell of Jupyter Notebook Cell.
26
  - When Task is not resolvable using functions available in your python enviroment, first think about creating a new function to solve the task, then ask the user about your approach and your code, if user allowed you to use it, then define and execute your custom made function. [It is your super power, you can create functions to solve the task.]
27
  - When you are defining a new function, you need to add any needed imports inside the function.
 
 
 
 
 
 
 
 
 
 
28
  """)
29
 
30
  def load_template(path: str) -> str:
 
19
 
20
  prompt_qwen_helper = dedent("""
21
 
22
+ **Your learning from past mistakes**
23
+ - Always think step by step about the task, what is it, how can you solve it, what are the steps you need to take to solve it.
24
+ - When you write a code and receive an error from run_python , go through your code and error step by step, you need to debug your code.
25
+ - You are an Agent, You need to solve the task, not suggesting user about how to solve the task.
26
  - User can't directly see the response of run_python tool, so you need to use final_answer or ask_question whenever you want to show a response to the user.
27
  Other tools calls and their responses are not visible to the user.
28
  - run_python is a capable tool, if you need to call a function with different arguments, you can do it in one take, just like you would do in a python code you developed to be executed in one cell of Jupyter Notebook Cell.
29
  - When Task is not resolvable using functions available in your python enviroment, first think about creating a new function to solve the task, then ask the user about your approach and your code, if user allowed you to use it, then define and execute your custom made function. [It is your super power, you can create functions to solve the task.]
30
  - When you are defining a new function, you need to add any needed imports inside the function.
31
+ Example: instead of:
32
+ import requests
33
+ def get_weather_data(city: str,api_key: str) -> str:
34
+ response = requests.get(f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}")
35
+ return response.json()
36
+ You should do it like this: Otherwise you will get an error.
37
+ def get_weather_data(city: str,api_key: str) -> str:
38
+ import requests
39
+ response = requests.get(f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}")
40
+ return response.json()
41
  """)
42
 
43
  def load_template(path: str) -> str:
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- tinyagent-py[all]==0.0.7
2
  cloudpickle
3
  modal
4
  jinja2
 
1
+ tinyagent-py[all]==0.0.8
2
  cloudpickle
3
  modal
4
  jinja2