vision-agent 0.2.45__py3-none-any.whl → 0.2.47__py3-none-any.whl
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.
- vision_agent/agent/vision_agent.py +45 -16
- vision_agent/agent/vision_agent_prompts.py +0 -2
- vision_agent/tools/tools.py +2 -0
- vision_agent/utils/execute.py +5 -0
- vision_agent/utils/video.py +1 -1
- {vision_agent-0.2.45.dist-info → vision_agent-0.2.47.dist-info}/METADATA +1 -1
- {vision_agent-0.2.45.dist-info → vision_agent-0.2.47.dist-info}/RECORD +9 -9
- {vision_agent-0.2.45.dist-info → vision_agent-0.2.47.dist-info}/LICENSE +0 -0
- {vision_agent-0.2.45.dist-info → vision_agent-0.2.47.dist-info}/WHEEL +0 -0
@@ -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
|
43
|
-
return
|
44
|
-
|
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(
|
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,
|
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=
|
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
|
|
vision_agent/tools/tools.py
CHANGED
@@ -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"]
|
vision_agent/utils/execute.py
CHANGED
@@ -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)
|
vision_agent/utils/video.py
CHANGED
@@ -11,8 +11,8 @@ vision_agent/agent/easytool_v2.py,sha256=CjY-sSj3abxnSq3ZHZMt-7YvRWDXEZsC6RN8FFI
|
|
11
11
|
vision_agent/agent/easytool_v2_prompts.py,sha256=MZSIwovYgB-f-kdJ6btaNDVXptJn47bfOL3-Zn6NiC0,8573
|
12
12
|
vision_agent/agent/reflexion.py,sha256=AlM5AvBJvCslXlYQdZiadq4oVHsNBm3IF_03DglTxRo,10506
|
13
13
|
vision_agent/agent/reflexion_prompts.py,sha256=G7UAeNz_g2qCb2yN6OaIC7bQVUkda4m3z42EG8wAyfE,9342
|
14
|
-
vision_agent/agent/vision_agent.py,sha256=
|
15
|
-
vision_agent/agent/vision_agent_prompts.py,sha256=
|
14
|
+
vision_agent/agent/vision_agent.py,sha256=S0VJWsdr0NIYjikXvPrEX-njGMqOIA53r4Q4NYY0Lpo,20365
|
15
|
+
vision_agent/agent/vision_agent_prompts.py,sha256=hgnTlaYp2HMBHLi3e4faPb-DI5jQL9jfhKq9jyEUEgY,8370
|
16
16
|
vision_agent/fonts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
17
|
vision_agent/fonts/default_font_ch_en.ttf,sha256=1YM0Z3XqLDjSNbF7ihQFSAIUdjF9m1rtHiNC_6QosTE,1594400
|
18
18
|
vision_agent/llm/__init__.py,sha256=BoUm_zSAKnLlE8s-gKTSQugXDqVZKPqYlWwlTLdhcz4,48
|
@@ -23,14 +23,14 @@ vision_agent/tools/__init__.py,sha256=K_7knxmyTIcSEGL8c9wF8RpVh3GrMYfybFaq-2SUM1
|
|
23
23
|
vision_agent/tools/easytool_tools.py,sha256=pZc5dQlYINlV4nYbbzsDi3-wauA-fCeD2iGmJUMoUfE,47373
|
24
24
|
vision_agent/tools/prompts.py,sha256=V1z4YJLXZuUl_iZ5rY0M5hHc_2tmMEUKr0WocXKGt4E,1430
|
25
25
|
vision_agent/tools/tool_utils.py,sha256=wzRacbUpqk9hhfX_Y08rL8qP0XCN2w-8IZoYLi3Upn4,869
|
26
|
-
vision_agent/tools/tools.py,sha256=
|
26
|
+
vision_agent/tools/tools.py,sha256=SrNrIjyUKoTE3mCqGcy6nC-MeEzJ8uJCumlSkTvvPpg,26085
|
27
27
|
vision_agent/utils/__init__.py,sha256=Ce4yPhoWanRsnTy3X7YzZNBYYRJsrJeT7N59WUf8GZM,209
|
28
|
-
vision_agent/utils/execute.py,sha256=
|
28
|
+
vision_agent/utils/execute.py,sha256=6sil3ktl6t8R8dV_RhYfb_s-z5m0c1_xtHCFzofIyqI,20501
|
29
29
|
vision_agent/utils/image_utils.py,sha256=_cdiS5YrLzqkq_ZgFUO897m5M4_SCIThwUy4lOklfB8,7700
|
30
30
|
vision_agent/utils/sim.py,sha256=oUZ-6eu8Io-UNt9GXJ0XRKtP-Wc0sPWVzYGVpB2yDFk,3001
|
31
31
|
vision_agent/utils/type_defs.py,sha256=BlI8ywWHAplC7kYWLvt4AOdnKpEW3qWEFm-GEOSkrFQ,1792
|
32
|
-
vision_agent/utils/video.py,sha256=
|
33
|
-
vision_agent-0.2.
|
34
|
-
vision_agent-0.2.
|
35
|
-
vision_agent-0.2.
|
36
|
-
vision_agent-0.2.
|
32
|
+
vision_agent/utils/video.py,sha256=_u3UrEpcJzbclKyJYxF7SiDQGhE2gUc598diYYiEv34,8885
|
33
|
+
vision_agent-0.2.47.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
34
|
+
vision_agent-0.2.47.dist-info/METADATA,sha256=WuIuMBkKPAExXks1PVwavSOQhXXtHennV9WsvJ1sans,6817
|
35
|
+
vision_agent-0.2.47.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
36
|
+
vision_agent-0.2.47.dist-info/RECORD,,
|
File without changes
|
File without changes
|