Charles Azam commited on
Commit
dd7fa38
·
1 Parent(s): 395c3d4

refactor: rename functions in draw agent

Browse files
data/figure.png CHANGED
src/deepengineer/deepsearch/draw_agent.py CHANGED
@@ -13,9 +13,10 @@ from PIL import Image
13
  from smolagents import CodeAgent, LiteLLMModel
14
  from smolagents.agents import ActionStep
15
  from smolagents import tool, Tool
 
16
 
17
 
18
- def save_fig(image_path: Path = Path("figure.png")) -> str:
19
  """Save the current matplotlib figure to *path*.
20
  Save fig takes no arguments. The output path is hardcoded to "figure.png".
21
  """
@@ -48,7 +49,7 @@ class SaveMatplotlibFigTool(Tool):
48
  image_name = image_name + ".png"
49
  output_path = self.output_dir / image_name
50
  output_path.unlink(missing_ok=True)
51
- save_fig(output_path)
52
  if output_path.exists():
53
  return f"![]({image_name})"
54
  else:
@@ -58,7 +59,7 @@ class SaveMatplotlibFigTool(Tool):
58
  def _capture_snapshot(
59
  memory_step: ActionStep, agent: CodeAgent, image_path: Path = Path("figure.png")
60
  ) -> None:
61
- save_fig(image_path)
62
  if not plt.get_fignums():
63
  return
64
 
@@ -116,7 +117,7 @@ User instructions:
116
  """
117
 
118
 
119
- def draw_image_agent(
120
  prompt: str,
121
  image_path: str = Path("figure.png"),
122
  model_id: str = "mistral/mistral-medium-latest",
@@ -174,7 +175,9 @@ class DrawImageTool(Tool):
174
  def forward(self, prompt: str, image_name: str) -> str:
175
  if not image_name.endswith(".png"):
176
  image_name = image_name + ".png"
177
- output_path = draw_image_agent(prompt, self.output_dir / image_name)
 
 
178
  if output_path.exists():
179
  return f"![]({image_name})"
180
  else:
 
13
  from smolagents import CodeAgent, LiteLLMModel
14
  from smolagents.agents import ActionStep
15
  from smolagents import tool, Tool
16
+ from deepengineer.webcrawler.crawl_database import DataBase
17
 
18
 
19
+ def _find_and_save_matplotlib_figure(image_path: Path = Path("figure.png")) -> str:
20
  """Save the current matplotlib figure to *path*.
21
  Save fig takes no arguments. The output path is hardcoded to "figure.png".
22
  """
 
49
  image_name = image_name + ".png"
50
  output_path = self.output_dir / image_name
51
  output_path.unlink(missing_ok=True)
52
+ _find_and_save_matplotlib_figure(output_path)
53
  if output_path.exists():
54
  return f"![]({image_name})"
55
  else:
 
59
  def _capture_snapshot(
60
  memory_step: ActionStep, agent: CodeAgent, image_path: Path = Path("figure.png")
61
  ) -> None:
62
+ _find_and_save_matplotlib_figure(image_path)
63
  if not plt.get_fignums():
64
  return
65
 
 
117
  """
118
 
119
 
120
+ def draw_matplotlib_image_from_prompt(
121
  prompt: str,
122
  image_path: str = Path("figure.png"),
123
  model_id: str = "mistral/mistral-medium-latest",
 
175
  def forward(self, prompt: str, image_name: str) -> str:
176
  if not image_name.endswith(".png"):
177
  image_name = image_name + ".png"
178
+ output_path = draw_matplotlib_image_from_prompt(
179
+ prompt, self.output_dir / image_name
180
+ )
181
  if output_path.exists():
182
  return f"![]({image_name})"
183
  else:
src/deepengineer/deepsearch/scawl_web_agent.py CHANGED
@@ -203,11 +203,14 @@ class FindInMarkdownTool(Tool):
203
  return find_in_markdown(markdown, search_queries)
204
 
205
 
206
- def create_web_search_agent(model_id="deepseek/deepseek-chat"):
 
 
207
  """Create a web search agent with search, crawling, and PDF analysis capabilities."""
208
 
209
  model = LiteLLMModel(model_id=model_id)
210
- database = DataBase()
 
211
 
212
  # Web search and crawling tools
213
  WEB_SEARCH_TOOLS = [
 
203
  return find_in_markdown(markdown, search_queries)
204
 
205
 
206
+ def create_web_search_agent(
207
+ model_id="deepseek/deepseek-reasoner", database: DataBase | None = None
208
+ ):
209
  """Create a web search agent with search, crawling, and PDF analysis capabilities."""
210
 
211
  model = LiteLLMModel(model_id=model_id)
212
+ if database is None:
213
+ database = DataBase()
214
 
215
  # Web search and crawling tools
216
  WEB_SEARCH_TOOLS = [
tests/webcrawler/test_draw_agent.py CHANGED
@@ -1,6 +1,6 @@
1
  import pytest
2
  from deepengineer.deepsearch.draw_agent import (
3
- draw_image_agent,
4
  multiple_steps_draw_image_agent,
5
  SaveMatplotlibFigTool,
6
  )
@@ -14,7 +14,9 @@ def test_draw_image_agent():
14
  prompt = """Propose moi un schéma très détaillé d'un réacteur nucléaire hélium graphite."""
15
  output_path = Path(DATA_DIR) / "figure.png"
16
  output_path.unlink(missing_ok=True)
17
- output_path = draw_image_agent(prompt, output_path, multiple_steps=False)
 
 
18
  assert output_path.exists()
19
 
20
 
@@ -41,9 +43,6 @@ def test_save_matplotlib_fig_tool():
41
  assert (Path(DATA_DIR) / "figure.png").exists()
42
 
43
 
44
- test_save_matplotlib_fig_tool()
45
-
46
-
47
  @pytest.mark.skip(reason="This function is not working yet")
48
  def test_run_agent_step_by_step():
49
  prompt = """Propose moi un schéma très détaillé d'un réacteur nucléaire hélium graphite."""
 
1
  import pytest
2
  from deepengineer.deepsearch.draw_agent import (
3
+ draw_matplotlib_image_from_prompt,
4
  multiple_steps_draw_image_agent,
5
  SaveMatplotlibFigTool,
6
  )
 
14
  prompt = """Propose moi un schéma très détaillé d'un réacteur nucléaire hélium graphite."""
15
  output_path = Path(DATA_DIR) / "figure.png"
16
  output_path.unlink(missing_ok=True)
17
+ output_path = draw_matplotlib_image_from_prompt(
18
+ prompt, output_path, multiple_steps=False
19
+ )
20
  assert output_path.exists()
21
 
22
 
 
43
  assert (Path(DATA_DIR) / "figure.png").exists()
44
 
45
 
 
 
 
46
  @pytest.mark.skip(reason="This function is not working yet")
47
  def test_run_agent_step_by_step():
48
  prompt = """Propose moi un schéma très détaillé d'un réacteur nucléaire hélium graphite."""