vision-agent 0.2.14__py3-none-any.whl → 0.2.16__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/__init__.py +1 -0
- vision_agent/agent/agent_coder.py +33 -7
- vision_agent/agent/vision_agent.py +16 -14
- vision_agent/agent/vision_agent_v2.py +300 -0
- vision_agent/agent/vision_agent_v2_prompt.py +170 -0
- vision_agent/llm/llm.py +11 -3
- vision_agent/tools/__init__.py +3 -3
- vision_agent/tools/tool_utils.py +1 -1
- vision_agent/tools/tools.py +62 -41
- vision_agent/tools/tools_v2.py +278 -17
- vision_agent/utils/__init__.py +3 -0
- vision_agent/utils/execute.py +104 -0
- vision_agent/utils/sim.py +70 -0
- {vision_agent-0.2.14.dist-info → vision_agent-0.2.16.dist-info}/METADATA +4 -1
- vision_agent-0.2.16.dist-info/RECORD +34 -0
- vision_agent/agent/execution.py +0 -287
- vision_agent-0.2.14.dist-info/RECORD +0 -30
- /vision_agent/{image_utils.py → utils/image_utils.py} +0 -0
- /vision_agent/{type_defs.py → utils/type_defs.py} +0 -0
- /vision_agent/{tools → utils}/video.py +0 -0
- {vision_agent-0.2.14.dist-info → vision_agent-0.2.16.dist-info}/LICENSE +0 -0
- {vision_agent-0.2.14.dist-info → vision_agent-0.2.16.dist-info}/WHEEL +0 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
"""This code is adapted from MetaGPT's https://github.com/geekan/MetaGPT/blob/main/metagpt/actions/di/execute_nb_code.py
|
2
|
+
"""
|
3
|
+
|
4
|
+
import base64 as b64
|
5
|
+
import io
|
6
|
+
import re
|
7
|
+
from typing import Dict, List, Tuple
|
8
|
+
|
9
|
+
import nbformat
|
10
|
+
from nbclient import NotebookClient
|
11
|
+
from nbclient.exceptions import CellTimeoutError, DeadKernelError
|
12
|
+
from nbclient.util import run_sync
|
13
|
+
from nbformat import NotebookNode
|
14
|
+
from nbformat.v4 import new_code_cell
|
15
|
+
from PIL import Image
|
16
|
+
|
17
|
+
|
18
|
+
def remove_escape_and_color_codes(input_str: str) -> str:
|
19
|
+
pattern = re.compile(r"\x1b\[[0-9;]*[mK]")
|
20
|
+
result = pattern.sub("", input_str)
|
21
|
+
return result
|
22
|
+
|
23
|
+
|
24
|
+
def parse_outputs(outputs: List[Dict]) -> Tuple[bool, str]:
|
25
|
+
success, parsed_output = True, []
|
26
|
+
for output in outputs:
|
27
|
+
# TODO: add parse image data
|
28
|
+
if output["output_type"] == "stream":
|
29
|
+
parsed_output.append(output["text"])
|
30
|
+
elif output["output_type"] == "text/plain":
|
31
|
+
parsed_output.append(output["data"]["text/plain"])
|
32
|
+
elif output["output_type"] == "display_data":
|
33
|
+
if "image/png" in output["data"]:
|
34
|
+
image_bytes = b64.b64decode(output["data"]["image/png"])
|
35
|
+
Image.open(io.BytesIO(image_bytes)).show()
|
36
|
+
elif output["output_type"] == "error":
|
37
|
+
success = False
|
38
|
+
output_text = remove_escape_and_color_codes("\n".join(output["traceback"]))
|
39
|
+
parsed_output.append(output_text)
|
40
|
+
|
41
|
+
return success, ",".join(parsed_output)
|
42
|
+
|
43
|
+
|
44
|
+
class Execute:
|
45
|
+
def __init__(self, timeout: int = 600) -> None:
|
46
|
+
self.nb = nbformat.v4.new_notebook()
|
47
|
+
self.timeout = timeout
|
48
|
+
self.nb_client = NotebookClient(self.nb, timeout=self.timeout)
|
49
|
+
|
50
|
+
def build(self) -> None:
|
51
|
+
if self.nb_client.kc is None or not run_sync(self.nb_client.kc.is_alive)(): # type: ignore
|
52
|
+
self.nb_client.create_kernel_manager()
|
53
|
+
self.nb_client.start_new_kernel()
|
54
|
+
self.nb_client.start_new_kernel_client()
|
55
|
+
|
56
|
+
def terminate(self) -> None:
|
57
|
+
if self.nb_client.km is not None and run_sync(self.nb_client.km.is_alive)(): # type: ignore
|
58
|
+
run_sync(self.nb_client.km.shutdown_kernel)(now=True)
|
59
|
+
run_sync(self.nb_client.km.cleanup_resources)()
|
60
|
+
|
61
|
+
channels = [
|
62
|
+
self.nb_client.kc.stdin_channel,
|
63
|
+
self.nb_client.kc.hb_channel,
|
64
|
+
self.nb_client.kc.control_channel,
|
65
|
+
]
|
66
|
+
|
67
|
+
for ch in channels:
|
68
|
+
if ch.is_alive():
|
69
|
+
ch.stop()
|
70
|
+
|
71
|
+
self.nb_client.kc = None
|
72
|
+
self.nb_client.km = None
|
73
|
+
|
74
|
+
def reset(self) -> None:
|
75
|
+
self.terminate()
|
76
|
+
self.nb = nbformat.v4.new_notebook()
|
77
|
+
self.nb_client = NotebookClient(self.nb, timeout=self.timeout)
|
78
|
+
self.build()
|
79
|
+
|
80
|
+
def run_cell(self, cell: NotebookNode, cell_index: int) -> Tuple[bool, str]:
|
81
|
+
try:
|
82
|
+
self.nb_client.execute_cell(cell, cell_index)
|
83
|
+
return parse_outputs(self.nb.cells[-1].outputs)
|
84
|
+
except CellTimeoutError:
|
85
|
+
run_sync(self.nb_client.km.interrupt_kernel)() # type: ignore
|
86
|
+
return False, "Cell execution timed out."
|
87
|
+
except DeadKernelError:
|
88
|
+
self.reset()
|
89
|
+
return False, "DeadKernelError"
|
90
|
+
except Exception:
|
91
|
+
return parse_outputs(self.nb.cells[-1].outputs)
|
92
|
+
|
93
|
+
def add_code_cell(self, code: str) -> None:
|
94
|
+
self.nb.cells.append(new_code_cell(code))
|
95
|
+
|
96
|
+
def run_additional(self, code: str) -> Tuple[bool, str]:
|
97
|
+
self.build()
|
98
|
+
self.add_code_cell(code)
|
99
|
+
return self.run_cell(self.nb.cells[-1], len(self.nb.cells) - 1)
|
100
|
+
|
101
|
+
def run_isolation(self, code: str) -> Tuple[bool, str]:
|
102
|
+
self.reset()
|
103
|
+
self.add_code_cell(code)
|
104
|
+
return self.run_cell(self.nb.cells[-1], len(self.nb.cells) - 1)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
from typing import Dict, List, Optional, Sequence, Union
|
3
|
+
|
4
|
+
import pandas as pd
|
5
|
+
from openai import Client
|
6
|
+
from scipy.spatial.distance import cosine # type: ignore
|
7
|
+
|
8
|
+
|
9
|
+
def get_embedding(
|
10
|
+
client: Client, text: str, model: str = "text-embedding-3-small"
|
11
|
+
) -> List[float]:
|
12
|
+
text = text.replace("\n", " ")
|
13
|
+
return client.embeddings.create(input=[text], model=model).data[0].embedding
|
14
|
+
|
15
|
+
|
16
|
+
class Sim:
|
17
|
+
def __init__(
|
18
|
+
self,
|
19
|
+
df: pd.DataFrame,
|
20
|
+
sim_key: Optional[str] = None,
|
21
|
+
api_key: Optional[str] = None,
|
22
|
+
model: str = "text-embedding-3-small",
|
23
|
+
) -> None:
|
24
|
+
"""Creates a similarity object that can be used to find similar items in a
|
25
|
+
dataframe.
|
26
|
+
|
27
|
+
Parameters:
|
28
|
+
df: pd.DataFrame: The dataframe to use for similarity.
|
29
|
+
sim_key: Optional[str]: The column name that you want to use to construct
|
30
|
+
the embeddings.
|
31
|
+
model: str: The model to use for embeddings.
|
32
|
+
"""
|
33
|
+
self.df = df
|
34
|
+
if not api_key:
|
35
|
+
self.client = Client()
|
36
|
+
else:
|
37
|
+
self.client = Client(api_key=api_key)
|
38
|
+
|
39
|
+
self.model = model
|
40
|
+
if "embs" not in df.columns and sim_key is None:
|
41
|
+
raise ValueError("key is required if no column 'embs' is present.")
|
42
|
+
|
43
|
+
if sim_key is not None:
|
44
|
+
self.df["embs"] = self.df[sim_key].apply(
|
45
|
+
lambda x: get_embedding(self.client, x, model=self.model)
|
46
|
+
)
|
47
|
+
|
48
|
+
def save(self, sim_file: Union[str, Path]) -> None:
|
49
|
+
self.df.to_csv(sim_file, index=False)
|
50
|
+
|
51
|
+
def top_k(self, query: str, k: int = 5) -> Sequence[Dict]:
|
52
|
+
"""Returns the top k most similar items to the query.
|
53
|
+
|
54
|
+
Parameters:
|
55
|
+
query: str: The query to compare to.
|
56
|
+
k: int: The number of items to return.
|
57
|
+
|
58
|
+
Returns:
|
59
|
+
Sequence[Dict]: The top k most similar items.
|
60
|
+
"""
|
61
|
+
|
62
|
+
embedding = get_embedding(self.client, query, model=self.model)
|
63
|
+
self.df["sim"] = self.df.embs.apply(lambda x: 1 - cosine(x, embedding))
|
64
|
+
res = self.df.sort_values("sim", ascending=False).head(k)
|
65
|
+
return res[[c for c in res.columns if c != "embs"]].to_dict(orient="records")
|
66
|
+
|
67
|
+
|
68
|
+
def load_sim(sim_file: Union[str, Path]) -> Sim:
|
69
|
+
df = pd.read_csv(sim_file)
|
70
|
+
return Sim(df)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: vision-agent
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.16
|
4
4
|
Summary: Toolset for Vision Agent
|
5
5
|
Author: Landing AI
|
6
6
|
Author-email: dev@landing.ai
|
@@ -10,6 +10,8 @@ Classifier: Programming Language :: Python :: 3.9
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.10
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
12
12
|
Requires-Dist: moviepy (>=1.0.0,<2.0.0)
|
13
|
+
Requires-Dist: nbclient (>=0.10.0,<0.11.0)
|
14
|
+
Requires-Dist: nbformat (>=5.10.4,<6.0.0)
|
13
15
|
Requires-Dist: numpy (>=1.21.0,<2.0.0)
|
14
16
|
Requires-Dist: openai (>=1.0.0,<2.0.0)
|
15
17
|
Requires-Dist: opencv-python-headless (>=4.0.0,<5.0.0)
|
@@ -17,6 +19,7 @@ Requires-Dist: pandas (>=2.0.0,<3.0.0)
|
|
17
19
|
Requires-Dist: pillow (>=10.0.0,<11.0.0)
|
18
20
|
Requires-Dist: pydantic-settings (>=2.2.1,<3.0.0)
|
19
21
|
Requires-Dist: requests (>=2.0.0,<3.0.0)
|
22
|
+
Requires-Dist: rich (>=13.7.1,<14.0.0)
|
20
23
|
Requires-Dist: scipy (>=1.13.0,<1.14.0)
|
21
24
|
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
22
25
|
Requires-Dist: tqdm (>=4.64.0,<5.0.0)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
vision_agent/__init__.py,sha256=GVLHCeK_R-zgldpbcPmOzJat-BkadvkuRCMxDvTIcXs,108
|
2
|
+
vision_agent/agent/__init__.py,sha256=Zv8lc91mPy0iDySId38_vc4mo56JQ9mCMvUWdAKQjh0,206
|
3
|
+
vision_agent/agent/agent.py,sha256=X7kON-g9ePUKumCDaYfQNBX_MEFE-ax5PnRp7-Cc5Wo,529
|
4
|
+
vision_agent/agent/agent_coder.py,sha256=e3mQn1xenahYk_uGflvuQ10s6dSHHM6p0jZN9UT1ZpE,6508
|
5
|
+
vision_agent/agent/agent_coder_prompts.py,sha256=CJe3v7xvHQ32u3RQAXQga_Tk_4UgU64RBAMHZ3S70KY,5538
|
6
|
+
vision_agent/agent/easytool.py,sha256=oMHnBg7YBtIPgqQUNcZgq7uMgpPThs99_UnO7ERkMVg,11511
|
7
|
+
vision_agent/agent/easytool_prompts.py,sha256=Bikw-PPLkm78dwywTlnv32Y1Tw6JMeC-R7oCnXWLcTk,4656
|
8
|
+
vision_agent/agent/reflexion.py,sha256=4gz30BuFMeGxSsTzoDV4p91yE0R8LISXp28IaOI6wdM,10506
|
9
|
+
vision_agent/agent/reflexion_prompts.py,sha256=G7UAeNz_g2qCb2yN6OaIC7bQVUkda4m3z42EG8wAyfE,9342
|
10
|
+
vision_agent/agent/vision_agent.py,sha256=ywOowbuwNSapVwl02ePZP_EzW1FlZULoCV59LR5nFww,27028
|
11
|
+
vision_agent/agent/vision_agent_prompts.py,sha256=MZSIwovYgB-f-kdJ6btaNDVXptJn47bfOL3-Zn6NiC0,8573
|
12
|
+
vision_agent/agent/vision_agent_v2.py,sha256=CDgGBSoa2LoMS0b4JhyDkoS3PJJNmCCPfxIGUc4RfQg,9658
|
13
|
+
vision_agent/agent/vision_agent_v2_prompt.py,sha256=-90Hlbtqb5Fp7OVjGabpTdgr-yCr8AYKIfiMRfoL4SY,5141
|
14
|
+
vision_agent/fonts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
+
vision_agent/fonts/default_font_ch_en.ttf,sha256=1YM0Z3XqLDjSNbF7ihQFSAIUdjF9m1rtHiNC_6QosTE,1594400
|
16
|
+
vision_agent/llm/__init__.py,sha256=BoUm_zSAKnLlE8s-gKTSQugXDqVZKPqYlWwlTLdhcz4,48
|
17
|
+
vision_agent/llm/llm.py,sha256=qWDBpJolGLWNwDjpEXu1NrjlJbo7Fj9efJYkSfVn6oE,5784
|
18
|
+
vision_agent/lmm/__init__.py,sha256=nnNeKD1k7q_4vLb1x51O_EUTYaBgGfeiCx5F433gr3M,67
|
19
|
+
vision_agent/lmm/lmm.py,sha256=gK90vMxh0OcGSuIZQikBkDXm4pfkdFk1R2y7rtWDl84,10539
|
20
|
+
vision_agent/tools/__init__.py,sha256=p5SM0YhThSVO_jRF9O-OjH2fYDPv-iMjexDX9xPPb7M,452
|
21
|
+
vision_agent/tools/prompts.py,sha256=V1z4YJLXZuUl_iZ5rY0M5hHc_2tmMEUKr0WocXKGt4E,1430
|
22
|
+
vision_agent/tools/tool_utils.py,sha256=moR7X4hkLKQzC56axdojo_OcIuVOv45bKcHPUVZrPvk,753
|
23
|
+
vision_agent/tools/tools.py,sha256=sVxN7SpDkz_XTc_SKwkoRF4EwaMTuHvTsCHwtR942Fc,47373
|
24
|
+
vision_agent/tools/tools_v2.py,sha256=1Y_ZbYJyuo2eZZkq7jY3YfuKWC82C-GFCZMLYH-I5ew,13800
|
25
|
+
vision_agent/utils/__init__.py,sha256=AKXf1QVOpO6MnqU8RSaFLQ_4us4DcKf8ibgEbhuHjvI,95
|
26
|
+
vision_agent/utils/execute.py,sha256=RC_jKrm2kOWwzNe9xKuA2xJcbsNcD0Hb95_o3_Le0_E,3820
|
27
|
+
vision_agent/utils/image_utils.py,sha256=1dggPBhW8_hUXDItCRLa23h-hdBwS50cjL4v1hsoUbg,7586
|
28
|
+
vision_agent/utils/sim.py,sha256=FaD16kKL1-JR2aSCmznF9KkJux9u3_Nr9tF4smBeoK0,2327
|
29
|
+
vision_agent/utils/type_defs.py,sha256=4LTnTL4HNsfYqCrDn9Ppjg9bSG2ZGcoKSSd9YeQf4Bw,1792
|
30
|
+
vision_agent/utils/video.py,sha256=xTElFSFp1Jw4ulOMnk81Vxsh-9dTxcWUO6P9fzEi3AM,7653
|
31
|
+
vision_agent-0.2.16.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
32
|
+
vision_agent-0.2.16.dist-info/METADATA,sha256=gbDID2drbfeDyy0jHQYDQZN81zRet90-bAVQKTSVdC4,9121
|
33
|
+
vision_agent-0.2.16.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
34
|
+
vision_agent-0.2.16.dist-info/RECORD,,
|
vision_agent/agent/execution.py
DELETED
@@ -1,287 +0,0 @@
|
|
1
|
-
"""This code is based off of code from CodeGeeX https://github.com/THUDM/CodeGeeX"""
|
2
|
-
|
3
|
-
import contextlib
|
4
|
-
import faulthandler
|
5
|
-
import io
|
6
|
-
import multiprocessing
|
7
|
-
import os
|
8
|
-
import platform
|
9
|
-
import signal
|
10
|
-
import tempfile
|
11
|
-
import traceback
|
12
|
-
import typing
|
13
|
-
from pathlib import Path
|
14
|
-
from typing import Dict, Generator, List, Optional, Union
|
15
|
-
|
16
|
-
IMPORT_HELPER = """
|
17
|
-
import math
|
18
|
-
import re
|
19
|
-
import sys
|
20
|
-
import copy
|
21
|
-
import datetime
|
22
|
-
import itertools
|
23
|
-
import collections
|
24
|
-
import heapq
|
25
|
-
import statistics
|
26
|
-
import functools
|
27
|
-
import hashlib
|
28
|
-
import numpy
|
29
|
-
import numpy as np
|
30
|
-
import string
|
31
|
-
from typing import *
|
32
|
-
from collections import *
|
33
|
-
from vision_agent.tools.tools_v2 import *
|
34
|
-
"""
|
35
|
-
|
36
|
-
|
37
|
-
def unsafe_execute(code: str, timeout: float, result: List) -> None:
|
38
|
-
with create_tempdir() as dir:
|
39
|
-
code_path = Path(dir) / "code.py"
|
40
|
-
with open(code_path, "w") as f:
|
41
|
-
f.write(code)
|
42
|
-
|
43
|
-
# These system calls are needed when cleaning up tempdir.
|
44
|
-
import os
|
45
|
-
import shutil
|
46
|
-
|
47
|
-
rmtree = shutil.rmtree
|
48
|
-
rmdir = os.rmdir
|
49
|
-
chdir = os.chdir
|
50
|
-
|
51
|
-
# Disable functionalities that can make destructive changes to the test.
|
52
|
-
reliability_guard()
|
53
|
-
|
54
|
-
try:
|
55
|
-
with swallow_io() as s:
|
56
|
-
with time_limit(timeout):
|
57
|
-
# WARNING
|
58
|
-
# This program exists to execute untrusted model-generated code. Although
|
59
|
-
# it is highly unlikely that model-generated code will do something overtly
|
60
|
-
# malicious in response to this test suite, model-generated code may act
|
61
|
-
# destructively due to a lack of model capability or alignment.
|
62
|
-
# Users are strongly encouraged to sandbox this evaluation suite so that it
|
63
|
-
# does not perform destructive actions on their host or network.
|
64
|
-
# Once you have read this disclaimer and taken appropriate precautions,
|
65
|
-
# uncomment the following line and proceed at your own risk:
|
66
|
-
code = compile(code, code_path, "exec") # type: ignore
|
67
|
-
exec(code)
|
68
|
-
result.append({"output": s.getvalue(), "passed": True})
|
69
|
-
except TimeoutError:
|
70
|
-
result.append({"output": "Timed out", "passed": False})
|
71
|
-
except AssertionError:
|
72
|
-
result.append({"output": f"{traceback.format_exc()}", "passed": False})
|
73
|
-
except BaseException:
|
74
|
-
result.append({"output": f"{traceback.format_exc()}", "passed": False})
|
75
|
-
|
76
|
-
# Needed for cleaning up.
|
77
|
-
shutil.rmtree = rmtree
|
78
|
-
os.rmdir = rmdir
|
79
|
-
os.chdir = chdir
|
80
|
-
|
81
|
-
code_path.unlink()
|
82
|
-
|
83
|
-
|
84
|
-
def check_correctness(
|
85
|
-
code: str,
|
86
|
-
timeout: float = 3.0,
|
87
|
-
) -> Dict[str, Union[str, bool]]:
|
88
|
-
"""Evaluates the functional correctness of a completion by running the test suite
|
89
|
-
provided in the problem.
|
90
|
-
"""
|
91
|
-
|
92
|
-
manager = multiprocessing.Manager()
|
93
|
-
result = manager.list()
|
94
|
-
|
95
|
-
# p = multiprocessing.Process(target=unsafe_execute, args=(tmp_dir,))
|
96
|
-
p = multiprocessing.Process(target=unsafe_execute, args=(code, timeout, result))
|
97
|
-
p.start()
|
98
|
-
p.join(timeout=timeout + 1)
|
99
|
-
if p.is_alive():
|
100
|
-
p.kill()
|
101
|
-
|
102
|
-
if not result:
|
103
|
-
result.append("timed out")
|
104
|
-
|
105
|
-
return {
|
106
|
-
"code": code,
|
107
|
-
"result": result[0]["output"],
|
108
|
-
"passed": result[0]["passed"],
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
# Copyright (c) OpenAI (https://openai.com)
|
113
|
-
|
114
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
115
|
-
# of this software and associated documentation files (the "Software"), to deal
|
116
|
-
# in the Software without restriction, including without limitation the rights
|
117
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
118
|
-
# copies of the Software, and to permit persons to whom the Software is
|
119
|
-
# furnished to do so, subject to the following conditions:
|
120
|
-
|
121
|
-
# The above copyright notice and this permission notice shall be included in
|
122
|
-
# all copies or substantial portions of the Software.
|
123
|
-
|
124
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
125
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
126
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
127
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
128
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
129
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
130
|
-
# THE SOFTWARE.
|
131
|
-
# ============================================================================
|
132
|
-
|
133
|
-
|
134
|
-
class redirect_stdin(contextlib._RedirectStream):
|
135
|
-
_stream = "stdin"
|
136
|
-
|
137
|
-
|
138
|
-
@contextlib.contextmanager
|
139
|
-
def chdir(root: str) -> Generator[None, None, None]:
|
140
|
-
if root == ".":
|
141
|
-
yield
|
142
|
-
return
|
143
|
-
cwd = os.getcwd()
|
144
|
-
os.chdir(root)
|
145
|
-
try:
|
146
|
-
yield
|
147
|
-
except BaseException as exc:
|
148
|
-
raise exc
|
149
|
-
finally:
|
150
|
-
os.chdir(cwd)
|
151
|
-
|
152
|
-
|
153
|
-
class WriteOnlyStringIO(io.StringIO):
|
154
|
-
"""StringIO that throws an exception when it's read from"""
|
155
|
-
|
156
|
-
def read(self, *args, **kwargs): # type: ignore
|
157
|
-
raise IOError
|
158
|
-
|
159
|
-
def readline(self, *args, **kwargs): # type: ignore
|
160
|
-
raise IOError
|
161
|
-
|
162
|
-
def readlines(self, *args, **kwargs): # type: ignore
|
163
|
-
raise IOError
|
164
|
-
|
165
|
-
def readable(self, *args, **kwargs): # type: ignore
|
166
|
-
"""Returns True if the IO object can be read."""
|
167
|
-
return False
|
168
|
-
|
169
|
-
|
170
|
-
@contextlib.contextmanager
|
171
|
-
def create_tempdir() -> Generator[str, None, None]:
|
172
|
-
with tempfile.TemporaryDirectory() as dirname:
|
173
|
-
with chdir(dirname):
|
174
|
-
yield dirname
|
175
|
-
|
176
|
-
|
177
|
-
@contextlib.contextmanager
|
178
|
-
def swallow_io() -> Generator[WriteOnlyStringIO, None, None]:
|
179
|
-
stream = WriteOnlyStringIO()
|
180
|
-
with contextlib.redirect_stdout(stream):
|
181
|
-
with contextlib.redirect_stderr(stream):
|
182
|
-
with redirect_stdin(stream):
|
183
|
-
yield stream
|
184
|
-
|
185
|
-
|
186
|
-
@typing.no_type_check
|
187
|
-
@contextlib.contextmanager
|
188
|
-
def time_limit(seconds: float) -> Generator[None, None, None]:
|
189
|
-
def signal_handler(signum, frame):
|
190
|
-
raise TimeoutError("Timed out!")
|
191
|
-
|
192
|
-
if platform.uname().system != "Windows":
|
193
|
-
signal.setitimer(signal.ITIMER_REAL, seconds)
|
194
|
-
signal.signal(signal.SIGALRM, signal_handler)
|
195
|
-
try:
|
196
|
-
yield
|
197
|
-
finally:
|
198
|
-
signal.setitimer(signal.ITIMER_REAL, 0)
|
199
|
-
|
200
|
-
|
201
|
-
@typing.no_type_check
|
202
|
-
def reliability_guard(maximum_memory_bytes: Optional[int] = None) -> None:
|
203
|
-
"""
|
204
|
-
This disables various destructive functions and prevents the generated code
|
205
|
-
from interfering with the test (e.g. fork bomb, killing other processes,
|
206
|
-
removing filesystem files, etc.)
|
207
|
-
|
208
|
-
WARNING
|
209
|
-
This function is NOT a security sandbox. Untrusted code, including, model-
|
210
|
-
generated code, should not be blindly executed outside of one. See the
|
211
|
-
Codex paper for more information about OpenAI's code sandbox, and proceed
|
212
|
-
with caution.
|
213
|
-
"""
|
214
|
-
|
215
|
-
if maximum_memory_bytes is not None:
|
216
|
-
if platform.uname().system != "Windows":
|
217
|
-
import resource
|
218
|
-
|
219
|
-
resource.setrlimit(
|
220
|
-
resource.RLIMIT_AS, (maximum_memory_bytes, maximum_memory_bytes)
|
221
|
-
)
|
222
|
-
resource.setrlimit(
|
223
|
-
resource.RLIMIT_DATA, (maximum_memory_bytes, maximum_memory_bytes)
|
224
|
-
)
|
225
|
-
if not platform.uname().system == "Darwin":
|
226
|
-
resource.setrlimit(
|
227
|
-
resource.RLIMIT_STACK, (maximum_memory_bytes, maximum_memory_bytes)
|
228
|
-
)
|
229
|
-
|
230
|
-
faulthandler.disable()
|
231
|
-
|
232
|
-
import builtins
|
233
|
-
|
234
|
-
builtins.exit = None
|
235
|
-
builtins.quit = None
|
236
|
-
|
237
|
-
import os
|
238
|
-
|
239
|
-
os.environ["OMP_NUM_THREADS"] = "1"
|
240
|
-
|
241
|
-
os.kill = None
|
242
|
-
os.system = None
|
243
|
-
# os.putenv = None # this causes numpy to fail on import
|
244
|
-
os.remove = None
|
245
|
-
os.removedirs = None
|
246
|
-
os.rmdir = None
|
247
|
-
os.fchdir = None
|
248
|
-
os.setuid = None
|
249
|
-
os.fork = None
|
250
|
-
os.forkpty = None
|
251
|
-
os.killpg = None
|
252
|
-
os.rename = None
|
253
|
-
os.renames = None
|
254
|
-
os.truncate = None
|
255
|
-
os.replace = None
|
256
|
-
os.unlink = None
|
257
|
-
os.fchmod = None
|
258
|
-
os.fchown = None
|
259
|
-
os.chmod = None
|
260
|
-
os.chown = None
|
261
|
-
os.chroot = None
|
262
|
-
os.fchdir = None
|
263
|
-
os.lchflags = None
|
264
|
-
os.lchmod = None
|
265
|
-
os.lchown = None
|
266
|
-
os.getcwd = None
|
267
|
-
os.chdir = None
|
268
|
-
|
269
|
-
import shutil
|
270
|
-
|
271
|
-
shutil.rmtree = None
|
272
|
-
shutil.move = None
|
273
|
-
shutil.chown = None
|
274
|
-
|
275
|
-
import subprocess
|
276
|
-
|
277
|
-
subprocess.Popen = None # type: ignore
|
278
|
-
|
279
|
-
__builtins__["help"] = None
|
280
|
-
|
281
|
-
import sys
|
282
|
-
|
283
|
-
sys.modules["ipdb"] = None
|
284
|
-
sys.modules["joblib"] = None
|
285
|
-
sys.modules["resource"] = None
|
286
|
-
sys.modules["psutil"] = None
|
287
|
-
sys.modules["tkinter"] = None
|
@@ -1,30 +0,0 @@
|
|
1
|
-
vision_agent/__init__.py,sha256=GVLHCeK_R-zgldpbcPmOzJat-BkadvkuRCMxDvTIcXs,108
|
2
|
-
vision_agent/agent/__init__.py,sha256=6AIN_lkqAz83dRN2WKpW7m1lQH1m-8BA2L-oUCFSKd4,163
|
3
|
-
vision_agent/agent/agent.py,sha256=X7kON-g9ePUKumCDaYfQNBX_MEFE-ax5PnRp7-Cc5Wo,529
|
4
|
-
vision_agent/agent/agent_coder.py,sha256=65ZEF3_K2aAG0vve-Q9xOPP9uw30_vVD2Li6NE6BFRY,6073
|
5
|
-
vision_agent/agent/agent_coder_prompts.py,sha256=CJe3v7xvHQ32u3RQAXQga_Tk_4UgU64RBAMHZ3S70KY,5538
|
6
|
-
vision_agent/agent/easytool.py,sha256=oMHnBg7YBtIPgqQUNcZgq7uMgpPThs99_UnO7ERkMVg,11511
|
7
|
-
vision_agent/agent/easytool_prompts.py,sha256=Bikw-PPLkm78dwywTlnv32Y1Tw6JMeC-R7oCnXWLcTk,4656
|
8
|
-
vision_agent/agent/execution.py,sha256=wX8LwXDq_0g_bTPikNiaW6nz5bUC7fUlNQsQHe_7Ww0,8582
|
9
|
-
vision_agent/agent/reflexion.py,sha256=4gz30BuFMeGxSsTzoDV4p91yE0R8LISXp28IaOI6wdM,10506
|
10
|
-
vision_agent/agent/reflexion_prompts.py,sha256=G7UAeNz_g2qCb2yN6OaIC7bQVUkda4m3z42EG8wAyfE,9342
|
11
|
-
vision_agent/agent/vision_agent.py,sha256=5W5Xr_h4yDMsFvIk2JWcfMlYoPYmTv3JZnrDDumuZgM,26842
|
12
|
-
vision_agent/agent/vision_agent_prompts.py,sha256=MZSIwovYgB-f-kdJ6btaNDVXptJn47bfOL3-Zn6NiC0,8573
|
13
|
-
vision_agent/fonts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
-
vision_agent/fonts/default_font_ch_en.ttf,sha256=1YM0Z3XqLDjSNbF7ihQFSAIUdjF9m1rtHiNC_6QosTE,1594400
|
15
|
-
vision_agent/image_utils.py,sha256=1dggPBhW8_hUXDItCRLa23h-hdBwS50cjL4v1hsoUbg,7586
|
16
|
-
vision_agent/llm/__init__.py,sha256=BoUm_zSAKnLlE8s-gKTSQugXDqVZKPqYlWwlTLdhcz4,48
|
17
|
-
vision_agent/llm/llm.py,sha256=1BkrSVBWEClyqLc0Rmyw4heLhi_ZVm6JO7-i1wd1ziw,5383
|
18
|
-
vision_agent/lmm/__init__.py,sha256=nnNeKD1k7q_4vLb1x51O_EUTYaBgGfeiCx5F433gr3M,67
|
19
|
-
vision_agent/lmm/lmm.py,sha256=gK90vMxh0OcGSuIZQikBkDXm4pfkdFk1R2y7rtWDl84,10539
|
20
|
-
vision_agent/tools/__init__.py,sha256=uWySwcIeQMH57PVN6lVIknTx-SFmN_J0mvn_HbGlXcQ,451
|
21
|
-
vision_agent/tools/prompts.py,sha256=V1z4YJLXZuUl_iZ5rY0M5hHc_2tmMEUKr0WocXKGt4E,1430
|
22
|
-
vision_agent/tools/tool_utils.py,sha256=kY-hBDIrapI-030nZuasXU83P6X3GR0Y_gOR32bnedw,747
|
23
|
-
vision_agent/tools/tools.py,sha256=8JzNtn_uKTyc-bztjnaGCY7ctRnfW5dRS-ppxaP-1RE,46427
|
24
|
-
vision_agent/tools/tools_v2.py,sha256=RxeaBTTkhqvATQGuYKiopeU4L2m0GbpPo-ypDmQ9UfY,5407
|
25
|
-
vision_agent/tools/video.py,sha256=xTElFSFp1Jw4ulOMnk81Vxsh-9dTxcWUO6P9fzEi3AM,7653
|
26
|
-
vision_agent/type_defs.py,sha256=4LTnTL4HNsfYqCrDn9Ppjg9bSG2ZGcoKSSd9YeQf4Bw,1792
|
27
|
-
vision_agent-0.2.14.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
28
|
-
vision_agent-0.2.14.dist-info/METADATA,sha256=P4mOwafNaTHHf5GMoe-spAfPUmQHNWT7UKSBZ5LU-Vo,8997
|
29
|
-
vision_agent-0.2.14.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
30
|
-
vision_agent-0.2.14.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|