vision-agent 0.2.45__tar.gz → 0.2.47__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {vision_agent-0.2.45 → vision_agent-0.2.47}/PKG-INFO +1 -1
  2. {vision_agent-0.2.45 → vision_agent-0.2.47}/pyproject.toml +1 -1
  3. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/vision_agent.py +45 -16
  4. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/vision_agent_prompts.py +0 -2
  5. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/tools/tools.py +2 -0
  6. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/utils/execute.py +5 -0
  7. {vision_agent-0.2.45 → vision_agent-0.2.47}/LICENSE +0 -0
  8. {vision_agent-0.2.45 → vision_agent-0.2.47}/README.md +0 -0
  9. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/__init__.py +0 -0
  10. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/__init__.py +0 -0
  11. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/agent.py +0 -0
  12. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/agent_coder.py +0 -0
  13. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/agent_coder_prompts.py +0 -0
  14. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/data_interpreter.py +0 -0
  15. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/data_interpreter_prompts.py +0 -0
  16. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/easytool.py +0 -0
  17. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/easytool_prompts.py +0 -0
  18. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/easytool_v2.py +0 -0
  19. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/easytool_v2_prompts.py +0 -0
  20. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/reflexion.py +0 -0
  21. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/agent/reflexion_prompts.py +0 -0
  22. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/fonts/__init__.py +0 -0
  23. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/fonts/default_font_ch_en.ttf +0 -0
  24. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/llm/__init__.py +0 -0
  25. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/llm/llm.py +0 -0
  26. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/lmm/__init__.py +0 -0
  27. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/lmm/lmm.py +0 -0
  28. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/tools/__init__.py +0 -0
  29. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/tools/easytool_tools.py +0 -0
  30. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/tools/prompts.py +0 -0
  31. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/tools/tool_utils.py +0 -0
  32. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/utils/__init__.py +0 -0
  33. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/utils/image_utils.py +0 -0
  34. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/utils/sim.py +0 -0
  35. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/utils/type_defs.py +0 -0
  36. {vision_agent-0.2.45 → vision_agent-0.2.47}/vision_agent/utils/video.py +1 -1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vision-agent
3
- Version: 0.2.45
3
+ Version: 0.2.47
4
4
  Summary: Toolset for Vision Agent
5
5
  Author: Landing AI
6
6
  Author-email: dev@landing.ai
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "vision-agent"
7
- version = "0.2.45"
7
+ version = "0.2.47"
8
8
  description = "Toolset for Vision Agent"
9
9
  authors = ["Landing AI <dev@landing.ai>"]
10
10
  readme = "README.md"
@@ -1,4 +1,5 @@
1
1
  import copy
2
+ import difflib
2
3
  import json
3
4
  import logging
4
5
  import sys
@@ -16,7 +17,6 @@ import vision_agent.tools as T
16
17
  from vision_agent.agent import Agent
