MickyWin22 commited on
Commit
0f2b299
·
verified ·
1 Parent(s): 64cf24f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -9
app.py CHANGED
@@ -72,17 +72,31 @@ class GaiaSmolAgent:
72
 
73
  def _generate_plan(self, question: str) -> list[str]:
74
  """Generates a step-by-step plan to answer the question."""
75
- # ... (This method remains unchanged)
76
  print(f"Generating plan for question: {question[:100]}...")
 
77
  prompt = f"""
78
- You are an expert planner. Your job is to create a clear, step-by-step plan to answer the given question.
79
- The final step must be to output the answer using the `final_answer` tool.
80
- Each step should be a clear instruction for an agent to follow.
 
 
 
 
 
 
 
 
 
81
 
82
  Question: "{question}"
83
 
84
- Provide the plan as a Python list of strings. For example:
85
- ["Search the web for the latest news on topic X.", "Analyze the search results to find the key person.", "final_answer('The key person is John Doe.')"]
 
 
 
 
 
86
  """
87
  response = self.planner_model.generate(prompt)
88
  print(f"Generated plan: {response}")
@@ -92,10 +106,12 @@ class GaiaSmolAgent:
92
  if isinstance(plan, list):
93
  return plan
94
  else:
95
- return [f"final_answer('Error: Plan generation failed. Could not parse plan: {response}')"]
 
96
  except Exception as e:
97
- print(f"Error parsing plan: {e}")
98
- return [f"final_answer('Error: Plan generation failed. Could not parse plan: {response}')"]
 
99
 
100
 
101
  def __call__(self, question: str) -> str:
 
72
 
73
  def _generate_plan(self, question: str) -> list[str]:
74
  """Generates a step-by-step plan to answer the question."""
 
75
  print(f"Generating plan for question: {question[:100]}...")
76
+
77
  prompt = f"""
78
+ You are a master planner that creates Python code plans for an agent.
79
+ You have access to the following tools:
80
+ - `DuckDuckGoSearch(query: str) -> str`: Searches the web and returns a string with the results.
81
+ - `file_reader(file_path: str) -> str`: Reads a file from a URL or local path and returns its contents as a string.
82
+ - A full Python interpreter to process strings, perform calculations, etc.
83
+
84
+ Your task is to create a plan to answer the user's question. The plan must be a Python list of strings, where each string is a single line of Python code.
85
+
86
+ **Crucial Instructions:**
87
+ 1. The output of `DuckDuckGoSearch` and `file_reader` is always a STRING. You MUST use Python code (e.g., string manipulation, regex) in a subsequent step to extract information from this string. **DO NOT treat the tool output like a dictionary or JSON.**
88
+ 2. Store the output of tools in variables (e.g., `search_results = DuckDuckGoSearch(...)`).
89
+ 3. The final step of the plan MUST be a call to `final_answer("your final answer here")`. The answer must be a single, concise string.
90
 
91
  Question: "{question}"
92
 
93
+ Example of a good plan for the question "What is the main topic of the document at http://example.com/paper.pdf?":
94
+ Plan:
95
+ [
96
+ "file_content = file_reader('http://example.com/paper.pdf')",
97
+ "summary = 'The main topic seems to be about: ' + file_content[:200]",
98
+ "final_answer(summary)"
99
+ ]
100
  """
101
  response = self.planner_model.generate(prompt)
102
  print(f"Generated plan: {response}")
 
106
  if isinstance(plan, list):
107
  return plan
108
  else:
109
+ # If the LLM doesn't return a list, create a fallback plan
110
+ return [f"final_answer('Error: Plan generation failed. The model did not return a valid list.')"]
111
  except Exception as e:
112
+ print(f"Error parsing plan with eval(): {e}")
113
+ # If eval fails, create a fallback plan
114
+ return [f"final_answer('Error: Plan generation failed. The model returned malformed code: {response}')"]
115
 
116
 
117
  def __call__(self, question: str) -> str: