vision-agent 0.2.90__py3-none-any.whl → 0.2.92__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 +2 -1
- vision_agent/agent/agent.py +1 -1
- vision_agent/agent/agent_utils.py +43 -0
- vision_agent/agent/vision_agent.py +116 -824
- vision_agent/agent/vision_agent_coder.py +897 -0
- vision_agent/agent/vision_agent_coder_prompts.py +328 -0
- vision_agent/agent/vision_agent_prompts.py +89 -302
- vision_agent/lmm/__init__.py +2 -1
- vision_agent/lmm/lmm.py +3 -5
- vision_agent/lmm/types.py +5 -0
- vision_agent/tools/__init__.py +1 -0
- vision_agent/tools/meta_tools.py +402 -0
- vision_agent/tools/tool_utils.py +48 -2
- vision_agent/tools/tools.py +7 -49
- vision_agent/utils/execute.py +52 -76
- vision_agent/utils/image_utils.py +1 -1
- vision_agent/utils/type_defs.py +1 -1
- {vision_agent-0.2.90.dist-info → vision_agent-0.2.92.dist-info}/METADATA +42 -12
- vision_agent-0.2.92.dist-info/RECORD +29 -0
- vision_agent-0.2.90.dist-info/RECORD +0 -24
- {vision_agent-0.2.90.dist-info → vision_agent-0.2.92.dist-info}/LICENSE +0 -0
- {vision_agent-0.2.90.dist-info → vision_agent-0.2.92.dist-info}/WHEEL +0 -0
vision_agent/agent/__init__.py
CHANGED
vision_agent/agent/agent.py
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
import json
|
2
|
+
import logging
|
3
|
+
import sys
|
4
|
+
from typing import Any, Dict
|
5
|
+
|
6
|
+
logging.basicConfig(stream=sys.stdout)
|
7
|
+
_LOGGER = logging.getLogger(__name__)
|
8
|
+
|
9
|
+
|
10
|
+
def extract_json(json_str: str) -> Dict[str, Any]:
|
11
|
+
try:
|
12
|
+
json_dict = json.loads(json_str)
|
13
|
+
except json.JSONDecodeError:
|
14
|
+
input_json_str = json_str
|
15
|
+
if "```json" in json_str:
|
16
|
+
json_str = json_str[json_str.find("```json") + len("```json") :]
|
17
|
+
json_str = json_str[: json_str.find("```")]
|
18
|
+
elif "```" in json_str:
|
19
|
+
json_str = json_str[json_str.find("```") + len("```") :]
|
20
|
+
# get the last ``` not one from an intermediate string
|
21
|
+
json_str = json_str[: json_str.find("}```")]
|
22
|
+
try:
|
23
|
+
json_dict = json.loads(json_str)
|
24
|
+
except json.JSONDecodeError as e:
|
25
|
+
error_msg = f"Could not extract JSON from the given str: {json_str}.\nFunction input:\n{input_json_str}"
|
26
|
+
_LOGGER.exception(error_msg)
|
27
|
+
raise ValueError(error_msg) from e
|
28
|
+
return json_dict # type: ignore
|
29
|
+
|
30
|
+
|
31
|
+
def extract_code(code: str) -> str:
|
32
|
+
if "\n```python" in code:
|
33
|
+
start = "\n```python"
|
34
|
+
elif "```python" in code:
|
35
|
+
start = "```python"
|
36
|
+
else:
|
37
|
+
return code
|
38
|
+
|
39
|
+
code = code[code.find(start) + len(start) :]
|
40
|
+
code = code[: code.find("```")]
|
41
|
+
if code.startswith("python\n"):
|
42
|
+
code = code[len("python\n") :]
|
43
|
+
return code
|