Charles Azam commited on
Commit
6a6d57d
·
1 Parent(s): 69fe659

feat: add logging mechanism

Browse files
src/deepengineer/deepsearch/main_agent.py CHANGED
@@ -16,6 +16,8 @@ from smolagents import CodeAgent, LiteLLMModel
16
  import random
17
  from pathlib import Path
18
  import queue
 
 
19
 
20
 
21
  def create_output_image_path(random_name_images: int | None = None):
@@ -25,6 +27,30 @@ def create_output_image_path(random_name_images: int | None = None):
25
  return output_image_path
26
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def create_main_search_agent(
29
  model_id="deepseek/deepseek-reasoner",
30
  database: DataBase | None = None,
@@ -114,9 +140,14 @@ Run verification steps if that's needed, you must make sure you find the correct
114
  log_queue=log_queue,
115
  output_image_path=output_image_path,
116
  )
117
- answer = agent.run(MAIN_PROMPT.format(task=task))
118
-
119
- return answer, output_image_path
 
 
 
 
 
120
 
121
 
122
  if __name__ == "__main__":
 
16
  import random
17
  from pathlib import Path
18
  import queue
19
+ import json
20
+ import datetime
21
 
22
 
23
  def create_output_image_path(random_name_images: int | None = None):
 
27
  return output_image_path
28
 
29
 
30
+ def save_log(task: str, answer: str, model_id: str, success: bool = True, error: str = None):
31
+ """Simple function to save request logs with timestamps."""
32
+ logs_dir = Path(DATA_DIR) / "logs"
33
+ logs_dir.mkdir(parents=True, exist_ok=True)
34
+
35
+ timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
36
+ log_file = logs_dir / f"request_{timestamp}.json"
37
+
38
+ log_data = {
39
+ "timestamp": datetime.datetime.now().isoformat(),
40
+ "task": task,
41
+ "model_id": model_id,
42
+ "success": success,
43
+ "answer": answer,
44
+ "error": error
45
+ }
46
+
47
+ try:
48
+ with open(log_file, 'w', encoding='utf-8') as f:
49
+ json.dump(log_data, f, indent=2, ensure_ascii=False)
50
+ except Exception as e:
51
+ print(f"Failed to save log: {e}")
52
+
53
+
54
  def create_main_search_agent(
55
  model_id="deepseek/deepseek-reasoner",
56
  database: DataBase | None = None,
 
140
  log_queue=log_queue,
141
  output_image_path=output_image_path,
142
  )
143
+
144
+ try:
145
+ answer = agent.run(MAIN_PROMPT.format(task=task))
146
+ save_log(task, answer, model_id, success=True)
147
+ return answer, output_image_path
148
+ except Exception as e:
149
+ save_log(task, "", model_id, success=False, error=str(e))
150
+ raise e
151
 
152
 
153
  if __name__ == "__main__":