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.
@@ -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
- if runtime_tag := os.environ.get("RUNTIME_TAG", ""):
20
- payload["runtime_tag"] = runtime_tag
30
+ try:
31
+ if runtime_tag := os.environ.get("RUNTIME_TAG", ""):
32
+ payload["runtime_tag"] = runtime_tag
21
33
 
22
- url = f"{_LND_API_URL}/model/{endpoint_name}"
23
- if "TOOL_ENDPOINT_URL" in os.environ:
24
- url = os.environ["TOOL_ENDPOINT_URL"]
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
- headers = {"Content-Type": "application/json", "apikey": _LND_API_KEY}
27
- if "TOOL_ENDPOINT_AUTH" in os.environ:
28
- headers["Authorization"] = os.environ["TOOL_ENDPOINT_AUTH"]
29
- headers.pop("apikey")
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
- session = _create_requests_session(
32
- url=url,
33
- num_retry=3,
34
- headers=headers,
35
- )
36
- res = session.post(url, json=payload)
37
- if res.status_code != 200:
38
- _LOGGER.error(f"Request failed: {res.status_code} {res.text}")
39
- raise ValueError(f"Request failed: {res.status_code} {res.text}")
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
- resp = res.json()
42
- # TODO: consider making the response schema the same between below two sources
43
- return resp if "TOOL_ENDPOINT_AUTH" in os.environ else resp["data"] # type: ignore
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(
@@ -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
 
@@ -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
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vision-agent
3
- Version: 0.2.86
3
+ Version: 0.2.87
4
4
  Summary: Toolset for Vision Agent
5
5
  Author: Landing AI
6
6
  Author-email: dev@landing.ai
@@ -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=6z0jrvUnesJEFqDHZoAvbXPic8rzh0KfILL07tu0uRo,2205
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=JGiFPLAYnPpEvHfueQuJotv3rCkS-A7UAwEym56MmHM,1359
16
- vision_agent/utils/execute.py,sha256=BRG_HranjVLfDzfiMCPzbH061No2andw4nUVujaMmak,23600
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.86.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
22
- vision_agent-0.2.86.dist-info/METADATA,sha256=OQLE0bUpQHqt2UmjaCa_qLGCx70OvtqRANc6bHsVDLI,9477
23
- vision_agent-0.2.86.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
24
- vision_agent-0.2.86.dist-info/RECORD,,
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,,