vision-agent 0.2.86__py3-none-any.whl → 0.2.87__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/tools/tool_utils.py +50 -22
- vision_agent/utils/exceptions.py +9 -0
- vision_agent/utils/execute.py +11 -0
- {vision_agent-0.2.86.dist-info → vision_agent-0.2.87.dist-info}/METADATA +1 -1
- {vision_agent-0.2.86.dist-info → vision_agent-0.2.87.dist-info}/RECORD +7 -7
- {vision_agent-0.2.86.dist-info → vision_agent-0.2.87.dist-info}/LICENSE +0 -0
- {vision_agent-0.2.86.dist-info → vision_agent-0.2.87.dist-info}/WHEEL +0 -0
vision_agent/tools/tool_utils.py
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
import logging
|
2
2
|
import os
|
3
|
-
from typing import Any, Dict
|
3
|
+
from typing import Any, Dict, MutableMapping, Optional
|
4
4
|
|
5
|
+
from IPython.display import display
|
6
|
+
from pydantic import BaseModel
|
5
7
|
from requests import Session
|
6
8
|
from requests.adapters import HTTPAdapter
|
7
9
|
from urllib3.util.retry import Retry
|
8
10
|
|
11
|
+
from vision_agent.utils.exceptions import RemoteToolCallFailed
|
12
|
+
from vision_agent.utils.execute import Error, MimeType
|
9
13
|
from vision_agent.utils.type_defs import LandingaiAPIKey
|
10
14
|
|
11
15
|
_LOGGER = logging.getLogger(__name__)
|
@@ -13,34 +17,58 @@ _LND_API_KEY = LandingaiAPIKey().api_key
|
|
13
17
|
_LND_API_URL = "https://api.staging.landing.ai/v1/agent"
|
14
18
|
|
15
19
|
|
20
|
+
class ToolCallTrace(BaseModel):
|
21
|
+
endpoint_url: str
|
22
|
+
request: MutableMapping[str, Any]
|
23
|
+
response: MutableMapping[str, Any]
|
24
|
+
error: Optional[Error]
|
25
|
+
|
26
|
+
|
16
27
|
def send_inference_request(
|
17
28
|
payload: Dict[str, Any], endpoint_name: str
|
18
29
|
) -> Dict[str, Any]:
|
19
|
-
|
20
|
-
|
30
|
+
try:
|
31
|
+
if runtime_tag := os.environ.get("RUNTIME_TAG", ""):
|
32
|
+
payload["runtime_tag"] = runtime_tag
|
21
33
|
|
22
|
-
|
23
|
-
|
24
|
-
|
34
|
+
url = f"{_LND_API_URL}/model/{endpoint_name}"
|
35
|
+
if "TOOL_ENDPOINT_URL" in os.environ:
|
36
|
+
url = os.environ["TOOL_ENDPOINT_URL"]
|
25
37
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
38
|
+
tool_call_trace = ToolCallTrace(
|
39
|
+
endpoint_url=url,
|
40
|
+
request=payload,
|
41
|
+
response={},
|
42
|
+
error=None,
|
43
|
+
)
|
44
|
+
headers = {"Content-Type": "application/json", "apikey": _LND_API_KEY}
|
45
|
+
if "TOOL_ENDPOINT_AUTH" in os.environ:
|
46
|
+
headers["Authorization"] = os.environ["TOOL_ENDPOINT_AUTH"]
|
47
|
+
headers.pop("apikey")
|
30
48
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
49
|
+
session = _create_requests_session(
|
50
|
+
url=url,
|
51
|
+
num_retry=3,
|
52
|
+
headers=headers,
|
53
|
+
)
|
54
|
+
res = session.post(url, json=payload)
|
55
|
+
if res.status_code != 200:
|
56
|
+
tool_call_trace.error = Error(
|
57
|
+
name="RemoteToolCallFailed",
|
58
|
+
value=f"{res.status_code} - {res.text}",
|
59
|
+
traceback_raw=[],
|
60
|
+
)
|
61
|
+
_LOGGER.error(f"Request failed: {res.status_code} {res.text}")
|
62
|
+
raise RemoteToolCallFailed(payload["tool"], res.status_code, res.text)
|
40
63
|
|
41
|
-
|
42
|
-
|
43
|
-
|
64
|
+
resp = res.json()
|
65
|
+
tool_call_trace.response = resp
|
66
|
+
# TODO: consider making the response schema the same between below two sources
|
67
|
+
return resp if "TOOL_ENDPOINT_AUTH" in os.environ else resp["data"] # type: ignore
|
68
|
+
finally:
|
69
|
+
trace = tool_call_trace.model_dump()
|
70
|
+
trace["type"] = "tool_call"
|
71
|
+
display({MimeType.APPLICATION_JSON: trace}, raw=True)
|
44
72
|
|
45
73
|
|
46
74
|
def _create_requests_session(
|
vision_agent/utils/exceptions.py
CHANGED
@@ -13,6 +13,15 @@ For more information, see https://landing-ai.github.io/landingai-python/landinga
|
|
13
13
|
return self.message
|
14
14
|
|
15
15
|
|
16
|
+
class RemoteToolCallFailed(Exception):
|
17
|
+
"""Exception raised when an error occurs during a tool call."""
|
18
|
+
|
19
|
+
def __init__(self, tool_name: str, status_code: int, message: str):
|
20
|
+
self.message = (
|
21
|
+
f"""Tool call ({tool_name}) failed due to {status_code} - {message}"""
|
22
|
+
)
|
23
|
+
|
24
|
+
|
16
25
|
class RemoteSandboxError(Exception):
|
17
26
|
"""Exception related to remote sandbox."""
|
18
27
|
|
vision_agent/utils/execute.py
CHANGED
@@ -277,6 +277,17 @@ class Error(BaseModel):
|
|
277
277
|
text = "\n".join(self.traceback_raw)
|
278
278
|
return _remove_escape_and_color_codes(text) if return_clean_text else text
|
279
279
|
|
280
|
+
@staticmethod
|
281
|
+
def from_exception(e: Exception) -> "Error":
|
282
|
+
"""
|
283
|
+
Creates an Error object from an exception.
|
284
|
+
"""
|
285
|
+
return Error(
|
286
|
+
name=e.__class__.__name__,
|
287
|
+
value=str(e),
|
288
|
+
traceback_raw=traceback.format_exception(type(e), e, e.__traceback__),
|
289
|
+
)
|
290
|
+
|
280
291
|
|
281
292
|
class Execution(BaseModel):
|
282
293
|
"""
|
@@ -9,16 +9,16 @@ vision_agent/lmm/__init__.py,sha256=j9mQsIXQOYfW6nFd47uTwuBe1ranpEbwW308qLfCWN0,
|
|
9
9
|
vision_agent/lmm/lmm.py,sha256=035uONyp6_jD3PVdNdSg2PMHOG1voqnpsn2IyybUENs,15147
|
10
10
|
vision_agent/tools/__init__.py,sha256=k69hvcy2FWjDqVA0klzybKeoToOH_bom5NTVSliA0Og,1838
|
11
11
|
vision_agent/tools/prompts.py,sha256=V1z4YJLXZuUl_iZ5rY0M5hHc_2tmMEUKr0WocXKGt4E,1430
|
12
|
-
vision_agent/tools/tool_utils.py,sha256=
|
12
|
+
vision_agent/tools/tool_utils.py,sha256=ZnqaflVbLZB0GmgJJoQsZZs8hWbODXEPH1_Mq1s4bnc,3222
|
13
13
|
vision_agent/tools/tools.py,sha256=TkZqNYX-ocwdaCdXd6c6tysSa_HX2y6Nrgl4JKni4IQ,43661
|
14
14
|
vision_agent/utils/__init__.py,sha256=CW84HnhqI6XQVuxf2KifkLnSuO7EOhmuL09-gAymAak,219
|
15
|
-
vision_agent/utils/exceptions.py,sha256=
|
16
|
-
vision_agent/utils/execute.py,sha256=
|
15
|
+
vision_agent/utils/exceptions.py,sha256=isVH-SVL4vHj3q5kK4z7cy5_aOapAqHXWkpibfSNbUs,1659
|
16
|
+
vision_agent/utils/execute.py,sha256=DxuAoKmKAovgKe8IPkwg1B34osoz9_Ouvl1mi8aPXgE,23923
|
17
17
|
vision_agent/utils/image_utils.py,sha256=_cdiS5YrLzqkq_ZgFUO897m5M4_SCIThwUy4lOklfB8,7700
|
18
18
|
vision_agent/utils/sim.py,sha256=1HTaiVaBiKeyXIy21IYGXlPw0TipOyw9FPOJDfyLI94,4409
|
19
19
|
vision_agent/utils/type_defs.py,sha256=QeQRRIlklZMWzxROcCn5ELxP89nYdXGydy1rAiSpZZw,1384
|
20
20
|
vision_agent/utils/video.py,sha256=rNmU9KEIkZB5-EztZNlUiKYN0mm_55A_2VGUM0QpqLA,8779
|
21
|
-
vision_agent-0.2.
|
22
|
-
vision_agent-0.2.
|
23
|
-
vision_agent-0.2.
|
24
|
-
vision_agent-0.2.
|
21
|
+
vision_agent-0.2.87.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
22
|
+
vision_agent-0.2.87.dist-info/METADATA,sha256=St27tw1lvdjylYwUHeM3928tAzGeJjCj879nMJA-OWw,9477
|
23
|
+
vision_agent-0.2.87.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
24
|
+
vision_agent-0.2.87.dist-info/RECORD,,
|
File without changes
|
File without changes
|