17
18
  from vision_agent.agent.vision_agent_prompts import (
18
19
  CODE,
19
- FEEDBACK,
20
20
  FIX_BUG,
21
21
  FULL_TASK,
22
22
  PLAN,
@@ -39,17 +39,27 @@ _CONSOLE = Console()
39
39
  _DEFAULT_IMPORT = "\n".join(T.__new_tools__)
40
40
 
41
41
 
42
- def format_memory(memory: List[Dict[str, str]]) -> str:
43
- return FEEDBACK.format(
44
- feedback="\n".join(
45
- [
46
- f"### Feedback {i}:\nCode: ```python\n{m['code']}\n```\nFeedback: {m['feedback']}\n"
47
- for i, m in enumerate(memory)
48
- ]
42
+ def get_diff(before: str, after: str) -> str:
43
+ return "".join(
44
+ difflib.unified_diff(
45
+ before.splitlines(keepends=True), after.splitlines(keepends=True)
49
46
  )
50
47
  )
51
48
 
52
49
 
50
+ def format_memory(memory: List[Dict[str, str]]) -> str:
51
+ output_str = ""
52
+ for i, m in enumerate(memory):
53
+ output_str += f"### Feedback {i}:\n"
54
+ output_str += f"Code {i}:\n```python\n{m['code']}```\n\n"
55
+ output_str += f"Feedback {i}: {m['feedback']}\n\n"
56
+ if "edits" in m:
57
+ output_str += f"Edits {i}:\n{m['edits']}\n"
58
+ output_str += "\n"
59
+
60
+ return output_str
61
+
62
+
53
63
  def extract_code(code: str) -> str:
54
64
  if "\n```python" in code:
55
65
  start = "\n```python"
@@ -146,7 +156,7 @@ def write_and_test_code(
146
156
  task: str,
147
157
  tool_info: str,
148
158
  tool_utils: str,
149
- working_memory: str,
159
+ working_memory: List[Dict[str, str]],
150
160
  coder: LLM,
151
161
  tester: LLM,
152
162
  debugger: LLM,
@@ -163,7 +173,13 @@ def write_and_test_code(
163
173
  }
164
174
  )
165
175
  code = extract_code(
166
- coder(CODE.format(docstring=tool_info, question=task, feedback=working_memory))
176
+ coder(
177
+ CODE.format(
178
+ docstring=tool_info,
179
+ question=task,
180
+ feedback=format_memory(working_memory),
181
+ )
182
+ )
167
183
  )
168
184
  test = extract_code(
169
185
  tester(
@@ -206,7 +222,7 @@ def write_and_test_code(
206
222
  )
207
223
 
208
224
  count = 0
209
- new_working_memory = []
225
+ new_working_memory: List[Dict[str, str]] = []
210
226
  while not result.success and count < max_retries:
211
227
  log_progress(
212
228
  {
@@ -217,14 +233,28 @@ def write_and_test_code(
217
233
  fixed_code_and_test = extract_json(
218
234
  debugger(
219
235
  FIX_BUG.format(
220
- code=code, tests=test, result=result.text(), feedback=working_memory
236
+ code=code,
237
+ tests=test,
238
+ result="\n".join(result.text().splitlines()[-50:]),
239
+ feedback=format_memory(working_memory + new_working_memory),
221
240
  )
222
241
  )
223
242
  )
243
+ old_code = code
244
+ old_test = test
245
+
224
246
  if fixed_code_and_test["code"].strip() != "":
225
247
  code = extract_code(fixed_code_and_test["code"])
226
248
  if fixed_code_and_test["test"].strip() != "":
227
249
  test = extract_code(fixed_code_and_test["test"])
250
+
251
+ new_working_memory.append(
252
+ {
253
+ "code": f"{code}\n{test}",
254
+ "feedback": fixed_code_and_test["reflections"],
255
+ "edits": get_diff(f"{old_code}\n{old_test}", f"{code}\n{test}"),
256
+ }
257
+ )
228
258
  log_progress(
229
259
  {
230
260
  "type": "code",
@@ -235,9 +265,6 @@ def write_and_test_code(
235
265
  },
236
266
  }
237
267
  )
238
- new_working_memory.append(
239
- {"code": f"{code}\n{test}", "feedback": fixed_code_and_test["reflections"]}
240
- )
241
268
 
242
269
  result = code_interpreter.exec_isolation(f"{_DEFAULT_IMPORT}\n{code}\n{test}")
243
270
  log_progress(
@@ -485,7 +512,7 @@ class VisionAgent(Agent):
485
512
  ),
486
513
  tool_info=tool_info,
487
514
  tool_utils=T.UTILITIES_DOCSTRING,
488
- working_memory=format_memory(working_memory),
515
+ working_memory=working_memory,
489
516
  coder=self.coder,
490
517
  tester=self.tester,
491
518
  debugger=self.debugger,
@@ -529,6 +556,8 @@ class VisionAgent(Agent):
529
556
  working_memory.append(
530
557
  {"code": f"{code}\n{test}", "feedback": feedback}
531
558
  )
559
+ else:
560
+ break
532
561
 
533
562
  retries += 1
534
563
 
@@ -197,9 +197,7 @@ When we run this test code:
197
197
  ```
198
198
 
199
199
  It raises this error:
200
- ```python
201
200
  {result}
202
- ```
203
201
 
204
202
  This is previous feedback provided on the code:
205
203
  {feedback}
@@ -608,6 +608,7 @@ def overlay_bounding_boxes(
608
608
  label: COLORS[i % len(COLORS)]
609
609
  for i, label in enumerate(set([box["label"] for box in bboxes]))
610
610
  }
611
+ bboxes = sorted(bboxes, key=lambda x: x["label"], reverse=True)
611
612
 
612
613
  width, height = pil_image.size
613
614
  fontsize = max(12, int(min(width, height) / 40))
@@ -680,6 +681,7 @@ def overlay_segmentation_masks(
680
681
  label: COLORS[i % len(COLORS)]
681
682
  for i, label in enumerate(set([mask["label"] for mask in masks]))
682
683
  }
684
+ masks = sorted(masks, key=lambda x: x["label"], reverse=True)
683
685
 
684
686
  for elt in masks:
685
687
  mask = elt["mask"]
@@ -426,6 +426,11 @@ print(f"Vision Agent version: {va_version}")"""
426
426
  def restart_kernel(self) -> None:
427
427
  self.interpreter.notebook.restart_kernel()
428
428
 
429
+ @tenacity.retry(
430
+ wait=tenacity.wait_exponential_jitter(),
431
+ stop=tenacity.stop_after_attempt(2),
432
+ retry=tenacity.retry_if_exception_type(TimeoutError),
433
+ )
429
434
  def exec_cell(self, code: str) -> Execution:
430
435
  execution = self.interpreter.notebook.exec_cell(code, timeout=self.timeout)
431
436
  return Execution.from_e2b_execution(execution)
File without changes
File without changes
@@ -2,8 +2,8 @@ import base64
2
2
  import logging
3
3
  import math
4
4
  import os
5
- from concurrent.futures import ProcessPoolExecutor, as_completed
6
5
  import tempfile
6
+ from concurrent.futures import ProcessPoolExecutor, as_completed
7
7
  from typing import List, Tuple, cast
8
8
 
9
9
  import cv2